Skip to content

Commit f85a840

Browse files
committed
refactor(mcrypt,postcat,svcadm,tar,wodim): if ((v)) => if [[ $v ]]
1 parent 5f5d869 commit f85a840

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

completions/mcrypt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ _mcrypt()
4949
elif [[ ${words[0]} == mdecrypt ]]; then
5050
_filedir nc
5151
else
52-
local i decrypt=0
52+
local i decrypt=""
5353
for ((i = 1; i < ${#words[@]} - 1; i++)); do
5454
if [[ ${words[i]} == -@(d|-decrypt) ]]; then
5555
_filedir nc
56-
decrypt=1
56+
# shellcheck disable=SC2209
57+
decrypt=set
5758
break
5859
fi
5960
done
60-
if ((decrypt == 0)); then
61+
if [[ ! $decrypt ]]; then
6162
_filedir
6263
fi
6364
fi

completions/postcat

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ _postcat()
1717
return
1818
fi
1919

20-
local idx qfile=0
20+
local idx qfile=""
2121
for idx in "${words[@]}"; do
22-
[[ $idx == -q ]] && qfile=1 && break
22+
# shellcheck disable=SC2209
23+
[[ $idx == -q ]] && qfile=set && break
2324
done
24-
if ((qfile == 1)); then
25+
if [[ $qfile ]]; then
2526
local len=${#cur} pval
2627
for pval in $(mailq 2>/dev/null |
2728
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do

completions/svcadm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ _smf_complete_fmri()
2929
if [[ $cur == $prefix* ]]; then
3030
[[ $cur == "$prefix" ]] && cur+="/"
3131
pattern="$cur*"
32-
exact_mode=1
32+
# shellcheck disable=SC2209
33+
exact_mode=set
3334
else
3435
pattern="$prefix*/$cur*"
3536
fi

completions/tar

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,19 @@ __tar_parse_old_opt()
170170
local first_word char
171171

172172
# current word is the first word
173+
# shellcheck disable=SC2209
173174
[[ $cword -eq 1 && $cur && ${cur:0:1} != '-' ]] &&
174-
old_opt_progress=1
175+
old_opt_progress=set
175176

176177
# check that first argument does not begin with "-"
177178
first_word=${words[1]}
179+
# shellcheck disable=SC2209
178180
[[ $first_word && ${first_word:0:1} != "-" ]] &&
179-
old_opt_used=1
181+
old_opt_used=set
180182

181183
# parse the old option (if present) contents to allow later code expect
182184
# corresponding arguments
183-
if ((old_opt_used == 1)); then
185+
if [[ $old_opt_used ]]; then
184186
char=${first_word:0:1}
185187
while [[ $char ]]; do
186188
if __tar_is_argreq "$char"; then
@@ -195,13 +197,13 @@ __tar_parse_old_opt()
195197
# Make the analysis of whole command line.
196198
__tar_preparse_cmdline()
197199
{
198-
local first_arg i modes="ctxurdA"
200+
# shellcheck disable=SC2209
201+
local first_arg=set i modes="ctxurdA"
199202

200203
shift # progname
201204

202205
__tar_parse_old_opt
203206

204-
first_arg=1
205207
for i in "$@"; do
206208
case "$i" in
207209
--delete | --test-label)
@@ -220,14 +222,14 @@ __tar_preparse_cmdline()
220222
;;
221223
*[$modes]*)
222224
# Only the first arg may be "MODE" without leading dash
223-
if ((first_arg == 1)); then
225+
if [[ $first_arg ]]; then
224226
tar_mode=${i//[^$modes]/}
225227
tar_mode=${tar_mode:0:1}
226228
tar_mode_arg=$i
227229
fi
228230
;;
229231
esac
230-
first_arg=0
232+
first_arg=""
231233
done
232234
}
233235

@@ -306,7 +308,7 @@ __tar_complete_mode()
306308

307309
# The last short option requires argument, like '-cf<TAB>'. Cut the
308310
# completion here to enforce argument processing.
309-
if ((old_opt_progress == 0)) &&
311+
if [[ ! $old_opt_progress ]] &&
310312
__tar_is_argreq "$(__tar_last_char "$cur")"; then
311313
COMPREPLY=("$cur") && return 0
312314
fi
@@ -383,7 +385,7 @@ __tar_adjust_PREV_from_old_option()
383385
# deal with old style arguments here
384386
# $ tar cfTC # expects this sequence of arguments:
385387
# $ tar cfTC ARCHIVE_FILE PATTERNS_FILE CHANGE_DIR
386-
if ((old_opt_used == 1 && cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then
388+
if [[ $old_opt_used ]] && ((cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then
387389
# make e.g. 'C' option from 'cffCT'
388390
prev="-${old_opt_parsed[cword - 2]}"
389391
fi
@@ -488,8 +490,8 @@ _gtar()
488490
local long_opts short_opts basic_tar="" \
489491
long_arg_none="" long_arg_opt="" long_arg_req="" \
490492
short_arg_none="" short_arg_opt="" short_arg_req="" \
491-
tar_mode tar_mode_arg old_opt_progress=0 \
492-
old_opt_used=0 old_opt_parsed=()
493+
tar_mode tar_mode_arg old_opt_progress="" \
494+
old_opt_used="" old_opt_parsed=()
493495

494496
# Main mode, e.g. -x or -c (extract/creation)
495497
local tar_mode=none
@@ -679,8 +681,8 @@ _posix_tar()
679681
local long_opts short_opts basic_tar=set \
680682
long_arg_none="" long_arg_opt long_arg_req="" \
681683
short_arg_none short_arg_opt short_arg_req \
682-
tar_mode tar_mode_arg old_opt_progress=0 \
683-
old_opt_used=1 old_opt_parsed=()
684+
tar_mode tar_mode_arg old_opt_progress="" \
685+
old_opt_used=set old_opt_parsed=()
684686

685687
# Main mode, e.g. -x or -c (extract/creation)
686688
local tar_mode=none

completions/wodim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@ _cdrecord()
6666
-isosize -pad -nopad -shorttrack -noshorttrack -preemp -nopreemp
6767
-copy -nocopy -scms "isrc=" "index=" "padsize=" "pregap=" "tsize=")
6868
# look if previous was either a file or a track option
69-
track_mode=0
69+
track_mode=""
7070
if ((cword > 1)); then
7171
if [[ -f $prev ]]; then
72-
track_mode=1
72+
# shellcheck disable=SC2209
73+
track_mode=set
7374
else
7475
local opt
7576
for opt in "${track_options[@]}"; do
7677
if [[ $opt == "$prev" ]]; then
77-
track_mode=1
78+
# shellcheck disable=SC2209
79+
track_mode=set
7880
break
7981
fi
8082
done
@@ -86,7 +88,7 @@ _cdrecord()
8688
# track options are always available
8789
COMPREPLY+=($(compgen -W '"${track_options[@]}"' -- "$cur"))
8890
# general options are no more available after file or track option
89-
if ((track_mode == 0)); then
91+
if [[ ! $track_mode ]]; then
9092
COMPREPLY+=($(compgen -W '"${generic_options[@]}"' -- "$cur"))
9193
fi
9294
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace

0 commit comments

Comments
 (0)