Skip to content

Commit a2db7ad

Browse files
authored
Merge pull request #740 from scop/style/nz
style: prefer empty/`!` over `-n`/`-z`
2 parents 3ef73c4 + 063765c commit a2db7ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+83
-75
lines changed

bash_completion

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ _filedir()
624624
local opts=(-f -X "$xspec")
625625
[[ $xspec ]] && plusdirs=(-o plusdirs)
626626
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} ||
627-
-z ${plusdirs-} ]] ||
627+
! ${plusdirs-} ]] ||
628628
opts+=("${plusdirs[@]}")
629629

630630
reset=$(shopt -po noglob)
@@ -636,7 +636,7 @@ _filedir()
636636

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

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

15731573
# Get real command.
@@ -1952,7 +1952,7 @@ _known_hosts_real()
19521952

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

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

21412141
continue
21422142
fi
@@ -2267,7 +2267,7 @@ _filedir_xspec()
22672267
toks+=($(
22682268
eval compgen -f -X "'!$xspec'" -- '$(quote_readline "$cur")' | {
22692269
while read -r tmp; do
2270-
[[ -n $tmp ]] && printf '%s\n' $tmp
2270+
[[ $tmp ]] && printf '%s\n' $tmp
22712271
done
22722272
}
22732273
))
@@ -2372,7 +2372,7 @@ __load_completion()
23722372
{
23732373
local -a dirs=(${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions)
23742374
local IFS=: dir cmd="${1##*/}" compfile
2375-
[[ -n $cmd ]] || return 1
2375+
[[ $cmd ]] || return 1
23762376
for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do
23772377
dirs+=($dir/bash-completion/completions)
23782378
done

completions/_mount

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _mount()
4242
if [[ $cur == //* ]]; then
4343
host=${cur#//}
4444
host=${host%%/*}
45-
if [[ -n $host ]]; then
45+
if [[ $host ]]; then
4646
COMPREPLY=($(compgen -P "//$host" -W \
4747
"$(smbclient -d 0 -NL $host 2>/dev/null |
4848
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |

completions/_mount.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ _mount()
236236
if [[ $cur == //* ]]; then
237237
host=${cur#//}
238238
host=${host%%/*}
239-
if [[ -n $host ]]; then
239+
if [[ $host ]]; then
240240
COMPREPLY=($(compgen -P "//$host" -W \
241241
"$(smbclient -d 0 -NL $host 2>/dev/null |
242242
command sed -ne '/^[[:blank:]]*Sharename/,/^$/p' |

completions/abook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _abook()
66
_init_completion || return
77

88
# abook only takes options, tabbing after command name adds a single dash
9-
[[ $cword -eq 1 && -z $cur ]] &&
9+
[[ $cword -eq 1 && ! $cur ]] &&
1010
{
1111
compopt -o nospace
1212
COMPREPLY=("-")

completions/carton

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ _carton()
3939
return
4040
;;
4141
--help | -h)
42-
[[ -n $command ]] || _carton_commands "$1"
42+
[[ $command ]] || _carton_commands "$1"
4343
return
4444
;;
4545
--cpanfile)

completions/cppcheck

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ _cppcheck()
3535
;;
3636
--file-list)
3737
_filedir
38-
[[ -z $cur || $cur == - ]] && COMPREPLY+=(-)
38+
[[ ! $cur || $cur == - ]] && COMPREPLY+=(-)
3939
return
4040
;;
4141
-I)

completions/cryptsetup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ _cryptsetup()
3535

3636
local arg
3737
_get_first_arg
38-
if [[ -z $arg ]]; then
38+
if [[ ! $arg ]]; then
3939
if [[ $cur == -* ]]; then
4040
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
4141
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace

completions/cvs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _cvs_entries()
1313

1414
_cvs_modules()
1515
{
16-
if [[ -n $prefix ]]; then
16+
if [[ $prefix ]]; then
1717
COMPREPLY=($(command ls -d ${cvsroot}/${prefix}/!(CVSROOT)))
1818
else
1919
COMPREPLY=($(command ls -d ${cvsroot}/!(CVSROOT)))
@@ -152,7 +152,7 @@ _cvs()
152152

153153
if [[ $cur != -* ]]; then
154154
_cvs_entries
155-
[[ -z $cur ]] && files=(!(CVS)) ||
155+
[[ ! $cur ]] && files=(!(CVS)) ||
156156
files=($(command ls -d ${cur}* 2>/dev/null))
157157
local f
158158
for i in "${!files[@]}"; do
@@ -251,7 +251,7 @@ _cvs()
251251
# if $BASH_COMPLETION_CMD_CVS_REMOTE is not null, 'cvs commit'
252252
# will complete on remotely checked-out files (requires
253253
# passwordless access to the remote repository
254-
if [[ -n ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
254+
if [[ ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
255255
# this is the least computationally intensive way found so
256256
# far, but other changes (something other than
257257
# changed/removed/new) may be missing

completions/dict

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ _dict()
1717
case ${words[i]} in
1818
--host | -!(-*)h)
1919
host=${words[++i]}
20-
[[ -n $host ]] && host="-h $host"
20+
[[ $host ]] && host="-h $host"
2121
;;
2222
--port | -!(-*)p)
2323
port=${words[++i]}
24-
[[ -n $port ]] && port="-p $port"
24+
[[ $port ]] && port="-p $port"
2525
;;
2626
--database | -!(-*)d)
2727
db=${words[++i]}
28-
[[ -n $db ]] && host="-d $db"
28+
[[ $db ]] && host="-d $db"
2929
;;
3030
esac
3131
done

completions/ebtables

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _ebtables()
2020
COMPREPLY=($(compgen -W 'nat filter broute' -- "$cur"))
2121
;;
2222
-!(-*)j)
23-
if [[ $table == "-t filter" || -z $table ]]; then
23+
if [[ $table == "-t filter" || ! $table ]]; then
2424
COMPREPLY=($(compgen -W '$targets
2525
$("$1" $table -L 2>/dev/null | \
2626
command sed -n -e "s/INPUT\|OUTPUT\|FORWARD//" \

0 commit comments

Comments
 (0)