Selaa lähdekoodia

Publish and document API globals properly

Alois Mahdal 6 vuotta sitten
vanhempi
commit
196eaa37bf
2 muutettua tiedostoa jossa 44 lisäystä ja 24 poistoa
  1. 8
    10
      src/libexec/dottum-install
  2. 36
    14
      src/shellfu/dottum.sh

+ 8
- 10
src/libexec/dottum-install Näytä tiedosto

@@ -16,12 +16,12 @@ usage() {
16 16
 }
17 17
 
18 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 25
     case $Action in
26 26
         init)       dottum__make_links  ;;
27 27
         explore)    dottum__explore     ;;
@@ -32,12 +32,10 @@ export LC_ALL=C
32 32
 
33 33
 main() {
34 34
     local Action=init
35
-    local ClobberLinks=false
36
-    local ClobberBroken=true
37 35
     while true; do case $1 in
38 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 39
         -*) usage -w "unknown argument: $1" ;;
42 40
         *)                      break ;;
43 41
     esac done

+ 36
- 14
src/shellfu/dottum.sh Näytä tiedosto

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