Skip to content

Commit eab5952

Browse files
committed
refactor: switch from if "$var" to if [[ $var ]]
1 parent c622d46 commit eab5952

File tree

19 files changed

+74
-74
lines changed

19 files changed

+74
-74
lines changed

bash_completion

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ _comp_expand_glob()
339339
# generated.
340340
_comp_split()
341341
{
342-
local _append=false IFS=$' \t\n'
342+
local _append="" IFS=$' \t\n'
343343

344344
local OPTIND=1 OPTARG="" OPTERR=0 _opt
345345
while getopts ':alF:' _opt "$@"; do
346346
case $_opt in
347-
a) _append=true ;;
347+
a) _append="set" ;;
348348
l) IFS=$'\n' ;;
349349
F) IFS=$OPTARG ;;
350350
*)
@@ -367,7 +367,7 @@ _comp_split()
367367
set -o noglob
368368

369369
local _old_size _new_size
370-
if "$_append"; then
370+
if [[ $_append ]]; then
371371
eval "$1+=()" # in case $1 is unset
372372
eval "_old_size=\${#$1[@]}"
373373
eval "$1+=(\$2)"
@@ -409,13 +409,13 @@ _comp_split()
409409
# array instead.
410410
_comp_compgen()
411411
{
412-
local _append=false IFS=$' \t\n'
412+
local _append="" IFS=$' \t\n'
413413
local -a _split_options=(-l)
414414

415415
local OPTIND=1 OPTARG="" OPTERR=0 _opt
416416
while getopts ':alF:' _opt "$@"; do
417417
case $_opt in
418-
a) _append=true _split_options+=(-a) ;;
418+
a) _append="set" _split_options+=(-a) ;;
419419
l) IFS=$'\n' ;;
420420
F) IFS=$OPTARG ;;
421421
*)
@@ -447,7 +447,7 @@ _comp_compgen()
447447
local _result
448448
_result=$(compgen "${@:2}") || {
449449
local _status=$?
450-
if "$_append"; then
450+
if [[ $_append ]]; then
451451
# make sure existence of variable
452452
eval -- "$1+=()"
453453
else

completions/_adb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ _comp_cmd_adb()
2525
;;
2626
esac
2727

28-
local cmd has_cmd=false i
28+
local cmd has_cmd="" i
2929
for ((i = 1; i < cword; i++)); do
3030
if [[ ${words[i]} != -* && ${words[i - 1]} != -[sp] ]]; then
3131
cmd="${words[i]}"
32-
has_cmd=true
32+
has_cmd="set"
3333
break
3434
fi
3535
done
3636

37-
if ! "$has_cmd"; then
37+
if [[ ! $has_cmd ]]; then
3838
local tmp=()
3939
if [[ ! $cur || $cur == -* ]]; then
4040
tmp+=($(compgen -W '$(_parse_help "$1" help)' -- "$cur"))

completions/_chsh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ _comp_cmd_chsh()
88
local cur prev words cword comp_args
99
_comp_initialize -- "$@" || return
1010

11-
local word chroot="" has_chroot=false
11+
local word chroot="" has_chroot=""
1212
for word in "${words[@]}"; do
13-
if "$has_chroot"; then
13+
if [[ $has_chroot ]]; then
1414
chroot=$word
1515
break
1616
fi
17-
[[ $word != -@(R|-root) ]] || has_chroot=true
17+
[[ $word != -@(R|-root) ]] || has_chroot="set"
1818
done
1919

2020
case $prev in

completions/_udevadm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ _comp_cmd_udevadm()
88
local cur prev words cword split comp_args
99
_comp_initialize -s -- "$@" || return
1010

11-
local i udevcmd has_udevcmd=false
11+
local i udevcmd has_udevcmd=""
1212
for ((i = 1; i < cword; i++)); do
1313
if [[ ${words[i]} != -* ]]; then
1414
udevcmd=${words[i]}
15-
has_udevcmd=true
15+
has_udevcmd="set"
1616
break
1717
fi
1818
done
@@ -54,7 +54,7 @@ _comp_cmd_udevadm()
5454

5555
$split && return
5656

57-
if ! "$has_udevcmd"; then
57+
if [[ ! $has_udevcmd ]]; then
5858
case $cur in
5959
-*)
6060
COMPREPLY=($(compgen -W '--help --version --debug' -- "$cur"))

completions/carton

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ _carton()
1818
local cur prev words cword split comp_args
1919
_comp_initialize -s -- "$@" || return
2020

21-
local i command="" has_command=false
21+
local i command="" has_command=""
2222
for ((i = 1; i < cword; i++)); do
2323
case ${words[i]} in
2424
-*) ;;
2525
*)
2626
command=${words[i]}
27-
has_command=true
27+
has_command="set"
2828
break
2929
;;
3030
esac
3131
done
3232

33-
if ! "$has_command"; then
33+
if [[ ! $has_command ]]; then
3434
_carton_commands "$1"
3535
return
3636
fi
@@ -40,7 +40,7 @@ _carton()
4040
return
4141
;;
4242
--help | -h)
43-
"$has_command" || _carton_commands "$1"
43+
[[ $has_command ]] || _carton_commands "$1"
4444
return
4545
;;
4646
--cpanfile)

completions/cvs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ _cvs()
5353
local cur prev words cword comp_args
5454
_comp_initialize -n : -- "$@" || return
5555

56-
local count mode="" i cvsroot="" has_cvsroot=false cvsroots pwd
56+
local count mode="" i cvsroot="" has_cvsroot="" cvsroots pwd
5757
local -a flags files entries changed newremoved
5858

