Skip to content

style: prefer empty/! over -n/-z #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ _filedir()
local opts=(-f -X "$xspec")
[[ $xspec ]] && plusdirs=(-o plusdirs)
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} ||
-z ${plusdirs-} ]] ||
! ${plusdirs-} ]] ||
opts+=("${plusdirs[@]}")

reset=$(shopt -po noglob)
Expand All @@ -636,7 +636,7 @@ _filedir()

# Try without filter if it failed to produce anything and configured to
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} &&
-n $arg && ${#toks[@]} -lt 1 ]] && {
$arg && ${#toks[@]} -lt 1 ]] && {
reset=$(shopt -po noglob)
set -o noglob
toks+=($(compgen -f ${plusdirs+"${plusdirs[@]}"} -- $quoted))
Expand Down Expand Up @@ -1567,7 +1567,7 @@ _fstypes()
$([[ -d /etc/fs ]] && command ls /etc/fs)"
fi

[[ -n $fss ]] && COMPREPLY+=($(compgen -W "$fss" -- "$cur"))
[[ $fss ]] && COMPREPLY+=($(compgen -W "$fss" -- "$cur"))
}

# Get real command.
Expand Down Expand Up @@ -1952,7 +1952,7 @@ _known_hosts_real()

# Add results of normal hostname completion, unless
# `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
if [[ -n ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then
if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then
COMPREPLY+=(
$(compgen -A hostname -P "$prefix" -S "$suffix" -- "$cur"))
fi
Expand Down Expand Up @@ -1993,7 +1993,7 @@ _cd()

# Use standard dir completion if no CDPATH or parameter starts with /,
# ./ or ../
if [[ -z ${CDPATH:-} || $cur == ?(.)?(.)/* ]]; then
if [[ ! ${CDPATH:-} || $cur == ?(.)?(.)/* ]]; then
_filedir -d
return
fi
Expand Down Expand Up @@ -2136,7 +2136,7 @@ _command_offset()
# Note: When completion spec is removed after 124, we do
# not generate any completions including the default ones.
# This is the behavior of the original Bash progcomp.
[[ -n $cspec ]] || break
[[ $cspec ]] || break

continue
fi
Expand Down Expand Up @@ -2267,7 +2267,7 @@ _filedir_xspec()
toks+=($(
eval compgen -f -X "'!$xspec'" -- '$(quote_readline "$cur")' | {
while read -r tmp; do
[[ -n $tmp ]] && printf '%s\n' $tmp
[[ $tmp ]] && printf '%s\n' $tmp
done
}
))
Expand Down Expand Up @@ -2372,7 +2372,7 @@ __load_completion()
{
local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions)
local IFS=: dir cmd="${1##*/}" compfile
[[ -n $cmd ]] || return 1
[[ $cmd ]] || return 1
for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do
dirs+=($dir/bash-completion/completions)
done
Expand Down
2 changes: 1 addition & 1 deletion completions/_mount
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _mount()
if [[ $cur == //* ]]; then
host=${cur#//}
host=${host%%/*}
if [[ -n $host ]]; then
if [[ $host ]]; then
COMPREPLY=($(compgen -P "//$host" -W \
"$(smbclient -d 0 -NL $host 2>/dev/null |
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |
Expand Down
2 changes: 1 addition & 1 deletion completions/_mount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ _mount()
if [[ $cur == //* ]]; then
host=${cur#//}
host=${host%%/*}
if [[ -n $host ]]; then
if [[ $host ]]; then
COMPREPLY=($(compgen -P "//$host" -W \
"$(smbclient -d 0 -NL $host 2>/dev/null |
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |
Expand Down
2 changes: 1 addition & 1 deletion completions/abook
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _abook()
_init_completion || return

# abook only takes options, tabbing after command name adds a single dash
[[ $cword -eq 1 && -z $cur ]] &&
[[ $cword -eq 1 && ! $cur ]] &&
{
compopt -o nospace
COMPREPLY=("-")
Expand Down
2 changes: 1 addition & 1 deletion completions/carton
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _carton()
return
;;
--help | -h)
[[ -n $command ]] || _carton_commands "$1"
[[ $command ]] || _carton_commands "$1"
return
;;
--cpanfile)
Expand Down
2 changes: 1 addition & 1 deletion completions/cppcheck
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _cppcheck()
;;
--file-list)
_filedir
[[ -z $cur || $cur == - ]] && COMPREPLY+=(-)
[[ ! $cur || $cur == - ]] && COMPREPLY+=(-)
return
;;
-I)
Expand Down
2 changes: 1 addition & 1 deletion completions/cryptsetup
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _cryptsetup()

local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ ! $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
Expand Down
6 changes: 3 additions & 3 deletions completions/cvs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _cvs_entries()

_cvs_modules()
{
if [[ -n $prefix ]]; then
if [[ $prefix ]]; then
COMPREPLY=($(command ls -d ${cvsroot}/${prefix}/!(CVSROOT)))
else
COMPREPLY=($(command ls -d ${cvsroot}/!(CVSROOT)))
Expand Down Expand Up @@ -152,7 +152,7 @@ _cvs()

if [[ $cur != -* ]]; then
_cvs_entries
[[ -z $cur ]] && files=(!(CVS)) ||
[[ ! $cur ]] && files=(!(CVS)) ||
files=($(command ls -d ${cur}* 2>/dev/null))
local f
for i in "${!files[@]}"; do
Expand Down Expand Up @@ -251,7 +251,7 @@ _cvs()
# if $BASH_COMPLETION_CMD_CVS_REMOTE is not null, 'cvs commit'
# will complete on remotely checked-out files (requires
# passwordless access to the remote repository
if [[ -n ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
if [[ ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
# this is the least computationally intensive way found so
# far, but other changes (something other than
# changed/removed/new) may be missing
Expand Down
6 changes: 3 additions & 3 deletions completions/dict
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ _dict()
case ${words[i]} in
--host | -!(-*)h)
host=${words[++i]}
[[ -n $host ]] && host="-h $host"
[[ $host ]] && host="-h $host"
;;
--port | -!(-*)p)
port=${words[++i]}
[[ -n $port ]] && port="-p $port"
[[ $port ]] && port="-p $port"
;;
--database | -!(-*)d)
db=${words[++i]}
[[ -n $db ]] && host="-d $db"
[[ $db ]] && host="-d $db"
;;
esac
done
Expand Down
2 changes: 1 addition & 1 deletion completions/ebtables
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _ebtables()
COMPREPLY=($(compgen -W 'nat filter broute' -- "$cur"))
;;
-!(-*)j)
if [[ $table == "-t filter" || -z $table ]]; then
if [[ $table == "-t filter" || ! $table ]]; then
COMPREPLY=($(compgen -W '$targets
$("$1" $table -L 2>/dev/null | \
command sed -n -e "s/INPUT\|OUTPUT\|FORWARD//" \
Expand Down
12 changes: 6 additions & 6 deletions completions/hcitool
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_bluetooth_addresses()
{
if [[ -n ${COMP_BLUETOOTH_SCAN:-} ]]; then
if [[ ${COMP_BLUETOOTH_SCAN:-} ]]; then
COMPREPLY+=($(compgen -W "$(hcitool scan |
awk '/^\t/{print $1}')" -- "$cur"))
fi
Expand Down Expand Up @@ -51,7 +51,7 @@ _hcitool()

local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ ! $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
else
Expand Down Expand Up @@ -123,7 +123,7 @@ _sdptool()

local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ ! $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
else
Expand Down Expand Up @@ -207,7 +207,7 @@ _rfcomm()

local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ ! $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
else
Expand Down Expand Up @@ -247,7 +247,7 @@ _ciptool()

local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ ! $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
else
Expand Down Expand Up @@ -305,7 +305,7 @@ _hciconfig()

local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ ! $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '--help --all' -- "$cur"))
else
Expand Down
2 changes: 1 addition & 1 deletion completions/info
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ _info()
fi

infopath=$infopath:
if [[ -n $cur ]]; then
if [[ $cur ]]; then
infopath="${infopath//://$cur* }"
else
infopath="${infopath//:// }"
Expand Down
2 changes: 1 addition & 1 deletion completions/iptables
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _iptables()
COMPREPLY=($(compgen -W 'nat filter mangle' -- "$cur"))
;;
-j)
if [[ $table == "-t filter" || -z $table ]]; then
if [[ $table == "-t filter" || ! $table ]]; then
COMPREPLY=($(compgen -W 'ACCEPT DROP LOG ULOG REJECT
`"$1" $table -nL 2>/dev/null | command sed -ne "$chain" \
-e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
Expand Down
2 changes: 1 addition & 1 deletion completions/java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _java_find_classpath()
[[ ! -v classpath ]] && classpath=${CLASSPATH-}

# default to current directory
[[ -z $classpath ]] && classpath=.
[[ ! $classpath ]] && classpath=.
}

# exact sourcepath determination
Expand Down
2 changes: 1 addition & 1 deletion completions/make
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ _make_target_extract_script()
EOF

# don't complete with hidden targets unless we are doing a partial completion
if [[ -z ${prefix_pat} || ${prefix_pat} == */ ]]; then
if [[ ! ${prefix_pat} || ${prefix_pat} == */ ]]; then
cat <<EOF
/^${prefix_pat}[^a-zA-Z0-9]/d; # convention for hidden tgt
EOF
Expand Down
4 changes: 2 additions & 2 deletions completions/man
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _man()
fi

local manpath=$(manpath 2>/dev/null || command man -w 2>/dev/null)
if [[ -z $manpath ]]; then
if [[ ! $manpath ]]; then
# Note: Both "manpath" and "man -w" may be unavailable, in
# which case we determine the man paths based on the
# environment variable MANPATH.
Expand All @@ -76,7 +76,7 @@ _man()
[[ $prev == $mansect ]] && sect=$prev || sect='*'

manpath=$manpath:
if [[ -n $cur ]]; then
if [[ $cur ]]; then
manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
else
manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
Expand Down
4 changes: 2 additions & 2 deletions completions/modprobe
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ _modprobe()
# skip all other options
;;
*)
[[ -z $module ]] && module=${words[i]}
[[ ! $module ]] && module=${words[i]}
;;
esac
done
Expand All @@ -81,7 +81,7 @@ _modprobe()
# do filename completion if we're giving a path to a module
if [[ $cur == @(*/|[.~])* ]]; then
_filedir '@(?(k)o?(.[gx]z|.zst))'
elif [[ -n $module ]]; then
elif [[ $module ]]; then
# do module parameter completion
if [[ $cur == *=* ]]; then
prev=${cur%%=*}
Expand Down
2 changes: 1 addition & 1 deletion completions/mplayer
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ _mplayer()
# if you don't have installed mplayer in /usr you
# may want to set the MPLAYER_SKINS_DIR global variable
local -a dirs
if [[ -n $MPLAYER_SKINS_DIR ]]; then
if [[ $MPLAYER_SKINS_DIR ]]; then
dirs=($MPLAYER_SKINS_DIR)
else
dirs=(/usr/share/mplayer/skins /usr/local/share/mplayer/skins)
Expand Down
2 changes: 1 addition & 1 deletion completions/mr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _mr()
bootstrap)
_filedir
# Also complete stdin (-) as a potential bootstrap source.
if [[ -z ${cur} || $cur == - ]] && [[ $prev != - ]]; then
if [[ ! ${cur} || $cur == - ]] && [[ $prev != - ]]; then
COMPREPLY+=(-)
fi
return
Expand Down
6 changes: 3 additions & 3 deletions completions/mutt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ _muttaliases()
local -a conffiles aliases

muttrc=$(_muttrc)
[[ -z $muttrc ]] && return
[[ ! $muttrc ]] && return

conffiles=($(eval _muttconffiles $muttrc $muttrc))
# shellcheck disable=SC2046
Expand All @@ -88,7 +88,7 @@ _muttquery()
local -a queryresults

querycmd="$($muttcmd -Q query_command 2>/dev/null | command sed -e 's|^query_command=\"\(.*\)\"$|\1|' -e 's|%s|'$cur'|')"
if [[ -z $cur || -z $querycmd ]]; then
if [[ ! $cur || ! $querycmd ]]; then
queryresults=()
else
__expand_tilde_by_ref querycmd
Expand Down Expand Up @@ -118,7 +118,7 @@ _muttfiledir()
elif [[ $cur == !* ]]; then
spoolfile="$($muttcmd -F "$muttrc" -Q spoolfile 2>/dev/null |
command sed -e 's|^spoolfile=\"\(.*\)\"$|\1|')"
[[ -n $spoolfile ]] && eval cur="${cur/^!/$spoolfile}"
[[ $spoolfile ]] && eval cur="${cur/^!/$spoolfile}"
fi
_filedir
}
Expand Down
2 changes: 1 addition & 1 deletion completions/openssl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _openssl_sections()
done

# if no config given, check some usual default locations
if [[ -z $config ]]; then
if [[ ! $config ]]; then
for f in /etc/ssl/openssl.cnf /etc/pki/tls/openssl.cnf \
/usr/share/ssl/openssl.cnf; do
[[ -f $f ]] && config=$f && break
Expand Down
2 changes: 1 addition & 1 deletion completions/pkg-get
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _pkg_get_get_catalog_file()
done
conffile="${conffile:-/opt/csw/etc/pkg-get.conf}"

if [[ -z $url ]]; then
if [[ ! $url ]]; then
url=$(awk -F= ' $1=="url" { print $2 }' $conffile)
fi

Expand Down
4 changes: 2 additions & 2 deletions completions/puppet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_puppet_logdest()
{
if [[ -z $cur ]]; then
if [[ ! $cur ]]; then
COMPREPLY=($(compgen -W 'syslog console /' -- "$cur"))
else
COMPREPLY=($(compgen -W 'syslog console' -- "$cur"))
Expand Down Expand Up @@ -55,7 +55,7 @@ _puppet_references()
_puppet_subcmd_opts()
{
# puppet cmd help is somewhat slow, avoid if possible
[[ -z $cur || $cur == -* ]] &&
[[ ! $cur || $cur == -* ]] &&
COMPREPLY+=($(compgen -W \
'$(_parse_usage "$1" "help $2")' -- "$cur"))
}
Expand Down
2 changes: 1 addition & 1 deletion completions/qdbus
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _qdbus()
local cur prev words cword
_init_completion || return

[[ -n $cur ]] && unset -v "words[$((${#words[@]} - 1))]"
[[ $cur ]] && unset -v "words[$((${#words[@]} - 1))]"
COMPREPLY=($(compgen -W '$(command ${words[@]} 2>/dev/null | \
command sed "s/(.*)//")' -- "$cur"))
} &&
Expand Down
Loading