Browse Source

Publish and document API globals properly

Alois Mahdal 5 years ago
parent
commit
196eaa37bf
2 changed files with 44 additions and 24 deletions
  1. 8
    10
      src/libexec/dottum-install
  2. 36
    14
      src/shellfu/dottum.sh

+ 8
- 10
src/libexec/dottum-install View File

16
 }
16
 }
17
 
17
 
18
 dottum__route() {
18
 dottum__route() {
19
-    local Vault=$1; shift
20
-    local SubVaults=()
21
-    test -n "$Vault" || usage -w "no VAULT?"
22
-    test -e "$Vault" || die "vault does not exist: $Vault"
23
-    test -d "$Vault" || die "vault is not a directory: $Vault"
24
-    SubVaults=("$@")
19
+    DOTTUM__VAULT=$1; shift
20
+    local DOTTUM__SUBVAULTS=()
21
+    test -n "$DOTTUM__VAULT" || usage -w "no VAULT?"
22
+    test -e "$DOTTUM__VAULT" || die "vault does not exist: $DOTTUM__VAULT"
23
+    test -d "$DOTTUM__VAULT" || die "vault is not a directory: $DOTTUM__VAULT"
24
+    DOTTUM__SUBVAULTS=("$@")
25
     case $Action in
25
     case $Action in
26
         init)       dottum__make_links  ;;
26
         init)       dottum__make_links  ;;
27
         explore)    dottum__explore     ;;
27
         explore)    dottum__explore     ;;
32
 
32
 
33
 main() {
33
 main() {
34
     local Action=init
34
     local Action=init
35
-    local ClobberLinks=false
36
-    local ClobberBroken=true
37
     while true; do case $1 in
35
     while true; do case $1 in
38
         -n) Action=explore;     shift ;;
36
         -n) Action=explore;     shift ;;
39
-        -B) ClobberBroken=false; shift ;;
40
-        -f) ClobberLinks=true;  shift ;;
37
+        -B) DOTTUM__CLOBBER_BROKEN=false; shift ;;
38
+        -f) DOTTUM__CLOBBER_LINKS=true;  shift ;;
41
         -*) usage -w "unknown argument: $1" ;;
39
         -*) usage -w "unknown argument: $1" ;;
42
         *)                      break ;;
40
         *)                      break ;;
43
     esac done
41
     esac done

+ 36
- 14
src/shellfu/dottum.sh View File

2
 
2
 
3
 shellfu import pretty
3
 shellfu import pretty
4
 
4
 