5959
local noargopts='!(-*|*[d]*)'
@@ -74,7 +74,7 @@ _cvs()
7474
-${noargopts}d)
7575
mode=cvsroot
7676
cvsroot=${words[count + 1]}
77-
has_cvsroot=true
77+
has_cvsroot="set"
7878
;;
7979
add | ad | new)
8080
mode=add
@@ -232,7 +232,7 @@ _cvs()
232232
esac
233233

234234
if [[ $cur != -* ]]; then
235-
! "$has_cvsroot" && cvsroot=${CVSROOT-}
235+
[[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-}
236236
COMPREPLY=($(cvs -d "$cvsroot" co -c 2>/dev/null |
237237
awk '{print $1}'))
238238
((${#COMPREPLY[@]})) &&
@@ -317,7 +317,7 @@ _cvs()
317317
esac
318318

319319
if [[ $cur != -* ]]; then
320-
! "$has_cvsroot" && cvsroot=${CVSROOT-}
320+
[[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-}
321321
COMPREPLY=($(cvs -d "$cvsroot" co -c | awk '{print $1}'))
322322
((${#COMPREPLY[@]})) &&
323323
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}"' -- "$cur"))
@@ -339,7 +339,7 @@ _cvs()
339339

340340
if [[ $cur != -* ]]; then
341341
# starts with same algorithm as checkout
342-
! "$has_cvsroot" && cvsroot=${CVSROOT-}
342+
[[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-}
343343
local prefix=${cur%/*}
344344
if [[ -r ${cvsroot}/${prefix} ]]; then
345345
_cvs_modules

completions/dmypy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ _comp_cmd_dmypy()
1515
;;
1616
esac
1717

18-
local cmd has_cmd=false i
18+
local cmd has_cmd="" i
1919
for ((i = 1; i < cword; i++)); do
2020
if [[ ${words[i]} != -* && ${words[i - 1]} != --status-file ]]; then
2121
cmd=${words[i]}
22-
has_cmd=true
22+
has_cmd="set"
2323
break
2424
fi
2525
done
@@ -36,7 +36,7 @@ _comp_cmd_dmypy()
3636
return
3737
fi
3838

39-
if ! "$has_cmd"; then
39+
if [[ ! $has_cmd ]]; then
4040
local cmds=$("$1" --help 2>&1 |
4141
command sed -ne '/positional arguments/{p;n;p;q;}' |
4242
command sed -ne 's/{\(.*\)}/\1/p')

completions/getent

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _comp_cmd_getent()
66
_comp_initialize -s -- "$@" || return
77

88
local noargopts='!(-*|*[s]*)'
9-
local i db has_db=false
9+
local i db has_db=""
1010
for ((i = 1; i < cword; i++)); do
1111
# shellcheck disable=SC2254
1212
case ${words[i]} in
@@ -21,7 +21,7 @@ _comp_cmd_getent()
2121
*)
2222
# First non-option value is the db
2323
db=${words[i]}
24-
has_db=true
24+
has_db="set"
2525
break
2626
;;
2727
esac
@@ -69,7 +69,7 @@ _comp_cmd_getent()
6969
if [[ $cur == -* ]]; then
7070
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
7171
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
72-
elif ! "$has_db"; then
72+
elif [[ ! $has_db ]]; then
7373
COMPREPLY=($(compgen -W 'passwd group hosts services protocols
7474
networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc
7575
shadow gshadow' -- "$cur"))

completions/ip

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ _ip()
4343
;;
4444
esac
4545

46-
local subcword cmd="" has_cmd=false subcmd=""
46+
local subcword cmd="" has_cmd="" subcmd=""
4747
for ((subcword = 1; subcword < ${#words[@]} - 1; subcword++)); do
4848
[[ ${words[subcword]} == -b?(atch) ]] && return
49-
"$has_cmd" && subcmd=${words[subcword]} && break
49+
[[ $has_cmd ]] && subcmd=${words[subcword]} && break
5050
[[ ${words[subcword]} != -* &&
5151
${words[subcword - 1]} != -@(f?(amily)|rc?(vbuf)) ]] &&
52-
cmd=${words[subcword]} has_cmd=true
52+
cmd=${words[subcword]} has_cmd="set"
5353
done
5454

55-
if ! "$has_cmd"; then
55+
if [[ ! $has_cmd ]]; then
5656
case $cur in
5757
-*)
5858
local force=""

completions/ipmitool

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ _ipmitool()
6767
local cmds=(raw i2c spd lan chassis power event mc sdr sensor fru gendev
6868
sel pef sol tsol isol user channel session sunoem kontronoem picmg fwum
6969
firewall shell exec set hpm ekanalyzer)
70-
local i c cmd="" has_cmd=false subcmd
70+
local i c cmd="" has_cmd="" subcmd
7171
for ((i = 1; i < ${#words[@]} - 1; i++)); do
72-
"$has_cmd" && subcmd=${words[i]} && break
72+
[[ $has_cmd ]] && subcmd=${words[i]} && break
7373
for c in "${cmds[@]}"; do
74-
[[ ${words[i]} == "$c" ]] && cmd=$c has_cmd=true && break
74+
[[ ${words[i]} == "$c" ]] && cmd=$c has_cmd="set" && break
7575
done
7676
done
7777

78-
if ! "$has_cmd"; then
78+
if [[ ! $has_cmd ]]; then
7979
COMPREPLY=($(compgen -W '"${cmds[@]}"' -- "$cur"))
8080
return
8181
fi

0 commit comments

Comments
 (0)