Skip to content

Commit 238fef0

Browse files
committed
refactor: switch from if "$var" to if [[ $var ]]
1 parent 6baed8a commit 238fef0

File tree

22 files changed

+114
-85
lines changed

22 files changed

+114
-85
lines changed

bash_completion

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,15 @@ _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)
348+
# shellcheck disable=SC2209
349+
_append=set
350+
;;
348351
l) IFS=$'\n' ;;
349352
F) IFS=$OPTARG ;;
350353
*)
@@ -367,7 +370,7 @@ _comp_split()
367370
set -o noglob
368371

369372
local _old_size _new_size
370-
if "$_append"; then
373+
if [[ $_append ]]; then
371374
eval "$1+=()" # in case $1 is unset
372375
eval "_old_size=\${#$1[@]}"
373376
eval "$1+=(\$2)"
@@ -409,13 +412,16 @@ _comp_split()
409412
# array instead.
410413
_comp_compgen()
411414
{
412-
local _append=false IFS=$' \t\n'
415+
local _append="" IFS=$' \t\n'
413416
local -a _split_options=(-l)
414417

415418
local OPTIND=1 OPTARG="" OPTERR=0 _opt
416419
while getopts ':alF:' _opt "$@"; do
417420
case $_opt in
418-
a) _append=true _split_options+=(-a) ;;
421+
a)
422+
# shellcheck disable=SC2209
423+
_append=set _split_options+=(-a)
424+
;;
419425
l) IFS=$'\n' ;;
420426
F) IFS=$OPTARG ;;
421427
*)
@@ -447,7 +453,7 @@ _comp_compgen()
447453
local _result
448454
_result=$(compgen "${@:2}") || {
449455
local _status=$?
450-
if "$_append"; then
456+
if [[ $_append ]]; then
451457
# make sure existence of variable
452458
eval -- "$1+=()"
453459
else

completions/_adb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@ _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+
# shellcheck disable=SC2209
33+
has_cmd=set
3334
break
3435
fi
3536
done
3637

37-
if ! "$has_cmd"; then
38+
if [[ ! $has_cmd ]]; then
3839
local tmp=()
3940
if [[ ! $cur || $cur == -* ]]; then
4041
tmp+=($(compgen -W '$(_parse_help "$1" help)' -- "$cur"))

completions/_chsh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ _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+
# shellcheck disable=SC2209
18+
[[ $word != -@(R|-root) ]] || has_chroot=set
1819
done
1920

2021
case $prev in

completions/_mount.linux

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@ _comp_cmd_mount()
88
local cur prev words cword comp_args
99
_comp_initialize -n =: -- "$@" || return
1010

11-
local split=false
11+
local split=""
1212
case "$prev" in
1313
-t | --types)
1414
# find /lib/modules/$(uname -r)/ -type f -path '*/fs/*.ko' -printf '%f\n' | cut -d. -f1
1515
# FIXME: no<fstype>
1616
if [[ $cur == ?*,* ]]; then
1717
prev="${cur%,*}"
1818
cur="${cur##*,}"
19-
split=true
19+
# shellcheck disable=SC2209
20+
split=set
2021
fi
2122
COMPREPLY=($(compgen -W 'auto adfs affs autofs btrfs cifs coda
2223
cramfs davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus
2324
hpfs iso9660 jffs2 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g
2425
proc qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs
2526
udf ufs umsdos usbfs vfat xfs' -- "$cur"))
2627
_fstypes
27-
$split && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
28+
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
2829
return
2930
;;
3031
--bind | -B | --rbind | -R)
@@ -74,7 +75,8 @@ _comp_cmd_mount()
7475
if [[ $cur == ?*,* ]]; then
7576
prev="${cur%,*}"
7677
cur="${cur##*,}"
77-
split=true
78+
# shellcheck disable=SC2209
79+
split=set
7880
fi
7981
# no completion if $cur is opt=smth
8082
[[ $cur == *=* ]] && return
@@ -206,7 +208,7 @@ _comp_cmd_mount()
206208
esac
207209
# COMP_WORDBREAKS is a real pain in the ass
208210
prev="${prev##*["$COMP_WORDBREAKS"]}"
209-
$split && COMPREPLY=(${COMPREPLY[@]/#/"$prev,"})
211+
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/"$prev,"})
210212
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
211213
return
212214
;;

completions/_slackpkg

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ _comp_cmd_slackpkg()
99
local cur prev words cword comp_args
1010
_comp_initialize -n = -- "$@" || return
1111

12-
local split=false
12+
local split=""
1313
if [[ $cur == -?*=* ]]; then
1414
prev="${cur%%?(\\)=*}"
1515
cur="${cur#*=}"
16-
split=true
16+
# shellcheck disable=SC2209
17+
split=set
1718
fi
1819

1920
case "$prev" in
@@ -33,7 +34,7 @@ _comp_cmd_slackpkg()
3334
;;
3435
esac
3536

36-
$split && return
37+
[[ $split ]] && return
3738

3839
if [[ $cur == -* ]]; then
3940
compopt -o nospace

completions/_udevadm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ _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+
# shellcheck disable=SC2209
16+
has_udevcmd=set
1617
break
1718
fi
1819
done
@@ -54,7 +55,7 @@ _comp_cmd_udevadm()
5455

5556
$split && return
5657

57-
if ! "$has_udevcmd"; then
58+
if [[ ! $has_udevcmd ]]; then
5859
case $cur in
5960
-*)
6061
COMPREPLY=($(compgen -W '--help --version --debug' -- "$cur"))

