Browse Source

Use more compact `do`/`then` form

Drop the unnecessary and space-wasting requirement that `do` and `then`
must be alone on line.  It's a thing of the past!
Alois Mahdal 7 years ago
parent
commit
b44e804804
6 changed files with 24 additions and 47 deletions
  1. 6
    12
      src/include/build.sh
  2. 6
    12
      src/include/deploy.sh
  3. 1
    2
      src/include/facts.sh
  4. 8
    15
      src/include/ini.sh
  5. 2
    4
      src/include/mkit.sh
  6. 1
    2
      src/include/release.sh

+ 6
- 12
src/include/build.sh View File

68
     local varvalue      # each token value
68
     local varvalue      # each token value
69
     script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
69
     script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
70
     {
70
     {
71
-        for section in "$@";
72
-        do
71
+        for section in "$@"; do
73
             debug_var section
72
             debug_var section
74
             ini lskeys "$section" \
73
             ini lskeys "$section" \
75
-              | while read -r varname;
76
-                do
74
+              | while read -r varname; do
77
                     varvalue="$(ini 1value "$section:$varname" | _qfs )"
75
                     varvalue="$(ini 1value "$section:$varname" | _qfs )"
78
                     echo "s|$varname|$varvalue|g;"
76
                     echo "s|$varname|$varvalue|g;"
79
                     debug_var varname varvalue
77
                     debug_var varname varvalue
120
     #
118
     #
121
     local srcpath   # each source path
119
     local srcpath   # each source path
122
     find -type f -name '*.skel' \
120
     find -type f -name '*.skel' \
123
-     | while read -r srcpath;
124
-       do
121
+     | while read -r srcpath; do
125
            _build1 "$srcpath"
122
            _build1 "$srcpath"
126
        done
123
        done
127
 }
124
 }
132
     #
129
     #
133
     local manfile   # each manual file listed in '[files:man]'
130
     local manfile   # each manual file listed in '[files:man]'
134
     local mdfile    # each source markdown file
131
     local mdfile    # each source markdown file
135
-    if command -v ronn >/dev/null;
136
-    then
132
+    if command -v ronn >/dev/null; then
137
         ini lskeys "files:man" \
133
         ini lskeys "files:man" \
138
-          | while read -r manfile;
139
-            do
134
+          | while read -r manfile; do
140
                 mdfile="$manfile.md"
135
                 mdfile="$manfile.md"
141
                 ronn -r "$mdfile"
136
                 ronn -r "$mdfile"
142
                 mkdir -p "$MKIT_LOCAL"
137
                 mkdir -p "$MKIT_LOCAL"
185
     test -d "$debian_skel" || die "debian directory template found: $debian_skel"
180
     test -d "$debian_skel" || die "debian directory template found: $debian_skel"
186
     mkdir -p debian/source
181
     mkdir -p debian/source
187
     find "$debian_skel" -type f \
182
     find "$debian_skel" -type f \
188
-      | while read -r dfsrc;
189
-        do
183
+      | while read -r dfsrc; do
190
             dftgt="debian/${dfsrc#$debian_skel}"
184
             dftgt="debian/${dfsrc#$debian_skel}"
191
             mkdir -p "$(dirname "$dftgt")"
185
             mkdir -p "$(dirname "$dftgt")"
192
             _build1 "$dfsrc" "$dftgt" debstuff
186
             _build1 "$dfsrc" "$dftgt" debstuff

+ 6
- 12
src/include/deploy.sh View File

27
     local dst=$2                            # destination path
27
     local dst=$2                            # destination path
28
     local mode=${3:-$MKIT_DEFAULT_MODE}     # mode
28
     local mode=${3:-$MKIT_DEFAULT_MODE}     # mode
29
     local chmod_item                        # each file to chmod in directory
29
     local chmod_item                        # each file to chmod in directory
30
-    if test -d "$src";
31
-    then
30
+    if test -d "$src"; then
32
         _maybe mkdir -vp "$(dirname "$dst")"
31
         _maybe mkdir -vp "$(dirname "$dst")"
33
         _maybe cp -Tvr "$src" "$dst"
32
         _maybe cp -Tvr "$src" "$dst"
34
         find "$dst" -type f \
33
         find "$dst" -type f \
35
-          | while read -r chmod_item;
36
-            do
34
+          | while read -r chmod_item; do
37
                 _maybe chmod "$mode" "$chmod_item"
35
                 _maybe chmod "$mode" "$chmod_item"
38
             done
36
             done
39
     else
37
     else
94
     ini lskeys "files" \
92
     ini lskeys "files" \
95
       | sort \
93
       | sort \
96
       | uniq \
94
       | uniq \
97
-      | while read -r group;
98
-        do
95
+      | while read -r group; do
99
             mode=$(ini 1value "modes:$group")
96
             mode=$(ini 1value "modes:$group")
100
             ini values "files:$group" \
97
             ini values "files:$group" \
101
-              | while read -r src dst;
102
-                do
98
+              | while read -r src dst; do
103
                     dst=$(_get_dst "$group" "$src" "$dst")
99
                     dst=$(_get_dst "$group" "$src" "$dst")
104
                     _deploy_item "$src" "$dst" "$mode"
100
                     _deploy_item "$src" "$dst" "$mode"
105
                 done
101
                 done
118
     ini lskeys "files" \
114
     ini lskeys "files" \
119
       | sort \
115
       | sort \
120
       | uniq \
116
       | uniq \
