Skip to content

Commit 78e4e4a

Browse files
akinomyogascop
andcommitted
fix: switch from if $var to if [[ $var ]] for custom IFS
Co-authored-by: Ville Skyttä <[email protected]>
1 parent 9b1cb54 commit 78e4e4a

File tree

12 files changed

+39
-38
lines changed

12 files changed

+39
-38
lines changed

.shellcheckrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ disable=SC1090 # not really fixable usually (ever?)
55
disable=SC2034 # for localizing variables set in called functions
66
disable=SC2128 # intentional style choice
77
disable=SC2206 # suggested alternatives fail in posix mode or use temp files
8+
disable=SC2209 # interferes with our `set` (literal) vs empty booleans
89
disable=SC2207 # suggested alternatives fail in posix mode or use temp files
910

1011
# These disables are to be investigated and decided

bash_completion

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,16 +859,16 @@ _variables()
859859
# -k: do not filter out already present tokens in value
860860
_comp_delimited()
861861
{
862-
local prefix="" delimiter=$1 deduplicate=true
862+
local prefix="" delimiter=$1 deduplicate=set
863863
shift
864864
if [[ $delimiter == -k ]]; then
865-
deduplicate=false
865+
deduplicate=""
866866
delimiter=$1
867867
shift
868868
fi
869869
[[ $cur == *$delimiter* ]] && prefix=${cur%"$delimiter"*}$delimiter
870870

871-
if $deduplicate; then
871+
if [[ $deduplicate ]]; then
872872
# We could construct a -X pattern to feed to compgen, but that'd
873873
# conflict with possibly already set -X in $@, as well as have
874874
# glob char escaping issues to deal with. Do removals by hand instead.

completions/export

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _comp_cmd_export()
55
local cur prev words cword comp_args
66
_comp_initialize -n := -- "$@" || return
77

8-
local i action=variable remove=false
8+
local i action=variable remove=""
99
for ((i = 1; i < cword; i++)); do
1010
case ${words[i]} in
1111
-p)
@@ -15,7 +15,7 @@ _comp_cmd_export()
1515
action=function
1616
;;&
1717
-*n*)
18-
remove=true
18+
remove=set
1919
;;
2020
-*)
2121
continue
@@ -52,7 +52,7 @@ _comp_cmd_export()
5252
return
5353
fi
5454
local suffix=""
55-
if ! $remove && [[ $action != function ]]; then
55+
if [[ ! $remove && $action != function ]]; then
5656
suffix="="
5757
compopt -o nospace
5858
fi

completions/find

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ _comp_cmd_find()
6464
;;
6565
esac
6666

67-
local i exprfound=false
67+
local i exprfound=""
6868
# set exprfound to true if there is already an expression present
6969
for i in "${words[@]}"; do
70-
[[ $i == [-\(\),\!]* ]] && exprfound=true && break
70+
[[ $i == [-\(\),\!]* ]] && exprfound=set && break
7171
done
7272

7373
# handle case where first parameter is not a dash option
74-
if ! $exprfound && [[ $cur != [-\(\),\!]* ]]; then
74+
if [[ ! $exprfound && $cur != [-\(\),\!]* ]]; then
7575
_filedir -d
7676
return
7777
fi

completions/fio

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ _comp_cmd_fio()
115115
# For example, for --kb_base=:
116116
# valid values: 1024 [...]
117117
# : 1000 [...]
118-
local line="" in_values=false
118+
local line="" in_values=""
119119
ret=()
120120
for line in "${cmdhelp[@]}"; do
121-
if $in_values; then
121+
if [[ $in_values ]]; then
122122
if [[ $line =~ ^[[:space:]]*:[[:space:]]*([^[:space:]]+) ]]; then
123123
ret+=("${BASH_REMATCH[1]}")
124124
else
125125
break
126126
fi
127127
elif [[ $line =~ ^[[:space:]]*valid\ values:[[:space:]]*([^[:space:]]+) ]]; then
128-
in_values=true
128+
in_values=set
129129
ret+=("${BASH_REMATCH[1]}")
130130
fi
131131
done

completions/jarsigner

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ _jarsigner()
3131
esac
3232

