Skip to content

Commit bbafd60

Browse files
akinomyogascop
authored andcommitted
refactor(mcrypt,postcat,svcadm,tar,wodim): if ((v)) => if [[ $v ]]
1 parent 5580a6e commit bbafd60

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

completions/mcrypt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ _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+
decrypt=set
5757
break
5858
fi
5959
done
60-
if ((decrypt == 0)); then
60+
if [[ ! $decrypt ]]; then
6161
_filedir
6262
fi
6363
fi

completions/postcat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ _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+
[[ $idx == -q ]] && qfile=set && break
2323
done
24-
if ((qfile == 1)); then
24+
if [[ $qfile ]]; then
2525
local len=${#cur} pval
2626
for pval in $(mailq 2>/dev/null |
2727
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do

completions/svcadm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ _smf_complete_fmri()
2929
if [[ $cur == $prefix* ]]; then
3030
[[ $cur == "$prefix" ]] && cur+="/"
3131
pattern="$cur*"
32-
exact_mode=1
32+
exact_mode=set
3333
else
3434
pattern="$prefix*/$cur*"
3535
fi

completions/tar

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ __tar_parse_old_opt()
171171

172172
# current word is the first word
173173
[[ $cword -eq 1 && $cur && ${cur:0:1} != '-' ]] &&
174-
old_opt_progress=1
174+
old_opt_progress=set
175175

176176
# check that first argument does not begin with "-"
177177
first_word=${words[1]}
178178
[[ $first_word && ${first_word:0:1} != "-" ]] &&
179-
old_opt_used=1
179+
old_opt_used=set
180180

181181
# parse the old option (if present) contents to allow later code expect
182182
# corresponding arguments
183-
if ((old_opt_used == 1)); then
183+
if [[ $old_opt_used ]]; then
184184
char=${first_word:0:1}
185185
while [[ $char ]]; do
186186
if __tar_is_argreq "$char"; then
@@ -195,13 +195,12 @@ __tar_parse_old_opt()
195195
# Make the analysis of whole command line.
196196
__tar_preparse_cmdline()
197197
{
198-
local first_arg i modes="ctxurdA"
198+
local first_arg=set i modes="ctxurdA"
199199

200200
shift # progname
201201

202202
__tar_parse_old_opt
203203

204-
first_arg=1
205204
for i in "$@"; do
206205
case "$i" in
207206
--delete | --test-label)
@@ -220,14 +219,14 @@ __tar_preparse_cmdline()
220219
;;
221220
*[$modes]*)
222221
# Only the first arg may be "MODE" without leading dash
223-
if ((first_arg == 1)); then
222+
if [[ $first_arg ]]; then
224223
tar_mode=${i//[^$modes]/}
225224
tar_mode=${tar_mode:0:1}
226225
tar_mode_arg=$i
227226
fi
228227
;;
229228
esac
230-
first_arg=0
229+
first_arg=""
231230
done
232231
}
233232

@@ -306,7 +305,7 @@ __tar_complete_mode()
306305

307306
# The last short option requires argument, like '-cf<TAB>'. Cut the
308307
# completion here to enforce argument processing.
309-
if ((old_opt_progress == 0)) &&
308+
if [[ ! $old_opt_progress ]] &&
310309
__tar_is_argreq "$(__tar_last_char "$cur")"; then
311310
COMPREPLY=("$cur") && return 0
312311
fi
@@ -383,7 +382,7 @@ __tar_adjust_PREV_from_old_option()
383382
# deal with old style arguments here
384383
# $ tar cfTC # expects this sequence of arguments:
385384
# $ tar cfTC ARCHIVE_FILE PATTERNS_FILE CHANGE_DIR
386-
if ((old_opt_used == 1 && cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then
385+
if [[ $old_opt_used ]] && ((cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then
387386
# make e.g. 'C' option from 'cffCT'
388387
prev="-${old_opt_parsed[cword - 2]}"
389388
fi
@@ -488,8 +487,8 @@ _gtar()
488487
local long_opts short_opts basic_tar="" \
489488
long_arg_none="" long_arg_opt="" long_arg_req="" \
490489
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=()
490+
tar_mode tar_mode_arg old_opt_progress="" \
491+
old_opt_used="" old_opt_parsed=()
493492

494493
# Main mode, e.g. -x or -c (extract/creation)
495494
local tar_mode=none
@@ -678,8 +677,8 @@ _posix_tar()
678677
local long_opts short_opts basic_tar=set \
679678
long_arg_none="" long_arg_opt long_arg_req="" \
680679
short_arg_none short_arg_opt short_arg_req \
681-
tar_mode tar_mode_arg old_opt_progress=0 \
682-
old_opt_used=1 old_opt_parsed=()
680+
tar_mode tar_mode_arg old_opt_progress="" \
681+
old_opt_used=set old_opt_parsed=()
683682

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

completions/wodim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ _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+
track_mode=set
7373
else
7474
local opt
7575
for opt in "${track_options[@]}"; do
7676
if [[ $opt == "$prev" ]]; then
77-
track_mode=1
77+
track_mode=set
7878
break
7979
fi
8080
done
@@ -86,7 +86,7 @@ _cdrecord()
8686
# track options are always available
8787
COMPREPLY+=($(compgen -W '"${track_options[@]}"' -- "$cur"))
8888
# general options are no more available after file or track option
89-
if ((track_mode == 0)); then
89+
if [[ ! $track_mode ]]; then
9090
COMPREPLY+=($(compgen -W '"${generic_options[@]}"' -- "$cur"))
9191
fi
9292
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace

0 commit comments

Comments
 (0)