121
-      | while read -r group;
122
-        do
117
+      | while read -r group; do
123
             ini values "files:$group" \
118
             ini values "files:$group" \
124
-              | while read -r src dst;
125
-                do
119
+              | while read -r src dst; do
126
                     dst=$(_get_dst "$group" "$src" "$dst")
120
                     dst=$(_get_dst "$group" "$src" "$dst")
127
                     _maybe rm -vrf "$dst"
121
                     _maybe rm -vrf "$dst"
128
                 done
122
                 done

+ 1
- 2
src/include/facts.sh View File

89
     # target, but that's actually expected.)
89
     # target, but that's actually expected.)
90
     #
90
     #
91
     local last_hash     # last commit hash
91
     local last_hash     # last commit hash
92
-    if git_present;
93
-    then    # we are in git repo
92
+    if git_present; then    # we are in git repo
94
         last_hash=$(git rev-parse HEAD)
93
         last_hash=$(git rev-parse HEAD)
95
         echo -n "$last_hash"
94
         echo -n "$last_hash"
96
         git_bool dirty && echo -n ".dirty"
95
         git_bool dirty && echo -n ".dirty"

+ 8
- 15
src/include/ini.sh View File

5
     # A no-op for text stream
5
     # A no-op for text stream
6
     #
6
     #
7
     local line      # each line
7
     local line      # each line
8
-    while read -r line;
9
-    do
8
+    while read -r line; do
10
         printf -- "%s\n" "$line"
9
         printf -- "%s\n" "$line"
11
     done
10
     done
12
 }
11
 }
19
     local suffix    # tail of the line
18
     local suffix    # tail of the line
20
     local ref       # reference
19
     local ref       # reference
21
     local value     # value if reference
20
     local value     # value if reference
22
-    while read -r line;                     # [foo:bar]/path
23
-    do
21
+    while read -r line; do                  # [foo:bar]/path
24
         suffix="${line#\[*\]}"              # /path
22
         suffix="${line#\[*\]}"              # /path
25
         ref="${line%$suffix}"               # [foo:bar]
23
         ref="${line%$suffix}"               # [foo:bar]
26
         ref="${ref%\]}"                     # [foo:bar
24
         ref="${ref%\]}"                     # [foo:bar
56
     local wntkey=${wnt##*:}         # ^^ key part
54
     local wntkey=${wnt##*:}         # ^^ key part
57
     local wntsec=${wnt%:$wntkey}    # ^^ section part
55
     local wntsec=${wnt%:$wntkey}    # ^^ section part
58
     local override                  # ENV override (only ENV section)
56
     local override                  # ENV override (only ENV section)
59
-    if test "$wntsec" = 'ENV';
60
-    then
57
+    if test "$wntsec" = 'ENV'; then
61
         override=${!wntkey}
58
         override=${!wntkey}
62
-        if test -n "$override";
63
-        then
64
-            echo "$override"
65
-            return
66
-        fi
59
+        test -n "$override" \
60
+         && echo "$override" \
61
+         && return
67
     fi
62
     fi
68
     _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
63
     _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
69
 }
64
 }
77
     local line          # each input line
72
     local line          # each input line
78
     grep '.' \
73
     grep '.' \
79
       | grep -v '\s*#' \
74
       | grep -v '\s*#' \
80
-      | while read -r line;
81
-        do
75
+      | while read -r line; do
82
             case "$line" in
76
             case "$line" in
83
                 \[$wnt\]) ok=true;  continue ;;
77
                 \[$wnt\]) ok=true;  continue ;;
84
                 \[*\])    ok=false; continue ;;
78
                 \[*\])    ok=false; continue ;;
101
     #
95
     #
102
     # Decide whether or not to expand
96
     # Decide whether or not to expand
103
     #
97
     #
104
-    if test "$MKIT_INI_EXPAND" -gt 0;
105
-    then
98
+    if test "$MKIT_INI_EXPAND" -gt 0; then
106
         MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
99
         MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
107
     else
100
     else
108
         _ini_cat
101
         _ini_cat

+ 2
- 4
src/include/mkit.sh View File

39
     #
39
     #
40
     $MKIT_DEBUG || return 0
40
     $MKIT_DEBUG || return 0
41
     local __mkit_debug_var_name__       # variable name to debug
41
     local __mkit_debug_var_name__       # variable name to debug
42
-    for __mkit_debug_var_name__ in "$@";
43
-    do
42
+    for __mkit_debug_var_name__ in "$@"; do
44
         {
43
         {
45
             echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
44
             echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
46
             echo -n " $__mkit_debug_var_name__"
45
             echo -n " $__mkit_debug_var_name__"
125
     #
124
     #
126
     # Call correct function based on $1
125
     # Call correct function based on $1
127
     #
126
     #
128
-    if _valid_targets | grep -qwx "^$1";
129
-    then
127
+    if _valid_targets | grep -qwx "^$1"; then
130
         "$1"
128
         "$1"
131
     else
129
     else
132
         {
130
         {

+ 1
- 2
src/include/release.sh View File

107
 
107
 
108
     reldst=$(ini 1value project:reldst)
108
     reldst=$(ini 1value project:reldst)
109
     debug_var reldst
109
     debug_var reldst
110
-    if test -n "$reldst";
111
-    then
110
+    if test -n "$reldst"; then
112
         git branch -f "$reldst" "$newtag"
111
         git branch -f "$reldst" "$newtag"
113
     fi
112
     fi
114
 }
113
 }