3333
# Check if a jar was already given.
34-
local i jar=false
34+
local i jar=""
3535
for ((i = 1; i < ${#words[@]} - 1; i++)); do
3636
if [[ ${words[i]} == *.@(jar|apk) &&
3737
${words[i - 1]} != -signedjar ]]; then
38-
jar=true
38+
jar=set
3939
break
4040
fi
4141
done
4242

43-
if ! $jar; then
43+
if [[ ! $jar ]]; then
4444
if [[ $cur == -* ]]; then
4545
# Documented as "should not be used": -internalsf, -sectionsonly
4646
COMPREPLY=($(compgen -W '-keystore -storepass -storetype

completions/lzip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _lzip()
55
local cur prev words cword split comp_args
66
_comp_initialize -s -- "$@" || return
77

8-
local decompress=false
8+
local decompress=""
99

1010
local noargopts='!(-*|*[bmsSBdno]*)'
1111
# shellcheck disable=SC2254
@@ -15,7 +15,7 @@ _lzip()
1515
return
1616
;;
1717
--decompress | -${noargopts}d)
18-
decompress=true
18+
decompress=set
1919
;;
2020
--threads | -${noargopts}n)
2121
COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur"))
@@ -35,7 +35,7 @@ _lzip()
3535
return
3636
fi
3737

38-
if $decompress; then
38+
if [[ $decompress ]]; then
3939
_filedir lz
4040
return
4141
fi

completions/pack200

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ _pack200()
4545
$split && return
4646

4747
# Check if a pack or a jar was already given.
48-
local i pack=false jar=false
48+
local i pack="" jar=""
4949
for ((i = 1; i < ${#words[@]} - 1; i++)); do
5050
case ${words[i]} in
51-
*.pack | *.pack.gz) pack=true ;;
52-
*.jar) jar=true ;;
51+
*.pack | *.pack.gz) pack=set ;;
52+
*.jar) jar=set ;;
5353
esac
5454
done
5555

56-
if ! $pack; then
56+
if [[ ! $pack ]]; then
5757
if [[ $cur == -* ]]; then
5858
COMPREPLY=($(compgen -W '--no-gzip --gzip --strip-debug
5959
--no-keep-file-order --segment-limit= --effort= --deflate-hint=
@@ -65,7 +65,7 @@ _pack200()
6565
else
6666
_filedir 'pack?(.gz)'
6767
fi
68-
elif ! $jar; then
68+
elif [[ ! $jar ]]; then
6969
_filedir jar
7070
fi
7171
} &&

completions/pytest

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ _pytest()
103103

104104
if [[ $cur == *.py::*:* ]]; then
105105
local file=${cur/.py:*/.py}
106-
local class=${cur#*.py::} in_class=false
106+
local class=${cur#*.py::} in_class=""
107107
local line
108108
class=${class%%:*}
109109
while IFS= read -r line; do
110110
if [[ $line =~ ^class[[:space:]]+${class}[[:space:]:\(] ]]; then
111-
in_class=true
111+
in_class=set
112112
elif [[ $line =~ ^class[[:space:]] ]]; then
113-
in_class=false
113+
in_class=""
114114
fi
115-
if $in_class && [[ $line =~ ^[[:space:]]+(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then
115+
if [[ $in_class && $line =~ ^[[:space:]]+(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then
116116
COMPREPLY+=(${BASH_REMATCH[2]})
117117
fi
118118
done 2>/dev/null <"$file"

completions/ssh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,16 @@ _comp_xfunc_ssh_scp_local_files()
480480
{
481481
local IFS=$'\n'
482482

483-
local dirsonly=false
483+
local dirsonly=""
484484
if [[ ${1-} == -d ]]; then
485-
dirsonly=true
485+
dirsonly=set
486486
shift
487487
fi
488488

489489
local files
490490
_comp_expand_glob files '"$cur"*'
491491
((${#files[@]})) || return 0
492-
if $dirsonly; then
492+
if [[ $dirsonly ]]; then
493493
COMPREPLY+=($(command ls -aF1dL "${files[@]}" 2>/dev/null |
494494
command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" -e '/[^\/]$/d' \
495495
-e "s/^/${1-}/"))

0 commit comments

Comments
 (0)