Browse Source

Apply ShellCheck advice

Alois Mahdal 9 years ago
parent
commit
6e128ebffd

+ 2
- 2
src/bin/saturnin.skel View File

@@ -40,8 +40,8 @@ usage() {
40 40
 }
41 41
 
42 42
 version_info() {
43
-    echo "$(basename $0) (Smart and ready desktop helper) $SATURNIN_VERSION"
44
-    exit $FFOO_EXIT_OK
43
+    echo "$(basename "$0") (Smart and ready desktop helper) $SATURNIN_VERSION"
44
+    exit "$FFOO_EXIT_OK"
45 45
 }
46 46
 
47 47
 while true; do case $1 in

+ 2
- 3
src/ffoo/saturnin_meta.sh View File

@@ -36,7 +36,7 @@ saturnin_runhook() {
36 36
         warn "unknown subcommand, ignoring hook: $hname"
37 37
         return 0
38 38
     }
39
-    hook_code="$(inigrep -j -p hook.$SATURNIN_SUBCOMMAND.$hname)"
39
+    hook_code="$(inigrep -j -p "hook.$SATURNIN_SUBCOMMAND.$hname")"
40 40
     debug -v SATURNIN_SUBCOMMAND hook_code hname
41 41
     bash -n <<<"$hook_code" || {
42 42
         warn "syntax errors, ignoring hook: $hname"
@@ -46,14 +46,13 @@ saturnin_runhook() {
46 46
 }
47 47
 
48 48
 saturnin_runsc() {
49
-    local sc_es=0   # future exit (return) status
50 49
     local lexpath="$SATURNIN_LIBEXEC/saturnin-$SATURNIN_SUBCOMMAND"
51 50
     debug -v lexpath
52 51
     debug "\$*='$*'"
53 52
     test -x "$lexpath" || {
54 53
         warn "invalid sub-command: $SATURNIN_SUBCOMMAND"
55 54
         saturnin_help
56
-        return $FFOO_EXIT_USAGE
55
+        return "$FFOO_EXIT_USAGE"
57 56
     }
58 57
     "$lexpath" "$@"
59 58
 }

+ 5
- 5
src/ffoo/saturnin_urimagic.sh View File

@@ -28,7 +28,7 @@ saturnin_urimagic__scan() {
28 28
     #
29 29
     local d=$(mktemp -d -t saturnin_urimagic.XXXXXXXX)
30 30
     local p=__saturnin_urimagic__
31
-    pushd $d >&/dev/null
31
+    pushd "$d" >&/dev/null
32 32
         ##
33 33
         # heat up and fill pipes
34 34
         #
@@ -55,7 +55,7 @@ saturnin_urimagic__scan() {
55 55
             cat uris_from_kws
56 56
         } | grep .  # throw away empties; add missing LF
57 57
     popd >&/dev/null
58
-    rm -rf $d
58
+    rm -rf "$d"
59 59
 }
60 60
 
61 61
 __saturnin_urimagic__deref() {
@@ -72,11 +72,11 @@ __saturnin_urimagic__deref() {
72 72
         debug -v kw query
73 73
         if test -n "$query";
74 74
         then
75
-            local fmt=$(inigrep -j -1 -p $pfxN.${kw,,})
75
+            local fmt=$(inigrep -j -1 -p "$pfxN.${kw,,}")
76 76
             debug -v fmt
77 77
             printf "$fmt\n" "$query"
78 78
         else
79
-            inigrep -j -1 -p $pfx0.$kw
79
+            inigrep -j -1 -p "$pfx0.$kw"
80 80
         fi
81 81
     done
82 82
 }
@@ -85,7 +85,7 @@ __saturnin_urimagic__flt_exps() {
85 85
     #
86 86
     # Hack expressions like bug = 123 out of the text
87 87
     #
88
-    sed -e 's/(\d)\</\n/;'\
88
+    sed -e 's/(\d)\</\n/;' \
89 89
       | perl -ne '
90 90
             next unless m/\b([a-zA-Z]\w*\s*=\s*\w+)\b/;
91 91
             print "$1\n";

+ 16
- 16
src/ffoo/saturnin_zleep.sh View File

@@ -11,9 +11,9 @@ __zleep_user_part() {
11 11
 
12 12
 __zleep_try_umount() {
13 13
     local mp=$1
14
-    mountpoint -q $mp || return 0
15
-    umount        $mp || return 1
16
-    mount | grep  $mp && return 1
14
+    mountpoint -q "$mp" || return 0
15
+    umount        "$mp" || return 1
16
+    mount | grep  "$mp" && return 1
17 17
     return 0
18 18
 }
19 19
 
@@ -21,7 +21,7 @@ __zleep_try_umount_all() {
21 21
     local mp
22 22
     for mp in $(inigrep -p iam.mounting.point);
23 23
     do
24
-        __zleep_try_umount $mp || return 1
24
+        __zleep_try_umount "$mp" || return 1
25 25
     done
26 26
     return 0
27 27
 }
@@ -33,25 +33,25 @@ __zleep_sudo_part() {
33 33
 
34 34
 __zleep_sudo_part_started() {
35 35
     # i.e. password prompt went ok
36
-    test -e $ZLEEP_ON_ROOT
36
+    test -e "$ZLEEP_ON_ROOT"
37 37
     rv=$?
38 38
     debug -v rv
39 39
     return $rv
40 40
 }
41 41
 
42 42
 __zleep_user_part_done() {
43
-    ! test -e $ZLEEP_ON_USER
43
+    ! test -e "$ZLEEP_ON_USER"
44 44
     rv=$?
45 45
     debug -v rv
46 46
     return $rv
47 47
 }
48 48
 
49 49
 __zleep_min_path() {
50
-    echo -n $(sudo env | grep ^PATH)
50
+    echo -n "$(sudo env | grep ^PATH)"
51 51
     echo -n :
52
-    echo -n $(dirname $(which ffoom))
52
+    echo -n "$(dirname "$(which ffoom)")"
53 53
     echo -n :
54
-    echo -n $(dirname $(which saturnin))
54
+    echo -n "$(dirname "$(which saturnin)")"
55 55
 }
56 56
 
57 57
 zleep() {
@@ -76,19 +76,19 @@ zleep() {
76 76
         SUDO_PATH=$(__zleep_min_path)   # needed while bins are still under local
77 77
         debug -v ZLEEP_ON_USER ZLEEP_ON_ROOT SUDO_PATH
78 78
         sudo env \
79
-            ZLEEP_ON_ROOT=$ZLEEP_ON_ROOT \
80
-            ZLEEP_ON_USER=$ZLEEP_ON_USER \
81
-            PATH=$SUDO_PATH \
79
+            ZLEEP_ON_ROOT="$ZLEEP_ON_ROOT" \
80
+            ZLEEP_ON_USER="$ZLEEP_ON_USER" \
81
+            PATH="$SUDO_PATH" \
82 82
             saturnin iam zleeping &
83 83
         wait_until -t 60 __zleep_sudo_part_started    # i.e. password prompt done
84 84
         __zleep_user_part
85
-        rm -f $ZLEEP_ON_USER
85
+        rm -f "$ZLEEP_ON_USER"
86 86
     else                            ## we are child (running as root)
87
-        touch $ZLEEP_ON_ROOT
88
-        test $(id -u) -eq 0         || die "must be root"
87
+        touch "$ZLEEP_ON_ROOT"
88
+        test "$(id -u)" -eq 0               || die "must be root"
89 89
         wait_until __zleep_user_part_done   || die "timeout waiting for parent"
90 90
         __zleep_sudo_part
91
-        rm -f $ZLEEP_ON_ROOT
91
+        rm -f "$ZLEEP_ON_ROOT"
92 92
         return $?
93 93
     fi
94 94
 }

+ 1
- 1
src/libexec/saturnin-au View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import pretty
6 6
 

+ 12
- 14
src/libexec/saturnin-clip View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -25,7 +25,7 @@ clipln() {
25 25
     #
26 26
     case $1 in
27 27
         primary|secondary|clipboard)
28
-            xclip -o -selection $1   2>/dev/null
28
+            xclip -o -selection "$1"   2>/dev/null
29 29
             ;;
30 30
         ALL)
31 31
             xclip -o -selection primary   2>/dev/null
@@ -43,29 +43,28 @@ save_clip() {
43 43
     local clipname=$1
44 44
     mkdir -p "$STORAGE_DIR" || die "could not create directory for saving"
45 45
     local path="$STORAGE_DIR/$(date +%Y%m%d-%H%M%S.clip)"
46
-    clipln $clipname > "$path"
46
+    clipln "$clipname" > "$path"
47 47
 }
48 48
 
49 49
 lsclips() {
50 50
     #
51 51
     # List clips with MIME types and hints
52 52
     #
53
-    local clipname=$1
54 53
     local ft hint name
55 54
     test -d "$STORAGE_DIR" || return 0
56
-    ls "$STORAGE_DIR/"*.clip 2>/dev/null \
55
+    find "$STORAGE_DIR" -name "*.clip" 2>/dev/null \
57 56
       | while read name;
58 57
         do
59
-            ft=$(file -b -i $name | cut -d\; -f1)
58
+            ft=$(file -b -i "$name" | cut -d\; -f1)
60 59
             case $ft in
61 60
                 text/*)
62
-                    hint=$(head -c 80 $name | tr '\n' '↵')
61
+                    hint=$(head -c 80 "$name" | tr '\n' '↵')
63 62
                     ;;
64 63
                 *)
65
-                    hint=$(head -c 16 $name | hexdump -C | head -1)
64
+                    hint=$(head -c 16 "$name" | hexdump -C | head -1)
66 65
                     ;;
67 66
             esac
68
-            echos "$(basename $name) || $ft || $hint"
67
+            echos "$(basename "$name") || $ft || $hint"
69 68
         done
70 69
 }
71 70
 
@@ -83,17 +82,16 @@ load_clip() {
83 82
     local clipname=$1
84 83
     local name=$(pick_clip)
85 84
     test -n "$name" || return 1
86
-    cat $STORAGE_DIR/$name | xclip -i -selection $clipname
85
+    < "$STORAGE_DIR/$name" xclip -i -selection "$clipname"
87 86
 }
88 87
 
89 88
 rm_clip() {
90 89
     #
91 90
     # Remove single clip of choice
92 91
     #
93
-    local clipname=$1
94 92
     local name=$(pick_clip)
95 93
     test -n "$name" || return 1
96
-    rm -f $STORAGE_DIR/$name
94
+    rm -f "$STORAGE_DIR/$name"
97 95
 }
98 96
 
99 97
 rm_all() {
@@ -102,7 +100,7 @@ rm_all() {
102 100
     #
103 101
     test -n "$STORAGE_DIR" || die "storage directory is unset, aborting"
104 102
     test -d "$STORAGE_DIR" || return 0
105
-    find "$STORAGE_DIR" -name "*.clip" | xargs rm -f
103
+    find "$STORAGE_DIR" -name "*.clip" -print0 | xargs -0 rm -f
106 104
     rmdir "$STORAGE_DIR" 2>/dev/null | :
107 105
 }
108 106
 
@@ -129,7 +127,7 @@ while true; do case "$1" in
129 127
     *)      usage                     ;;
130 128
 esac done
131 129
 
132
-debug "\$@='$@'"
130
+debug "\$*='$*'"
133 131
 debug -v clipname action
134 132
 
135 133
 case $action in

+ 3
- 4
src/libexec/saturnin-dmenu View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -9,7 +9,6 @@ usage() {
9 9
     mkusage "[-l|--lines NUM] [--split CHAR] ARGS..."
10 10
 }
11 11
 
12
-numbered=false
13 12
 lines=10
14 13
 maybe_split=cat
15 14
 delim=" "
@@ -41,7 +40,7 @@ style() {
41 40
 }
42 41
 
43 42
 do_split() {
44
-    cut "-d$delim" -f$field
43
+    cut "-d$delim" -f"$field"
45 44
 }
46 45
 
47
-dmenu -b -i -l $lines $(style) "$@" | $maybe_split
46
+dmenu -b -i -l "$lines" "$(style)" "$@" | $maybe_split

+ 7
- 7
src/libexec/saturnin-iam View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -17,7 +17,7 @@ ffoo import saturnin_zleep
17 17
 available_commands="afk at back gone ooo wfh undocking zleeping"
18 18
 
19 19
 usage() {
20
-    mkusage $available_commands
20
+    mkusage "$available_commands"
21 21
 }
22 22
 
23 23
 
@@ -31,7 +31,7 @@ where_i_am() {
31 31
     #
32 32
     if=$(inigrep -p iam.using.if)
33 33
     gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
34
-    inigrep -p iam.seeing.gw.$gwmac || echo OUT
34
+    inigrep -p "iam.seeing.gw.$gwmac" || echo OUT
35 35
 }
36 36
 
37 37
 set_status() {
@@ -39,8 +39,8 @@ set_status() {
39 39
     # set public status $1 by command in conf file
40 40
     #
41 41
     local what=$1
42
-    saturnin_runhook say_$what
43
-    saturnin_runhook log_$what
42
+    saturnin_runhook "say_$what"
43
+    saturnin_runhook "log_$what"
44 44
 }
45 45
 
46 46
 
@@ -119,8 +119,8 @@ cmd=$1
119 119
 
120 120
 test -n "$cmd" || usage
121 121
 
122
-echo $available_commands | grep -qw "$cmd" || usage
122
+echo "$available_commands" | grep -qw "$cmd" || usage
123 123
 
124 124
 shift
125 125
 
126
-i_am_$cmd $1
126
+"i_am_$cmd" "$1"

+ 2
- 2
src/libexec/saturnin-kb View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -22,7 +22,7 @@ next_layout() {
22 22
     local def="$default_layout"
23 23
     local nxt=$(
24 24
         echo -e "$all\n$all" \
25
-          | grep -m 1 -A 1 $cur \
25
+          | grep -m 1 -A 1 "$cur" \
26 26
           | tail -1
27 27
     )
28 28
     test -z "$nxt" && nxt=$def

+ 4
- 4
src/libexec/saturnin-ln View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -22,12 +22,12 @@ link() {
22 22
     local src=$1
23 23
     local dst=$2
24 24
     think "linking $src to $dst"
25
-    rm -f $dst
26
-    ln -sr $src $dst
25
+    rm -f "$dst"
26
+    ln -sr "$src" "$dst"
27 27
 }
28 28
 
29 29
 load() {
30
-    inigrep -p ln.dir.$1 | expand_tilde
30
+    inigrep -p "ln.dir.$1" | expand_tilde
31 31
 }
32 32
 
33 33
 while true; do case $1 in

+ 12
- 12
src/libexec/saturnin-menu View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -28,7 +28,7 @@ load_parts() {
28 28
     mname="$SATURNIN_MENU_MNAME"
29 29
 
30 30
     # check that menu item exists
31
-    inigrep -s menu.$mname | grep -q . \
31
+    inigrep -s "menu.$mname" | grep -q . \
32 32
      || die "no such menu: $mname"
33 33
 
34 34
     test -n "$SATURNIN_MENU_GENERATOR" \
@@ -62,12 +62,12 @@ get_generator() {
62 62
     # then for items as 'item' keys at the same place,
63 63
     # finally default 'generator'.
64 64
     #
65
-    inigrep -1 -p menu.$mname.generator | grep . \
65
+    inigrep -1 -p "menu.$mname.generator" | grep . \
66 66
      && return 0
67
-    inigrep -p menu.$mname.item | grep -m 1 -q . \
68
-     && printf "inigrep -p menu.$mname.item" \
67
+    inigrep -p "menu.$mname.item" | grep -m 1 -q . \
68
+     && echo "inigrep -p menu.$mname.item" \
69 69
      && return 0
70
-    inigrep -1 -p menu._default_.generator | grep . \
70
+    inigrep -1 -p "menu._default_.generator" | grep . \
71 71
      && return 0
72 72
     return 1
73 73
 }
@@ -79,9 +79,9 @@ get_selector() {
79 79
     # First, look for 'selector' key in menu definition,
80 80
     # then a default 'selector'.
81 81
     #
82
-    inigrep -1 -p menu.$mname.selector | grep . \
82
+    inigrep -1 -p "menu.$mname.selector" | grep . \
83 83
      && return 0
84
-    inigrep -1 -p menu._default_.selector | grep .
84
+    inigrep -1 -p "menu._default_.selector" | grep .
85 85
 }
86 86
 
87 87
 get_select_args() {
@@ -91,9 +91,9 @@ get_select_args() {
91 91
     # First, look for 'select_args' key in menu definition,
92 92
     # then a default 'select_args'.
93 93
     #
94
-    inigrep -1 -p menu.$mname.select_args | grep . \
94
+    inigrep -1 -p "menu.$mname.select_args" | grep . \
95 95
      && return 0
96
-    inigrep -1 -p menu._default_.select_args
96
+    inigrep -1 -p "menu._default_.select_args"
97 97
 }
98 98
 
99 99
 get_consumer() {
@@ -103,9 +103,9 @@ get_consumer() {
103 103
     # First, look for 'consumer' key in menu definition,
104 104
     # then a default 'consumer'.
105 105
     #
106
-    inigrep -1 -p menu.$mname.consumer | grep . \
106
+    inigrep -1 -p "menu.$mname.consumer" | grep . \
107 107
      && return 0
108
-    inigrep -1 -p menu._default_.consumer | grep .
108
+    inigrep -1 -p "menu._default_.consumer" | grep .
109 109
 }
110 110
 
111 111
 do_generate() {

+ 3
- 3
src/libexec/saturnin-uris View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $(ffoom path)
3
+. "$(ffoom path)"
4 4
 
5 5
 ffoo import inigrep
6 6
 ffoo import pretty
@@ -51,12 +51,12 @@ while true; do case "$1" in
51 51
     *)  break ;;
52 52
 esac done
53 53
 
54
-debug "\$@='$@'"
54
+debug "\$*='$*'"
55 55
 debug -v src
56 56
 
57 57
 case "$src" in
58 58
     args) uri="$(echo "$@" | saturnin_urimagic__scan)" ;;
59
-    file) uri="$(cat "$file" | saturnin_urimagic__scan)" ;;
59
+    file) uri="$(<"$file" saturnin_urimagic__scan)" ;;
60 60
     xpri) uri="$(clipln pri | saturnin_urimagic__scan)" ;;
61 61
     xsec) uri="$(clipln sec | saturnin_urimagic__scan)" ;;
62 62
     xclp) uri="$(clipln clp | saturnin_urimagic__scan)" ;;

+ 11
- 12
src/libexec/saturnin-xuris View File

@@ -2,7 +2,7 @@
2 2
 
3 3
 # launch Uzbl once per each URI in stdin
4 4
 
5
-. $(ffoom path) || exit 3
5
+. "$(ffoom path)" || exit 3
6 6
 ffoo import pretty
7 7
 
8 8
 SATURNIN_XURIS_NOTIFICATIONS=true
@@ -65,23 +65,22 @@ notify() {
65 65
 
66 66
 open_from() {
67 67
     local list="$1"
68
-    local count=$(wc -l <$list)
68
+    local count=$(wc -l <"$list")
69 69
 
70
-    test $count -gt $SATURNIN_XURIS_LIMIT && {
70
+    test "$count" -gt $SATURNIN_XURIS_LIMIT && {
71 71
         notify "too much URIs; giving up: $count > $SATURNIN_XURIS_LIMIT"
72 72
         return 1
73 73
     }
74 74
 
75
-    test $count -eq 0 && {
75
+    test "$count" -eq 0 && {
76 76
         $SATURNIN_XURIS_ALWAYS_RUN && $SATURNIN_XURIS_BIN &
77 77
         return 0
78 78
     }
79 79
 
80
-    cat $list \
81
-      | while read uri;
82
-        do
83
-            $SATURNIN_XURIS_BIN "$uri" &
84
-        done
80
+    while read uri;
81
+    do
82
+        $SATURNIN_XURIS_BIN "$uri" &
83
+    done < "$list"
85 84
 }
86 85
 
87 86
 while true; do case $1 in
@@ -103,7 +102,7 @@ debug -v SATURNIN_XURIS_ALWAYS_RUN \
103 102
          SATURNIN_XURIS_UNIQ
104 103
 
105 104
 SATURNIN_XURIS_URI_LIST=$(mktemp -t saturnin-xuris.XXXXXXXX)
106
-cat | maybe_uniq | grep . >$SATURNIN_XURIS_URI_LIST
105
+cat | maybe_uniq | grep . >"$SATURNIN_XURIS_URI_LIST"
107 106
 
108 107
 # choice of URI has been made; we may try to use dmenu
109 108
 bash -n <<<"$SATURNIN_XURIS_CHOICE"
@@ -112,5 +111,5 @@ SATURNIN_XURIS_BIN="${SATURNIN_XURIS_BIN:-$(decide_bin)}"
112 111
 
113 112
 debug -v SATURNIN_XURIS_BIN
114 113
 
115
-open_from $SATURNIN_XURIS_URI_LIST
116
-rm $SATURNIN_XURIS_URI_LIST
114
+open_from "$SATURNIN_XURIS_URI_LIST"
115
+rm "$SATURNIN_XURIS_URI_LIST"

+ 1
- 2
tests/TF_HEADER View File

@@ -1,4 +1,3 @@
1 1
 #!/bin/sh
2 2
 
3
-echo -n "version: ";
4
-saturnin --version-semver
3
+echo "version: $(saturnin --version-semver)"

+ 2
- 2
tests/cli/TF_RUN View File

@@ -1,7 +1,7 @@
1 1
 #!/bin/bash
2 2
 
3
-. $TF_DIR/include/subtest.sh
4
-. $TF_DIR/include/tools.sh
3
+. "$TF_DIR/include/subtest.sh"
4
+. "$TF_DIR/include/tools.sh"
5 5
 
6 6
 tf_enum_subtests() {
7 7
     echo usage