Skip to content

Commit 36a109e

Browse files
akinomyogascop
authored andcommitted
refactor: switch from if "$var" to if [[ $var ]]
1 parent 9899889 commit 36a109e

File tree

22 files changed

+85
-85
lines changed

22 files changed

+85
-85
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/_mount.linux

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ _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+
split=set
2020
fi
2121
COMPREPLY=($(compgen -W 'auto adfs affs autofs btrfs cifs coda
2222
cramfs davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus
2323
hpfs iso9660 jffs2 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g
2424
proc qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs
2525
udf ufs umsdos usbfs vfat xfs' -- "$cur"))
2626
_fstypes
27-
$split && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
27+
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
2828
return
2929
;;
3030
--bind | -B | --rbind | -R)
@@ -74,7 +74,7 @@ _comp_cmd_mount()
7474
if [[ $cur == ?*,* ]]; then
7575
prev="${cur%,*}"
7676
cur="${cur##*,}"
77-
split=true
77+
split=set
7878
fi
7979
# no completion if $cur is opt=smth
8080
[[ $cur == *=* ]] && return
@@ -206,7 +206,7 @@ _comp_cmd_mount()
206206
esac
207207
# COMP_WORDBREAKS is a real pain in the ass
208208
prev="${prev##*["$COMP_WORDBREAKS"]}"
209-
$split && COMPREPLY=(${COMPREPLY[@]/#/"$prev,"})
209+
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/"$prev,"})
210210
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
211211
return
212212
;;

completions/_slackpkg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ _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+
split=set
1717
fi
1818

1919
case "$prev" in
@@ -33,7 +33,7 @@ _comp_cmd_slackpkg()
3333
;;
3434
esac
3535

36-
$split && return
36+
[[ $split ]] && return
3737

3838
if [[ $cur == -* ]]; then
3939
compopt -o nospace

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/_umount.linux

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,19 @@ _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+
split=set
109109
fi
110110
COMPREPLY=($(compgen -W 'adfs affs autofs btrfs cifs coda
111111
cramfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs
112112
iso9660 jfs minix msdos ncpfs nfs nfs4 ntfs ntfs-3g proc qnx4
113113
ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs
114114
umsdos usbfs vfat xfs' -- "$cur"))
115115
_fstypes
116-
$split && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
116+
[[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,})
117117
return
118118
;;
119119
-O)

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')

0 commit comments

Comments
 (0)