diff --git a/.shellcheckrc b/.shellcheckrc index 58675d59d2b..3a3d9395d30 100644 --- a/.shellcheckrc +++ b/.shellcheckrc @@ -5,6 +5,7 @@ disable=SC1090 # not really fixable usually (ever?) disable=SC2034 # for localizing variables set in called functions disable=SC2128 # intentional style choice disable=SC2206 # suggested alternatives fail in posix mode or use temp files +disable=SC2209 # interferes with our `set` (literal) vs empty booleans disable=SC2207 # suggested alternatives fail in posix mode or use temp files # These disables are to be investigated and decided diff --git a/bash_completion b/bash_completion index 1bfab05d8d5..6e297dc756f 100644 --- a/bash_completion +++ b/bash_completion @@ -339,12 +339,12 @@ _comp_expand_glob() # generated. _comp_split() { - local _append=false IFS=$' \t\n' + local _append="" IFS=$' \t\n' local OPTIND=1 OPTARG="" OPTERR=0 _opt while getopts ':alF:' _opt "$@"; do case $_opt in - a) _append=true ;; + a) _append=set ;; l) IFS=$'\n' ;; F) IFS=$OPTARG ;; *) @@ -367,7 +367,7 @@ _comp_split() set -o noglob local _old_size _new_size - if "$_append"; then + if [[ $_append ]]; then eval "$1+=()" # in case $1 is unset eval "_old_size=\${#$1[@]}" eval "$1+=(\$2)" @@ -409,13 +409,13 @@ _comp_split() # array instead. _comp_compgen() { - local _append=false IFS=$' \t\n' + local _append="" IFS=$' \t\n' local -a _split_options=(-l) local OPTIND=1 OPTARG="" OPTERR=0 _opt while getopts ':alF:' _opt "$@"; do case $_opt in - a) _append=true _split_options+=(-a) ;; + a) _append=set _split_options+=(-a) ;; l) IFS=$'\n' ;; F) IFS=$OPTARG ;; *) @@ -447,7 +447,7 @@ _comp_compgen() local _result _result=$(compgen "${@:2}") || { local _status=$? - if "$_append"; then + if [[ $_append ]]; then # make sure existence of variable eval -- "$1+=()" else @@ -859,16 +859,16 @@ _variables() # -k: do not filter out already present tokens in value _comp_delimited() { - local prefix="" delimiter=$1 deduplicate=true + local prefix="" delimiter=$1 deduplicate=set shift if [[ $delimiter == -k ]]; then - deduplicate=false + deduplicate="" delimiter=$1 shift fi [[ $cur == *$delimiter* ]] && prefix=${cur%"$delimiter"*}$delimiter - if $deduplicate; then + if [[ $deduplicate ]]; then # We could construct a -X pattern to feed to compgen, but that'd # conflict with possibly already set -X in $@, as well as have # glob char escaping issues to deal with. Do removals by hand instead. @@ -1959,7 +1959,7 @@ _known_hosts_real() local OPTIND=1 while getopts "ac46F:p:" flag "$@"; do case $flag in - a) aliases='yes' ;; + a) aliases=set ;; c) suffix=':' ;; F) if [[ ! $OPTARG ]]; then @@ -1969,8 +1969,8 @@ _known_hosts_real() configfile=$OPTARG ;; p) prefix=$OPTARG ;; - 4) ipv4=1 ;; - 6) ipv6=1 ;; + 4) ipv4=set ;; + 6) ipv6=set ;; *) echo "bash_completion: $FUNCNAME: usage error" >&2 return 1 diff --git a/completions/_adb b/completions/_adb index ed11dad0697..d1e3a8af5c6 100644 --- a/completions/_adb +++ b/completions/_adb @@ -25,16 +25,16 @@ _comp_cmd_adb() ;; esac - local cmd has_cmd=false i + local cmd has_cmd="" i for ((i = 1; i < cword; i++)); do if [[ ${words[i]} != -* && ${words[i - 1]} != -[sp] ]]; then cmd="${words[i]}" - has_cmd=true + has_cmd=set break fi done - if ! "$has_cmd"; then + if [[ ! $has_cmd ]]; then local tmp=() if [[ ! $cur || $cur == -* ]]; then tmp+=($(compgen -W '$(_parse_help "$1" help)' -- "$cur")) diff --git a/completions/_chsh b/completions/_chsh index b6569ce7af6..651a5a660b1 100644 --- a/completions/_chsh +++ b/completions/_chsh @@ -8,13 +8,13 @@ _comp_cmd_chsh() local cur prev words cword comp_args _comp_initialize -- "$@" || return - local word chroot="" has_chroot=false + local word chroot="" has_chroot="" for word in "${words[@]}"; do - if "$has_chroot"; then + if [[ $has_chroot ]]; then chroot=$word break fi - [[ $word != -@(R|-root) ]] || has_chroot=true + [[ $word != -@(R|-root) ]] || has_chroot=set done case $prev in diff --git a/completions/_mount.linux b/completions/_mount.linux index 91a543120fa..ac41ae68f1d 100644 --- a/completions/_mount.linux +++ b/completions/_mount.linux @@ -8,7 +8,7 @@ _comp_cmd_mount() local cur prev words cword comp_args _comp_initialize -n =: -- "$@" || return - local split=false + local split="" case "$prev" in -t | --types) # find /lib/modules/$(uname -r)/ -type f -path '*/fs/*.ko' -printf '%f\n' | cut -d. -f1 @@ -16,7 +16,7 @@ _comp_cmd_mount() if [[ $cur == ?*,* ]]; then prev="${cur%,*}" cur="${cur##*,}" - split=true + split=set fi COMPREPLY=($(compgen -W 'auto adfs affs autofs btrfs cifs coda cramfs davfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus @@ -24,7 +24,7 @@ _comp_cmd_mount() proc qnx4 ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs umsdos usbfs vfat xfs' -- "$cur")) _fstypes - $split && COMPREPLY=(${COMPREPLY[@]/#/$prev,}) + [[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,}) return ;; --bind | -B | --rbind | -R) @@ -74,7 +74,7 @@ _comp_cmd_mount() if [[ $cur == ?*,* ]]; then prev="${cur%,*}" cur="${cur##*,}" - split=true + split=set fi # no completion if $cur is opt=smth [[ $cur == *=* ]] && return @@ -206,7 +206,7 @@ _comp_cmd_mount() esac # COMP_WORDBREAKS is a real pain in the ass prev="${prev##*["$COMP_WORDBREAKS"]}" - $split && COMPREPLY=(${COMPREPLY[@]/#/"$prev,"}) + [[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/"$prev,"}) [[ ${COMPREPLY-} == *= ]] && compopt -o nospace return ;; diff --git a/completions/_slackpkg b/completions/_slackpkg index 153d4a10fbc..7e234d4e6ba 100644 --- a/completions/_slackpkg +++ b/completions/_slackpkg @@ -9,11 +9,11 @@ _comp_cmd_slackpkg() local cur prev words cword comp_args _comp_initialize -n = -- "$@" || return - local split=false + local split="" if [[ $cur == -?*=* ]]; then prev="${cur%%?(\\)=*}" cur="${cur#*=}" - split=true + split=set fi case "$prev" in @@ -33,7 +33,7 @@ _comp_cmd_slackpkg() ;; esac - $split && return + [[ $split ]] && return if [[ $cur == -* ]]; then compopt -o nospace diff --git a/completions/_udevadm b/completions/_udevadm index 5332989632f..2735627a6b0 100644 --- a/completions/_udevadm +++ b/completions/_udevadm @@ -8,11 +8,11 @@ _comp_cmd_udevadm() local cur prev words cword split comp_args _comp_initialize -s -- "$@" || return - local i udevcmd has_udevcmd=false + local i udevcmd has_udevcmd="" for ((i = 1; i < cword; i++)); do if [[ ${words[i]} != -* ]]; then udevcmd=${words[i]} - has_udevcmd=true + has_udevcmd=set break fi done @@ -54,7 +54,7 @@ _comp_cmd_udevadm() $split && return - if ! "$has_udevcmd"; then + if [[ ! $has_udevcmd ]]; then case $cur in -*) COMPREPLY=($(compgen -W '--help --version --debug' -- "$cur")) diff --git a/completions/_umount.linux b/completions/_umount.linux index 609de7d4bc3..321df9504c3 100644 --- a/completions/_umount.linux +++ b/completions/_umount.linux @@ -101,11 +101,11 @@ _comp_cmd_umount() case "$prev" in -t) # FIXME: no - local split=false + local split="" if [[ $cur == ?*,* ]]; then prev="${cur%,*}" cur="${cur##*,}" - split=true + split=set fi COMPREPLY=($(compgen -W 'adfs affs autofs btrfs cifs coda cramfs debugfs devpts efs ext2 ext3 ext4 fuse hfs hfsplus hpfs @@ -113,7 +113,7 @@ _comp_cmd_umount() ramfs reiserfs romfs squashfs smbfs sysv tmpfs ubifs udf ufs umsdos usbfs vfat xfs' -- "$cur")) _fstypes - $split && COMPREPLY=(${COMPREPLY[@]/#/$prev,}) + [[ $split ]] && COMPREPLY=(${COMPREPLY[@]/#/$prev,}) return ;; -O) diff --git a/completions/carton b/completions/carton index 5953bc9309c..f79ed2b7a88 100644 --- a/completions/carton +++ b/completions/carton @@ -18,19 +18,19 @@ _carton() local cur prev words cword split comp_args _comp_initialize -s -- "$@" || return - local i command="" has_command=false + local i command="" has_command="" for ((i = 1; i < cword; i++)); do case ${words[i]} in -*) ;; *) command=${words[i]} - has_command=true + has_command=set break ;; esac done - if ! "$has_command"; then + if [[ ! $has_command ]]; then _carton_commands "$1" return fi @@ -40,7 +40,7 @@ _carton() return ;; --help | -h) - "$has_command" || _carton_commands "$1" + [[ $has_command ]] || _carton_commands "$1" return ;; --cpanfile) diff --git a/completions/cvs b/completions/cvs index b8f19bb6043..66ff9b6fe41 100644 --- a/completions/cvs +++ b/completions/cvs @@ -53,7 +53,7 @@ _cvs() local cur prev words cword comp_args _comp_initialize -n : -- "$@" || return - local count mode="" i cvsroot="" has_cvsroot=false cvsroots pwd + local count mode="" i cvsroot="" has_cvsroot="" cvsroots pwd local -a flags files entries changed newremoved local noargopts='!(-*|*[d]*)' @@ -74,7 +74,7 @@ _cvs() -${noargopts}d) mode=cvsroot cvsroot=${words[count + 1]} - has_cvsroot=true + has_cvsroot=set ;; add | ad | new) mode=add @@ -232,7 +232,7 @@ _cvs() esac if [[ $cur != -* ]]; then - ! "$has_cvsroot" && cvsroot=${CVSROOT-} + [[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-} COMPREPLY=($(cvs -d "$cvsroot" co -c 2>/dev/null | awk '{print $1}')) ((${#COMPREPLY[@]})) && @@ -317,7 +317,7 @@ _cvs() esac if [[ $cur != -* ]]; then - ! "$has_cvsroot" && cvsroot=${CVSROOT-} + [[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-} COMPREPLY=($(cvs -d "$cvsroot" co -c | awk '{print $1}')) ((${#COMPREPLY[@]})) && COMPREPLY=($(compgen -W '"${COMPREPLY[@]}"' -- "$cur")) @@ -339,7 +339,7 @@ _cvs() if [[ $cur != -* ]]; then # starts with same algorithm as checkout - ! "$has_cvsroot" && cvsroot=${CVSROOT-} + [[ ! $has_cvsroot ]] && cvsroot=${CVSROOT-} local prefix=${cur%/*} if [[ -r ${cvsroot}/${prefix} ]]; then _cvs_modules diff --git a/completions/dmypy b/completions/dmypy index cd6a62adf41..af9288b2f30 100644 --- a/completions/dmypy +++ b/completions/dmypy @@ -15,11 +15,11 @@ _comp_cmd_dmypy() ;; esac - local cmd has_cmd=false i + local cmd has_cmd="" i for ((i = 1; i < cword; i++)); do if [[ ${words[i]} != -* && ${words[i - 1]} != --status-file ]]; then cmd=${words[i]} - has_cmd=true + has_cmd=set break fi done @@ -36,7 +36,7 @@ _comp_cmd_dmypy() return fi - if ! "$has_cmd"; then + if [[ ! $has_cmd ]]; then local cmds=$("$1" --help 2>&1 | command sed -ne '/positional arguments/{p;n;p;q;}' | command sed -ne 's/{\(.*\)}/\1/p') diff --git a/completions/export b/completions/export index 28ad8b84a5c..bc9907a707d 100644 --- a/completions/export +++ b/completions/export @@ -5,7 +5,7 @@ _comp_cmd_export() local cur prev words cword comp_args _comp_initialize -n := -- "$@" || return - local i action=variable remove=false + local i action=variable remove="" for ((i = 1; i < cword; i++)); do case ${words[i]} in -p) @@ -15,7 +15,7 @@ _comp_cmd_export() action=function ;;& -*n*) - remove=true + remove=set ;; -*) continue @@ -52,7 +52,7 @@ _comp_cmd_export() return fi local suffix="" - if ! $remove && [[ $action != function ]]; then + if [[ ! $remove && $action != function ]]; then suffix="=" compopt -o nospace fi diff --git a/completions/find b/completions/find index 646eefb1d5b..f229b04e0e8 100644 --- a/completions/find +++ b/completions/find @@ -64,14 +64,14 @@ _comp_cmd_find() ;; esac - local i exprfound=false + local i exprfound="" # set exprfound to true if there is already an expression present for i in "${words[@]}"; do - [[ $i == [-\(\),\!]* ]] && exprfound=true && break + [[ $i == [-\(\),\!]* ]] && exprfound=set && break done # handle case where first parameter is not a dash option - if ! $exprfound && [[ $cur != [-\(\),\!]* ]]; then + if [[ ! $exprfound && $cur != [-\(\),\!]* ]]; then _filedir -d return fi diff --git a/completions/fio b/completions/fio index b2a56d79814..14a0d71e4ba 100644 --- a/completions/fio +++ b/completions/fio @@ -115,17 +115,17 @@ _comp_cmd_fio() # For example, for --kb_base=: # valid values: 1024 [...] # : 1000 [...] - local line="" in_values=false + local line="" in_values="" ret=() for line in "${cmdhelp[@]}"; do - if $in_values; then + if [[ $in_values ]]; then if [[ $line =~ ^[[:space:]]*:[[:space:]]*([^[:space:]]+) ]]; then ret+=("${BASH_REMATCH[1]}") else break fi elif [[ $line =~ ^[[:space:]]*valid\ values:[[:space:]]*([^[:space:]]+) ]]; then - in_values=true + in_values=set ret+=("${BASH_REMATCH[1]}") fi done diff --git a/completions/getent b/completions/getent index 102398b1444..7749b0da966 100644 --- a/completions/getent +++ b/completions/getent @@ -6,7 +6,7 @@ _comp_cmd_getent() _comp_initialize -s -- "$@" || return local noargopts='!(-*|*[s]*)' - local i db has_db=false + local i db has_db="" for ((i = 1; i < cword; i++)); do # shellcheck disable=SC2254 case ${words[i]} in @@ -21,7 +21,7 @@ _comp_cmd_getent() *) # First non-option value is the db db=${words[i]} - has_db=true + has_db=set break ;; esac @@ -69,7 +69,7 @@ _comp_cmd_getent() if [[ $cur == -* ]]; then COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) [[ ${COMPREPLY-} == *= ]] && compopt -o nospace - elif ! "$has_db"; then + elif [[ ! $has_db ]]; then COMPREPLY=($(compgen -W 'passwd group hosts services protocols networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc shadow gshadow' -- "$cur")) diff --git a/completions/ip b/completions/ip index 4d0379f62f8..96ef3899131 100644 --- a/completions/ip +++ b/completions/ip @@ -43,16 +43,16 @@ _ip() ;; esac - local subcword cmd="" has_cmd=false subcmd="" + local subcword cmd="" has_cmd="" subcmd="" for ((subcword = 1; subcword < ${#words[@]} - 1; subcword++)); do [[ ${words[subcword]} == -b?(atch) ]] && return - "$has_cmd" && subcmd=${words[subcword]} && break + [[ $has_cmd ]] && subcmd=${words[subcword]} && break [[ ${words[subcword]} != -* && ${words[subcword - 1]} != -@(f?(amily)|rc?(vbuf)) ]] && - cmd=${words[subcword]} has_cmd=true + cmd=${words[subcword]} has_cmd=set done - if ! "$has_cmd"; then + if [[ ! $has_cmd ]]; then case $cur in -*) local force="" diff --git a/completions/ipmitool b/completions/ipmitool index 4f8c4c66728..b0962f2d211 100644 --- a/completions/ipmitool +++ b/completions/ipmitool @@ -67,15 +67,15 @@ _ipmitool() local cmds=(raw i2c spd lan chassis power event mc sdr sensor fru gendev sel pef sol tsol isol user channel session sunoem kontronoem picmg fwum firewall shell exec set hpm ekanalyzer) - local i c cmd="" has_cmd=false subcmd + local i c cmd="" has_cmd="" subcmd for ((i = 1; i < ${#words[@]} - 1; i++)); do - "$has_cmd" && subcmd=${words[i]} && break + [[ $has_cmd ]] && subcmd=${words[i]} && break for c in "${cmds[@]}"; do - [[ ${words[i]} == "$c" ]] && cmd=$c has_cmd=true && break + [[ ${words[i]} == "$c" ]] && cmd=$c has_cmd=set && break done done - if ! "$has_cmd"; then + if [[ ! $has_cmd ]]; then COMPREPLY=($(compgen -W '"${cmds[@]}"' -- "$cur")) return fi diff --git a/completions/jarsigner b/completions/jarsigner index bef320703fe..2c06920dd5c 100644 --- a/completions/jarsigner +++ b/completions/jarsigner @@ -31,16 +31,16 @@ _jarsigner() esac # Check if a jar was already given. - local i jar=false + local i jar="" for ((i = 1; i < ${#words[@]} - 1; i++)); do if [[ ${words[i]} == *.@(jar|apk) && ${words[i - 1]} != -signedjar ]]; then - jar=true + jar=set break fi done - if ! $jar; then + if [[ ! $jar ]]; then if [[ $cur == -* ]]; then # Documented as "should not be used": -internalsf, -sectionsonly COMPREPLY=($(compgen -W '-keystore -storepass -storetype diff --git a/completions/koji b/completions/koji index db8d1d7d12c..7033b819b98 100644 --- a/completions/koji +++ b/completions/koji @@ -37,11 +37,11 @@ _koji() local cur prev words cword split comp_args _comp_initialize -s -- "$@" || return - local commandix command="" has_command=false + local commandix command="" has_command="" for ((commandix = 1; commandix < cword; commandix++)); do if [[ ${words[commandix]} != -* ]]; then command=${words[commandix]} - has_command=true + has_command=set break fi done @@ -108,7 +108,7 @@ _koji() $split && return - if "$has_command"; then + if [[ $has_command ]]; then if [[ $cur == -* ]]; then COMPREPLY=($(compgen -W \ '$(_parse_help "$1" "$command --help")' -- "$cur")) @@ -238,7 +238,7 @@ _koji() if [[ $cur == -* ]]; then COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) [[ ${COMPREPLY-} == *= ]] && compopt -o nospace - elif ! "$has_command"; then + elif [[ ! $has_command ]]; then COMPREPLY=($(compgen -W '$("$1" --help-commands 2>/dev/null | \ awk "/^( +|\t)/ { print \$1 }")' -- "$cur")) fi diff --git a/completions/lzip b/completions/lzip index 3f33ae2fe63..09b62705762 100644 --- a/completions/lzip +++ b/completions/lzip @@ -5,7 +5,7 @@ _lzip() local cur prev words cword split comp_args _comp_initialize -s -- "$@" || return - local decompress=false + local decompress="" local noargopts='!(-*|*[bmsSBdno]*)' # shellcheck disable=SC2254 @@ -15,7 +15,7 @@ _lzip() return ;; --decompress | -${noargopts}d) - decompress=true + decompress=set ;; --threads | -${noargopts}n) COMPREPLY=($(compgen -W "{1..$(_ncpus)}" -- "$cur")) @@ -35,7 +35,7 @@ _lzip() return fi - if $decompress; then + if [[ $decompress ]]; then _filedir lz return fi diff --git a/completions/make b/completions/make index a54e04685ad..aa87eeb0fdc 100644 --- a/completions/make +++ b/completions/make @@ -111,7 +111,7 @@ _comp_make__truncate_non_unique_paths() for target in "${COMPREPLY[@]}"; do local path=${target%/} while [[ ! ${paths[$path]+set} ]] && - paths[$path]=1 && + paths[$path]=set && [[ $path == "$prefix"*/* ]]; do path=${path%/*} nchild[$path]=$((${nchild[$path]-0} + 1)) diff --git a/completions/mcrypt b/completions/mcrypt index 75a3e0c54b8..de990d4afe4 100644 --- a/completions/mcrypt +++ b/completions/mcrypt @@ -49,15 +49,15 @@ _mcrypt() elif [[ ${words[0]} == mdecrypt ]]; then _filedir nc else - local i decrypt=0 + local i decrypt="" for ((i = 1; i < ${#words[@]} - 1; i++)); do if [[ ${words[i]} == -@(d|-decrypt) ]]; then _filedir nc - decrypt=1 + decrypt=set break fi done - if ((decrypt == 0)); then + if [[ ! $decrypt ]]; then _filedir fi fi diff --git a/completions/mr b/completions/mr index 1f6fb09cb23..18a92d3d584 100644 --- a/completions/mr +++ b/completions/mr @@ -21,17 +21,17 @@ _mr() # Determine if user has entered an `mr` command. Used to block top-level # (option and command) completions. - local cmd has_cmd=false i + local cmd has_cmd="" i for ((i = 1; i < ${#words[@]} - 1; i++)); do if [[ $commands == *"${words[i]}"* ]]; then cmd="${words[i]}" - has_cmd=true + has_cmd=set break fi done # Complete options for specific commands. - if "$has_cmd"; then + if [[ $has_cmd ]]; then case $cmd in bootstrap) _filedir diff --git a/completions/mutt b/completions/mutt index 70ac3983d94..cb7a7807592 100644 --- a/completions/mutt +++ b/completions/mutt @@ -64,8 +64,8 @@ _comp_cmd_mutt__get_conffiles() # @var[ref] visited Dictionary of config files already visited _comp_cmd_mutt__get_conffiles__visit() { - [[ -f $1 && ${visited[$1]-} != yes ]] || return 0 - visited[$1]=yes + [[ -f $1 && ${visited[$1]-} != set ]] || return 0 + visited[$1]=set conffiles+=("$1") local -a newconffiles=($(command sed -n 's|^source[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*$|\1|p' "$1")) diff --git a/completions/pack200 b/completions/pack200 index 18481596b99..66dc9d4e977 100644 --- a/completions/pack200 +++ b/completions/pack200 @@ -45,15 +45,15 @@ _pack200() $split && return # Check if a pack or a jar was already given. - local i pack=false jar=false + local i pack="" jar="" for ((i = 1; i < ${#words[@]} - 1; i++)); do case ${words[i]} in - *.pack | *.pack.gz) pack=true ;; - *.jar) jar=true ;; + *.pack | *.pack.gz) pack=set ;; + *.jar) jar=set ;; esac done - if ! $pack; then + if [[ ! $pack ]]; then if [[ $cur == -* ]]; then COMPREPLY=($(compgen -W '--no-gzip --gzip --strip-debug --no-keep-file-order --segment-limit= --effort= --deflate-hint= @@ -65,7 +65,7 @@ _pack200() else _filedir 'pack?(.gz)' fi - elif ! $jar; then + elif [[ ! $jar ]]; then _filedir jar fi } && diff --git a/completions/postcat b/completions/postcat index 5d75dc31383..8d5e112e11f 100644 --- a/completions/postcat +++ b/completions/postcat @@ -17,11 +17,11 @@ _postcat() return fi - local idx qfile=0 + local idx qfile="" for idx in "${words[@]}"; do - [[ $idx == -q ]] && qfile=1 && break + [[ $idx == -q ]] && qfile=set && break done - if ((qfile == 1)); then + if [[ $qfile ]]; then local len=${#cur} pval for pval in $(mailq 2>/dev/null | command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do diff --git a/completions/pytest b/completions/pytest index 02c121a48ed..3a1ecb87b3d 100644 --- a/completions/pytest +++ b/completions/pytest @@ -103,16 +103,16 @@ _pytest() if [[ $cur == *.py::*:* ]]; then local file=${cur/.py:*/.py} - local class=${cur#*.py::} in_class=false + local class=${cur#*.py::} in_class="" local line class=${class%%:*} while IFS= read -r line; do if [[ $line =~ ^class[[:space:]]+${class}[[:space:]:\(] ]]; then - in_class=true + in_class=set elif [[ $line =~ ^class[[:space:]] ]]; then - in_class=false + in_class="" fi - if $in_class && [[ $line =~ ^[[:space:]]+(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then + if [[ $in_class && $line =~ ^[[:space:]]+(async[[:space:]]+)?def[[:space:]]+(test_[A-Za-z0-9_]+) ]]; then COMPREPLY+=(${BASH_REMATCH[2]}) fi done 2>/dev/null <"$file" diff --git a/completions/route b/completions/route index 6a938bb877d..44ae4f334a8 100644 --- a/completions/route +++ b/completions/route @@ -16,11 +16,11 @@ _route() local opt found i for opt in add del -host -net netmask metric mss window irtt reject mod \ dyn reinstate dev default gw; do - found=false + found="" for ((i = 1; i < ${#words[@]} - 1; i++)); do - [[ ${words[i]} == "$opt" ]] && found=true && break + [[ ${words[i]} == "$opt" ]] && found=set && break done - $found || COMPREPLY+=("$opt") + [[ $found ]] || COMPREPLY+=("$opt") done ((${#COMPREPLY[@]})) && diff --git a/completions/secret-tool b/completions/secret-tool index 4617c336d4a..1be538cc339 100644 --- a/completions/secret-tool +++ b/completions/secret-tool @@ -8,14 +8,14 @@ _secret_tool() $split && return local -i i - local mode="" has_mode=false word + local mode="" has_mode="" word for i in ${!words[*]}; do if [[ $i -gt 0 && ${words[i]} != -* ]]; then - ((i != cword)) && mode=${words[i]} has_mode=true + ((i != cword)) && mode=${words[i]} has_mode=set break fi done - if ! "$has_mode"; then + if [[ ! $has_mode ]]; then local -a modes modes=($("$1" nonexistent-mode 2>&1 | while read -r first second third rest; do diff --git a/completions/ssh b/completions/ssh index 4c34a02d615..77f417b79eb 100644 --- a/completions/ssh +++ b/completions/ssh @@ -480,16 +480,16 @@ _comp_xfunc_ssh_scp_local_files() { local IFS=$'\n' - local dirsonly=false + local dirsonly="" if [[ ${1-} == -d ]]; then - dirsonly=true + dirsonly=set shift fi local files _comp_expand_glob files '"$cur"*' ((${#files[@]})) || return 0 - if $dirsonly; then + if [[ $dirsonly ]]; then COMPREPLY+=($(command ls -aF1dL "${files[@]}" 2>/dev/null | command sed -e "s/$_comp_cmd_scp__path_esc/\\\\&/g" -e '/[^\/]$/d' \ -e "s/^/${1-}/")) diff --git a/completions/strace b/completions/strace index 349f2416290..1f43118c56b 100644 --- a/completions/strace +++ b/completions/strace @@ -40,7 +40,7 @@ _strace() while read -r define syscall rest; do [[ $define == "#define" && $syscall =~ ^__NR_(.+) ]] && - syscalls[${BASH_REMATCH[1]}]=1 + syscalls[${BASH_REMATCH[1]}]=set done 2>/dev/null /dev/null <$unistd fi diff --git a/completions/svcadm b/completions/svcadm index 115f90680d8..b29fdde13e7 100644 --- a/completions/svcadm +++ b/completions/svcadm @@ -29,7 +29,7 @@ _smf_complete_fmri() if [[ $cur == $prefix* ]]; then [[ $cur == "$prefix" ]] && cur+="/" pattern="$cur*" - exact_mode=1 + exact_mode=set else pattern="$prefix*/$cur*" fi diff --git a/completions/sysbench b/completions/sysbench index 21c8a6c682c..afa6261864c 100644 --- a/completions/sysbench +++ b/completions/sysbench @@ -105,23 +105,23 @@ _sysbench() esac # find out which test we're running - local i test="" has_test=false + local i test="" has_test="" for ((i = 1; i < ${#words[@]} - 1; i++)); do # TODO --test= is deprecated, bare test name preferred if [[ ${words[i]} == --test* ]]; then test=${words[i]#*=} - has_test=true + has_test=set break fi done local opts=$(_parse_help "$1") - if "$has_test"; then + if [[ $has_test ]]; then local help=($(_parse_help "$1" "--test=$test help")) opts="${opts/--test=/} ${help[*]} prepare run cleanup help version" fi - if [[ $cur == -* ]] || ! "$has_test"; then + if [[ $cur == -* || ! $has_test ]]; then COMPREPLY=($(compgen -W "$opts" -- "$cur")) [[ ${COMPREPLY-} == *= ]] && compopt -o nospace else diff --git a/completions/tar b/completions/tar index e9feebb1333..b826a36e1a7 100644 --- a/completions/tar +++ b/completions/tar @@ -171,16 +171,16 @@ __tar_parse_old_opt() # current word is the first word [[ $cword -eq 1 && $cur && ${cur:0:1} != '-' ]] && - old_opt_progress=1 + old_opt_progress=set # check that first argument does not begin with "-" first_word=${words[1]} [[ $first_word && ${first_word:0:1} != "-" ]] && - old_opt_used=1 + old_opt_used=set # parse the old option (if present) contents to allow later code expect # corresponding arguments - if ((old_opt_used == 1)); then + if [[ $old_opt_used ]]; then char=${first_word:0:1} while [[ $char ]]; do if __tar_is_argreq "$char"; then @@ -195,13 +195,12 @@ __tar_parse_old_opt() # Make the analysis of whole command line. __tar_preparse_cmdline() { - local first_arg i modes="ctxurdA" + local first_arg=set i modes="ctxurdA" shift # progname __tar_parse_old_opt - first_arg=1 for i in "$@"; do case "$i" in --delete | --test-label) @@ -220,14 +219,14 @@ __tar_preparse_cmdline() ;; *[$modes]*) # Only the first arg may be "MODE" without leading dash - if ((first_arg == 1)); then + if [[ $first_arg ]]; then tar_mode=${i//[^$modes]/} tar_mode=${tar_mode:0:1} tar_mode_arg=$i fi ;; esac - first_arg=0 + first_arg="" done } @@ -306,7 +305,7 @@ __tar_complete_mode() # The last short option requires argument, like '-cf'. Cut the # completion here to enforce argument processing. - if ((old_opt_progress == 0)) && + if [[ ! $old_opt_progress ]] && __tar_is_argreq "$(__tar_last_char "$cur")"; then COMPREPLY=("$cur") && return 0 fi @@ -383,7 +382,7 @@ __tar_adjust_PREV_from_old_option() # deal with old style arguments here # $ tar cfTC # expects this sequence of arguments: # $ tar cfTC ARCHIVE_FILE PATTERNS_FILE CHANGE_DIR - if ((old_opt_used == 1 && cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then + if [[ $old_opt_used ]] && ((cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then # make e.g. 'C' option from 'cffCT' prev="-${old_opt_parsed[cword - 2]}" fi @@ -488,8 +487,8 @@ _gtar() local long_opts short_opts basic_tar="" \ long_arg_none="" long_arg_opt="" long_arg_req="" \ short_arg_none="" short_arg_opt="" short_arg_req="" \ - tar_mode tar_mode_arg old_opt_progress=0 \ - old_opt_used=0 old_opt_parsed=() + tar_mode tar_mode_arg old_opt_progress="" \ + old_opt_used="" old_opt_parsed=() # Main mode, e.g. -x or -c (extract/creation) local tar_mode=none @@ -675,11 +674,11 @@ __tar_posix_prev_handle() _posix_tar() { - local long_opts short_opts basic_tar="" \ + local long_opts short_opts basic_tar=set \ long_arg_none="" long_arg_opt long_arg_req="" \ short_arg_none short_arg_opt short_arg_req \ - tar_mode tar_mode_arg old_opt_progress=0 \ - old_opt_used=1 old_opt_parsed=() + tar_mode tar_mode_arg old_opt_progress="" \ + old_opt_used=set old_opt_parsed=() # Main mode, e.g. -x or -c (extract/creation) local tar_mode=none @@ -691,7 +690,6 @@ _posix_tar() _comp_initialize -s -- "$@" || return - basic_tar=yes tar_mode=none # relatively compatible modes are {c,t,x} diff --git a/completions/timeout b/completions/timeout index 0929143b01d..98e51adb5c7 100644 --- a/completions/timeout +++ b/completions/timeout @@ -2,17 +2,17 @@ _timeout() { - local cur prev words cword split comp_args i found=false + local cur prev words cword split comp_args i found="" _comp_initialize -s -- "$@" || return local noargopts='!(-*|*[ks]*)' for ((i = 1; i <= COMP_CWORD; i++)); do if [[ ${COMP_WORDS[i]} != -* && ${COMP_WORDS[i - 1]} != = ]]; then - if $found; then + if [[ $found ]]; then _comp_command_offset $i return fi - found=true + found=set fi # shellcheck disable=SC2254 [[ ${COMP_WORDS[i]} == -@(-kill-after|-signal|${noargopts}[ks]) ]] && ((i++)) diff --git a/completions/unpack200 b/completions/unpack200 index 9ad1121ff15..b3d4708c01d 100644 --- a/completions/unpack200 +++ b/completions/unpack200 @@ -25,15 +25,15 @@ _unpack200() $split && return # Check if a pack or a jar was already given. - local word pack=false jar=false + local word pack="" jar="" for word in "${words[@]:1}"; do case $word in - *.pack | *.pack.gz) pack=true ;; - *.jar) jar=true ;; + *.pack | *.pack.gz) pack=set ;; + *.jar) jar=set ;; esac done - if ! $pack; then + if [[ ! $pack ]]; then if [[ $cur == -* ]]; then COMPREPLY=($(compgen -W '--deflate-hint= --remove-pack-file --verbose --quiet --log-file= --help --version' -- "$cur")) @@ -41,7 +41,7 @@ _unpack200() else _filedir 'pack?(.gz)' fi - elif ! $jar; then + elif [[ ! $jar ]]; then _filedir jar fi } && diff --git a/completions/upgradepkg b/completions/upgradepkg index 9dc2b84f967..a2e7e61eaf6 100644 --- a/completions/upgradepkg +++ b/completions/upgradepkg @@ -17,7 +17,7 @@ _upgradepkg() local nofiles="" IFS=$'\n' compopt -o filenames COMPREPLY=($(compgen -P "$prev%" -f -X "!*.@(t[bgxl]z)" -- "$cur")) - [[ ${COMPREPLY-} ]] || nofiles=1 + [[ ${COMPREPLY-} ]] || nofiles=set COMPREPLY+=($(compgen -P "$prev%" -S '/' -d -- "$cur")) [[ $nofiles ]] && compopt -o nospace return diff --git a/completions/useradd b/completions/useradd index fd91bb7c76c..d2ec6fdc6b3 100644 --- a/completions/useradd +++ b/completions/useradd @@ -8,13 +8,13 @@ _useradd() # TODO: if -o/--non-unique is given, could complete on existing uids # with -u/--uid - local word chroot="" has_chroot=false + local word chroot="" has_chroot="" for word in "${words[@]}"; do - if "$has_chroot"; then + if [[ $has_chroot ]]; then chroot=$word break fi - [[ $word != -@(R|-root) ]] || has_chroot=true + [[ $word != -@(R|-root) ]] || has_chroot=set done local noargopts='!(-*|*[cefKpubdkRgGZs]*)' diff --git a/completions/usermod b/completions/usermod index adf8231e07d..8938e339ca2 100644 --- a/completions/usermod +++ b/completions/usermod @@ -8,13 +8,13 @@ _usermod() # TODO: if -o/--non-unique is given, could complete on existing uids # with -u/--uid - local word chroot="" has_chroot=false + local word chroot="" has_chroot="" for word in "${words[@]}"; do - if "$has_chroot"; then + if [[ $has_chroot ]]; then chroot=$word break fi - [[ $word != -@(R|-root) ]] || has_chroot=true + [[ $word != -@(R|-root) ]] || has_chroot=set done local noargopts='!(-*|*[cdeflpugGRZs]*)' diff --git a/completions/wodim b/completions/wodim index 80187a13d3d..5741703747f 100644 --- a/completions/wodim +++ b/completions/wodim @@ -66,15 +66,15 @@ _cdrecord() -isosize -pad -nopad -shorttrack -noshorttrack -preemp -nopreemp -copy -nocopy -scms "isrc=" "index=" "padsize=" "pregap=" "tsize=") # look if previous was either a file or a track option - track_mode=0 + track_mode="" if ((cword > 1)); then if [[ -f $prev ]]; then - track_mode=1 + track_mode=set else local opt for opt in "${track_options[@]}"; do if [[ $opt == "$prev" ]]; then - track_mode=1 + track_mode=set break fi done @@ -86,7 +86,7 @@ _cdrecord() # track options are always available COMPREPLY+=($(compgen -W '"${track_options[@]}"' -- "$cur")) # general options are no more available after file or track option - if ((track_mode == 0)); then + if [[ ! $track_mode ]]; then COMPREPLY+=($(compgen -W '"${generic_options[@]}"' -- "$cur")) fi [[ ${COMPREPLY-} == *= ]] && compopt -o nospace diff --git a/completions/wtf b/completions/wtf index 1e3b844d18f..825e795a5f4 100644 --- a/completions/wtf +++ b/completions/wtf @@ -13,7 +13,7 @@ _wtf() return fi - local db="" has_db=false + local db="" has_db="" set -- "${words[@]}" while (($# > 0)); do @@ -21,20 +21,20 @@ _wtf() shift if (($# > 0)); then db=$1 - has_db=true + has_db=set fi break fi shift done - if ! "$has_db"; then + if [[ ! $has_db ]]; then local f for f in "${ACRONYMDB-}" /usr/share/misc/acronyms \ /usr/share/games/bsdgames/acronyms; do - [[ -f $f ]] && db="$f" has_db=true && break + [[ -f $f ]] && db="$f" has_db=set && break done - "$has_db" || return + [[ $has_db ]] || return fi COMPREPLY=($(compgen -W "$(cut -f 1 -s "$db"* 2>/dev/null) $addf" \ diff --git a/completions/xrandr b/completions/xrandr index 6b1e6a84edc..b0a4b576f41 100644 --- a/completions/xrandr +++ b/completions/xrandr @@ -46,11 +46,11 @@ _xrandr() local cur prev words cword comp_args _comp_initialize -- "$@" || return - local i output has_output=false + local i output has_output="" for ((i = cword - 1; i > 0; i--)); do if [[ ${words[i]} == --output ]]; then output=${words[i + 1]} - has_output=true + has_output=set break fi done @@ -67,14 +67,14 @@ _xrandr() return ;; --left-of | --right-of | --above | --below | --same-as) - if "$has_output"; then + if [[ $has_output ]]; then local outputs=$(_comp_cmd_xrandr_outputs "$1") COMPREPLY=($(compgen -W "$outputs" -- "$cur")) fi return ;; --mode) - if "$has_output"; then + if [[ $has_output ]]; then local modes=$(_comp_cmd_xrandr_modes "$1" "$output") COMPREPLY=($(compgen -W "$modes" -- "$cur")) fi @@ -87,19 +87,19 @@ _xrandr() return ;; --reflect) - if "$has_output"; then + if [[ $has_output ]]; then COMPREPLY=($(compgen -W 'normal x y xy' -- "$cur")) fi return ;; --rotate) - if "$has_output"; then + if [[ $has_output ]]; then COMPREPLY=($(compgen -W 'normal inverted left right' -- "$cur")) fi return ;; --filter) - if "$has_output"; then + if [[ $has_output ]]; then COMPREPLY=($(compgen -W 'bilinear nearest' -- "$cur")) fi return @@ -171,7 +171,7 @@ _xrandr() fi local options - if "$has_output"; then + if [[ $has_output ]]; then options=$( _comp_cmd_xrandr_help "$1" | command sed -e 's/ or /\n /g' -e 's/<[^>]*>]//g' |