5
+#
6
+# Should broken links be silently overwritten?
7
+#
8
+DOTTUM__CLOBBER_BROKEN=false
9
+
10
+#
11
+# Should all links be silently overwritten?
12
+#
13
+DOTTUM__CLOBBER_LINKS=false
14
+
15
+#
16
+# List of subvalults passed on command line
17
+#
18
+# This is added to the front of list in *subvalults* file.
19
+#
20
+DOTTUM__SUBVAULTS=()
21
+
22
+#
23
+# Vault to process
24
+#
25
+DOTTUM__VAULT=""
26
+
5
 _dottum__slstatus() {
27
 _dottum__slstatus() {
6
     #
28
     #
7
     # Print status of slpath $1
29
     # Print status of slpath $1
72
     #     $HOME/.local/share/klavaro -> dotfiles/local/share/klavaro
94
     #     $HOME/.local/share/klavaro -> dotfiles/local/share/klavaro
73
     #
95
     #
74
     local sv
96
     local sv
75
-    test -n "${SubVaults[0]}" && {
97
+    test -n "${DOTTUM__SUBVAULTS[0]}" && {
76
         think "using sub-vaults from command line"
98
         think "using sub-vaults from command line"
77
-        for sv in "${SubVaults[@]}";
99
+        for sv in "${DOTTUM__SUBVAULTS[@]}";
78
         do
100
         do
79
             echo "$sv"
101
             echo "$sv"
80
         done
102
         done
81
         return
103
         return
82
     }
104
     }
83
-    test -f "$Vault/dotvault/subvaults" && {
84
-        think "reading subvaults from file: $Vault/dotvault/subvaults"
85
-        grep . "$Vault/dotvault/subvaults" \
105
+    test -f "$DOTTUM__VAULT/dotvault/subvaults" && {
106
+        think "reading subvaults from file: $DOTTUM__VAULT/dotvault/subvaults"
107
+        grep . "$DOTTUM__VAULT/dotvault/subvaults" \
86
           | grep -v "^#.*"
108
           | grep -v "^#.*"
87
         return
109
         return
88
     }
110
     }
95
     # List all vaults and subvaults, depth-first
117
     # List all vaults and subvaults, depth-first
96
     #
118
     #
97
     {
119
     {
98
-        echo "$Vault"
120
+        echo "$DOTTUM__VAULT"
99
         dottum__lssv \
121
         dottum__lssv \
100
           | while IFS= read -r sv;
122
           | while IFS= read -r sv;
101
             do
123
             do
102
-                test -e "$Vault/$sv" || {
124
+                test -e "$DOTTUM__VAULT/$sv" || {
103
                     think "ignoring non-existent sub-vault: $sv"
125
                     think "ignoring non-existent sub-vault: $sv"
104
                     continue
126
                     continue
105
                 }
127
                 }
106
-                test -d "$Vault/$sv" || {
128
+                test -d "$DOTTUM__VAULT/$sv" || {
107
                     warn "ignoring non-directory sub-vault: $sv"
129
                     warn "ignoring non-directory sub-vault: $sv"
108
                     continue
130
                     continue
109
                 }
131
                 }
110
-                echo "$Vault/$sv"
132
+                echo "$DOTTUM__VAULT/$sv"
111
             done
133
             done
112
     } \
134
     } \
113
       | LC_ALL=C sort \
135
       | LC_ALL=C sort \
172
     local item
194
     local item
173
     find "$vlt" -mindepth 1 -maxdepth 1 -printf "%P\n" \
195
     find "$vlt" -mindepth 1 -maxdepth 1 -printf "%P\n" \
174
       | dottum__pfxpath "$vlt/" \
196
       | dottum__pfxpath "$vlt/" \
175
-      | grep -v "$Vault/dotvault" \
197
+      | grep -v "$DOTTUM__VAULT/dotvault" \
176
       | while IFS= read -r item;
198
       | while IFS= read -r item;
177
         do
199
         do
178
             dottum__istarget "$item" && echo "$item"
200
             dottum__istarget "$item" && echo "$item"
203
                             continue
225
                             continue
204
                             ;;
226
                             ;;
205
                         broken)
227
                         broken)
206
-                            if $ClobberLinks || $ClobberBroken; then
228
+                            if $DOTTUM__CLOBBER_LINKS || $DOTTUM__CLOBBER_BROKEN; then
207
                                 think "removing existing broken link: $slpath"
229
                                 think "removing existing broken link: $slpath"
208
                                 dottum__maybe rm "$slpath"
230
                                 dottum__maybe rm "$slpath"
209
                             else
231
                             else
212
                             fi
234
                             fi
213
                             ;;
235
                             ;;
214
                         symlink)
236
                         symlink)
215
-                            if $ClobberLinks; then
237
+                            if $DOTTUM__CLOBBER_LINKS; then
216
                                 think "removing existing link: $slpath"
238
                                 think "removing existing link: $slpath"
217
                                 dottum__maybe rm "$slpath"
239
                                 dottum__maybe rm "$slpath"
218
                             else
240
                             else
239
         do
261
         do
240
             tgts=$(dottum__lstarget "$vlt")
262
             tgts=$(dottum__lstarget "$vlt")
241
             test -n "$tgts" || continue
263
             test -n "$tgts" || continue
242
-            if test "$vlt" == "$Vault";
264
+            if test "$vlt" == "$DOTTUM__VAULT";
243
             then
265
             then
244
                 echo "VAULT:$vlt:"
266
                 echo "VAULT:$vlt:"
245
             else
267
             else
270
     # Print path where to create link for target $1
292
     # Print path where to create link for target $1
271
     #
293
     #
272
     local item=$1
294
     local item=$1
273
-    echo "$HOME/.${item#$Vault/}"
295
+    echo "$HOME/.${item#$DOTTUM__VAULT/}"
274
 }
296
 }