completions/_umount.linux

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,20 @@ _comp_cmd_umount()
101101
case "$prev" in
102102
-t)
103103
# FIXME: no<fstype>
104-
local split=false
104+
local split=""
105105
if [[ $cur == ?*,* ]]; then
106106
prev="${cur%,*}"
107107
cur="${cur##*,}"
108-
split=true
108+
# shellcheck disable=SC2209
109+
split=set
109110
fi
110111
COMPREPLY=($(compgen -W 'adfs affs autofs btrfs cifs coda
111112
cramfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs
112113
iso9660 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc qnx4
113114
ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs
114115
umsdos usbfs vfat xfs' -- "$cur"))
115116
_fstypes
116-
$split && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
117+
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
117118
return
118119
;;
119120
-O)

completions/carton

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ _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+
# shellcheck disable=SC2209
28+
has_command=set
2829
break
2930
;;
3031
esac
3132
done
3233

33-
if ! "$has_command"; then
34+
if [[ ! $has_command ]]; then
3435
_carton_commands "$1"
3536
return
3637
fi
@@ -40,7 +41,7 @@ _carton()
4041
return
4142
;;
4243
--help | -h)
43-
"$has_command" || _carton_commands "$1"
44+
[[ $has_command ]] || _carton_commands "$1"
4445
return
4546
;;
4647
--cpanfile)

completions/cvs

Lines changed: 6 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,8 @@ _cvs()
7474
-${noargopts}d)
7575
mode=cvsroot
7676
cvsroot=${words[count + 1]}
77-
has_cvsroot=true
77+
# shellcheck disable=SC2209
78+
has_cvsroot=set
7879
;;
7980
add | ad | new)
8081
mode=add
@@ -232,7 +233,7 @@ _cvs()
232233
esac
233234

234235
if [[ $cur != -* ]]; then
235-
! "$has_cvsroot" && cvsroot=${CVSROOT-}
236+
[[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-}
236237
COMPREPLY=($(cvs -d "$cvsroot" co -c 2>/dev/null |
237238
awk '{print $1}'))
238239
((${#COMPREPLY[@]})) &&
@@ -317,7 +318,7 @@ _cvs()
317318
esac
318319

319320
if [[ $cur != -* ]]; then
320-
! "$has_cvsroot" && cvsroot=${CVSROOT-}
321+
[[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-}
321322
COMPREPLY=($(cvs -d "$cvsroot" co -c | awk '{print $1}'))
322323
((${#COMPREPLY[@]})) &&
323324
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}"' -- "$cur"))
@@ -339,7 +340,7 @@ _cvs()
339340

340341
if [[ $cur != -* ]]; then
341342
# starts with same algorithm as checkout
342-
! "$has_cvsroot" && cvsroot=${CVSROOT-}
343+
[[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-}
343344
local prefix=${cur%/*}
344345
if [[ -r ${cvsroot}/${prefix} ]]; then
345346
_cvs_modules

completions/dmypy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ _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+
# shellcheck disable=SC2209
23+
has_cmd=set
2324
break
2425
fi
2526
done
@@ -36,7 +37,7 @@ _comp_cmd_dmypy()
3637
return
3738
fi
3839

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

0 commit comments

Comments
 (0)