Cleanups: Use [[ instead of [.

master
Ville Skyttä 2011-11-09 23:28:11 +02:00
parent 1d48f79b9c
commit 3b8ef29ef3
76 changed files with 226 additions and 237 deletions

View File

@ -265,7 +265,7 @@ __reassemble_comp_words_by_ref()
ref="$2[$j]"
eval $2[$j]=\${!ref}\${COMP_WORDS[i]}
# Indicate new cword
[ $i = $COMP_CWORD ] && eval $3=$j
[[ $i == $COMP_CWORD ]] && eval $3=$j
# Remove optional whitespace + word separator from line copy
line=${line#*"${COMP_WORDS[$i]}"}
# Start new word if word separator in original line is
@ -480,7 +480,7 @@ _get_cword()
#
_get_pword()
{
if [ $COMP_CWORD -ge 1 ]; then
if [[ $COMP_CWORD -ge 1 ]]; then
_get_cword "${@:-}" 1
fi
}
@ -509,7 +509,7 @@ __ltrim_colon_completions()
# Remove colon-word prefix from COMPREPLY items
local colon_word=${1%${1##*:}}
local i=${#COMPREPLY[*]}
while [ $((--i)) -ge 0 ]; do
while [[ $((--i)) -ge 0 ]]; do
COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"}
done
fi
@ -589,7 +589,7 @@ _filedir()
-n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
toks+=( $( compgen -f -- $quoted ) )
[ ${#toks[@]} -ne 0 ] && compopt -o filenames 2>/dev/null
[[ ${#toks[@]} -ne 0 ]] && compopt -o filenames 2>/dev/null
COMPREPLY+=( "${toks[@]}" )
} # _filedir()
@ -824,16 +824,16 @@ _mac_addresses()
#
_configured_interfaces()
{
if [ -f /etc/debian_version ]; then
if [[ -f /etc/debian_version ]]; then
# Debian system
COMPREPLY=( $( compgen -W "$( sed -ne 's|^iface \([^ ]\{1,\}\).*$|\1|p'\
/etc/network/interfaces )" -- "$cur" ) )
elif [ -f /etc/SuSE-release ]; then
elif [[ -f /etc/SuSE-release ]]; then
# SuSE system
COMPREPLY=( $( compgen -W "$( printf '%s\n' \
/etc/sysconfig/network/ifcfg-* | \
sed -ne 's|.*ifcfg-\(.*\)|\1|p' )" -- "$cur" ) )
elif [ -f /etc/pld-release ]; then
elif [[ -f /etc/pld-release ]]; then
# PLD Linux
COMPREPLY=( $( compgen -W "$( command ls -B \
/etc/sysconfig/interfaces | \
@ -872,9 +872,9 @@ _available_interfaces()
{
local cmd
if [ "${1:-}" = -w ]; then
if [[ ${1:-} == -w ]]; then
cmd="iwconfig"
elif [ "${1:-}" = -a ]; then
elif [[ ${1:-} == -a ]]; then
cmd="ifconfig"
else
cmd="ifconfig -a"
@ -905,7 +905,7 @@ _tilde()
# Try generate ~username completions
COMPREPLY=( $( compgen -P '~' -u "${1#\~}" ) )
result=${#COMPREPLY[@]}
[ $result -gt 0 ] && compopt -o filenames 2>/dev/null
[[ $result -gt 0 ]] && compopt -o filenames 2>/dev/null
fi
return $result
}
@ -970,7 +970,7 @@ _expand()
elif [[ "$cur" == \~* ]]; then
cur=${cur#\~}
COMPREPLY=( $( compgen -P '~' -u "$cur" ) )
[ ${#COMPREPLY[@]} -eq 1 ] && eval COMPREPLY[0]=${COMPREPLY[0]}
[[ ${#COMPREPLY[@]} -eq 1 ]] && eval COMPREPLY[0]=${COMPREPLY[0]}
return ${#COMPREPLY[@]}
fi
}
@ -1095,7 +1095,7 @@ _service()
_init_completion || return
# don't complete past 2nd token
[ $cword -gt 2 ] && return 0
[[ $cword -gt 2 ]] && return 0
if [[ $cword -eq 1 && $prev == ?(*/)service ]]; then
_services
@ -1112,7 +1112,7 @@ complete -F _service service
_sysvdirs
for svcdir in ${sysvdirs[@]}; do
for svc in $svcdir/!($_backup_glob); do
[ -x "$svc" ] && complete -F _service $svc
[[ -x $svc ]] && complete -F _service $svc
done
done
unset svc svcdir sysvdirs
@ -1228,7 +1228,7 @@ _fstypes()
{
local fss
if [ -e /proc/filesystems ] ; then
if [[ -e /proc/filesystems ]]; then
# Linux
fss="$( cut -d$'\t' -f2 /proc/filesystems )
$( awk '! /\*/ { print $NF }' /etc/filesystems 2>/dev/null )"
@ -1238,11 +1238,10 @@ _fstypes()
$( awk '/^[ \t]*[^#]/ { print $3 }' /etc/mnttab 2>/dev/null )
$( awk '/^[ \t]*[^#]/ { print $4 }' /etc/vfstab 2>/dev/null )
$( awk '{ print $1 }' /etc/dfs/fstypes 2>/dev/null )
$( [ -d /etc/fs ] && command ls /etc/fs )"
$( [[ -d /etc/fs ]] && command ls /etc/fs )"
fi
[ -n "$fss" ] && \
COMPREPLY+=( $( compgen -W "$fss" -- "$cur" ) )
[[ -n $fss ]] && COMPREPLY+=( $( compgen -W "$fss" -- "$cur" ) )
}
# Get real command.
@ -1396,26 +1395,25 @@ _known_hosts_real()
p) prefix=$OPTARG ;;
esac
done
[ $# -lt $OPTIND ] && echo "error: $FUNCNAME: missing mandatory argument CWORD"
[[ $# -lt $OPTIND ]] && echo "error: $FUNCNAME: missing mandatory argument CWORD"
cur=${!OPTIND}; let "OPTIND += 1"
[ $# -ge $OPTIND ] && echo "error: $FUNCNAME("$@"): unprocessed arguments:"\
$(while [ $# -ge $OPTIND ]; do printf '%s\n' ${!OPTIND}; shift; done)
[[ $# -ge $OPTIND ]] && echo "error: $FUNCNAME("$@"): unprocessed arguments:"\
$(while [[ $# -ge $OPTIND ]]; do printf '%s\n' ${!OPTIND}; shift; done)
[[ $cur == *@* ]] && user=${cur%@*}@ && cur=${cur#*@}
kh=()
# ssh config files
if [ -n "$configfile" ]; then
[ -r "$configfile" ] &&
config+=( "$configfile" )
if [[ -n $configfile ]]; then
[[ -r $configfile ]] && config+=( "$configfile" )
else
for i in /etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config; do
[ -r "$i" ] && config+=( "$i" )
[[ -r $i ]] && config+=( "$i" )
done
fi
# Known hosts files from configs
if [ ${#config[@]} -gt 0 ]; then
if [[ ${#config[@]} -gt 0 ]]; then
local OIFS=$IFS IFS=$'\n'
local -a tmpkh
# expand paths (if present) to global and user known hosts files
@ -1428,20 +1426,20 @@ _known_hosts_real()
i=${i//\"}
# Eval/expand possible `~' or `~user'
__expand_tilde_by_ref i
[ -r "$i" ] && kh+=( "$i" )
[[ -r $i ]] && kh+=( "$i" )
done
IFS=$OIFS
fi
if [ -z "$configfile" ]; then
if [[ -z $configfile ]]; then
# Global and user known_hosts files
for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 \
/etc/known_hosts /etc/known_hosts2 ~/.ssh/known_hosts \
~/.ssh/known_hosts2; do
[ -r "$i" ] && kh+=( "$i" )
[[ -r $i ]] && kh+=( "$i" )
done
for i in /etc/ssh2/knownhosts ~/.ssh2/hostkeys; do
[ -d "$i" ] && khd+=( "$i"/*pub )
[[ -d $i ]] && khd+=( "$i"/*pub )
done
fi
@ -1459,14 +1457,14 @@ _known_hosts_real()
# Digits followed by no dot or colon - search for digits followed
# by a dot or a colon
awkcur="^$awkcur.*[.:]"
elif [ -z "$awkcur" ]; then
elif [[ -z $awkcur ]]; then
# A blank - search for a dot, a colon, or an alpha character
awkcur="[a-z.:]"
else
awkcur="^$awkcur"
fi
if [ ${#kh[@]} -gt 0 ]; then
if [[ ${#kh[@]} -gt 0 ]]; then
# FS needs to look for a comma separated list
COMPREPLY+=( $( awk 'BEGIN {FS=","}
/^\s*[^|\#]/ {
@ -1477,7 +1475,7 @@ _known_hosts_real()
if ($i !~ /[*?]/ && $i ~ /'"$awkcur"'/) {print $i} \
}}' "${kh[@]}" 2>/dev/null ) )
fi
if [ ${#khd[@]} -gt 0 ]; then
if [[ ${#khd[@]} -gt 0 ]]; then
# Needs to look for files called
# .../.ssh2/key_22_<hostname>.pub
# dont fork any processes, because in a cluster environment,
@ -1519,7 +1517,7 @@ _known_hosts_real()
# Add results of normal hostname completion, unless
# `COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
if [ -n "${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}" ]; then
if [[ -n ${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1} ]]; then
COMPREPLY+=(
$( compgen -A hostname -P "$prefix$user" -S "$suffix" -- "$cur" ) )
fi
@ -1661,7 +1659,7 @@ _command_offset()
fi
if [[ -n $cspec ]]; then
if [ "${cspec#* -F }" != "$cspec" ]; then
if [[ ${cspec#* -F } != $cspec ]]; then
# complete -F <function>
# get function name
@ -1679,7 +1677,7 @@ _command_offset()
while true; do
# FIXME: should we take "+o opt" into account?
t=${cspec#*-o }
if [ "$t" == "$cspec" ]; then
if [[ $t == $cspec ]]; then
break
fi
opt=${t%% *}
@ -1691,7 +1689,7 @@ _command_offset()
cspec=${cspec%%$compcmd}
COMPREPLY=( $( eval compgen "$cspec" -- "$cur" ) )
fi
elif [ ${#COMPREPLY[@]} -eq 0 ]; then
elif [[ ${#COMPREPLY[@]} -eq 0 ]]; then
_minimal
fi
fi
@ -1800,12 +1798,12 @@ _filedir_xspec()
toks+=( $(
eval compgen -f -X "!$xspec" -- "\$(quote_readline "\$cur")" | {
while read -r tmp; do
[ -n $tmp ] && printf '%s\n' $tmp
[[ -n $tmp ]] && printf '%s\n' $tmp
done
}
))
[ ${#toks[@]} -ne 0 ] && compopt -o filenames
[[ ${#toks[@]} -ne 0 ]] && compopt -o filenames
COMPREPLY=( "${toks[@]}" )
}

View File

@ -12,7 +12,7 @@ _mock()
local cfgdir=/etc/mock count=0 i
for i in "${words[@]}" ; do
[ $count -eq $cword ] && break
[[ $count -eq $cword ]] && break
if [[ "$i" == --configdir ]] ; then
cfgdir="${words[((count+1))]}"
elif [[ "$i" == --configdir=* ]] ; then

View File

@ -49,7 +49,7 @@ _module ()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ] ; then
if [[ $cword -eq 1 ]]; then
# First parameter on line -- we expect it to be a mode selection
local options
@ -58,7 +58,7 @@ _module ()
COMPREPLY=( $(compgen -W "$options" -- "$cur") )
elif [ $cword -eq 2 ] ; then
elif [[ $cword -eq 2 ]]; then
case $prev in
add|display|help|load|show|whatis)
COMPREPLY=( $(_module_avail "$cur") )
@ -70,7 +70,7 @@ _module ()
COMPREPLY=( $(_module_path "$cur") )
;;
esac
elif [ $cword -eq 3 ] ; then
elif [[ $cword -eq 3 ]]; then
case ${words[1]} in
swap|switch)
COMPREPLY=( $(_module_avail "$cur") )

View File

@ -45,7 +45,7 @@ _yum()
fi
done
if [ -n "$special" ]; then
if [[ -n $special ]]; then
# TODO: install|update|upgrade should not match *src.rpm
if [[ "$cur" == @(*/|[.~])* && \
"$special" == @(deplist|install|update|upgrade) ]]; then

View File

@ -45,7 +45,7 @@ _ant()
break
fi
done
[ ! -f $buildfile ] && return 0
[[ ! -f $buildfile ]] && return 0
# parse buildfile for targets
local line targets

View File

@ -12,7 +12,7 @@ _apt_build()
fi
done
if [ -n "$special" ]; then
if [[ -n $special ]]; then
case $special in
install|source|info)
COMPREPLY=( $( apt-cache pkgnames "$cur" 2> /dev/null ) )

View File

@ -6,7 +6,7 @@ _apt_cache()
_init_completion || return
local special i
if [ "$cur" != show ]; then
if [[ $cur != show ]]; then
for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == @(add|depends|dotty|madison|policy|rdepends|show?(pkg|src|)) ]]; then
special=${words[i]}
@ -15,7 +15,7 @@ _apt_cache()
fi
if [ -n "$special" ]; then
if [[ -n $special ]]; then
case $special in
add)
_filedir

View File

@ -12,10 +12,10 @@ _apt_get()
fi
done
if [ -n "$special" ]; then
if [[ -n $special ]]; then
case $special in
remove|autoremove|purge)
if [ -f /etc/debian_version ]; then
if [[ -f /etc/debian_version ]]; then
# Debian system
COMPREPLY=( $( \
_xfunc dpkg _comp_dpkg_installed_packages $cur ) )

View File

@ -10,7 +10,7 @@ _avctrl()
else
local args
_count_args
if [ $args -eq 1 ]; then
if [[ $args -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'discover switch' -- "$cur" ) )
fi
fi

View File

@ -5,7 +5,7 @@ _cardctl()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'status config ident suspend \
resume reset eject insert scheme' -- "$cur" ) )
fi

View File

@ -31,7 +31,7 @@ _cfrun()
break
fi
done
[ ! -f $hostfile ] && return 0
[[ ! -f $hostfile ]] && return 0
COMPREPLY=( $(compgen -W "$( command grep -v \
-E '(=|^$|^#)' $hostfile )" -- "$cur" ) )

View File

@ -5,7 +5,7 @@ _cksfv()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi

View File

@ -26,7 +26,7 @@ _configure()
# --option=SETTING will include 'SETTING' as a contextual hint
[[ "$cur" != -* ]] && return 0
if [ -n "$COMP_CONFIGURE_HINTS" ]; then
if [[ -n $COMP_CONFIGURE_HINTS ]]; then
COMPREPLY=( $( compgen -W "$( $1 --help 2>&1 | \
awk '/^ --[A-Za-z]/ { print $1; \
if ($2 ~ /--[A-Za-z]/) print $2 }' | sed -e 's/[[,].*//g' )" \

View File

@ -33,7 +33,7 @@ _cpio()
$split && return 0
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W '-o --create -i --extract -p --pass-through \
-? --help --license --usage --version' -- "$cur" ) )
else

View File

@ -28,7 +28,7 @@ _cryptsetup()
local arg
_get_first_arg
if [ -z $arg ]; then
if [[ -z $arg ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace

View File

@ -13,7 +13,7 @@ _cvs_entries()
_cvs_modules()
{
if [ -n "$prefix" ]; then
if [[ -n $prefix ]]; then
COMPREPLY=( $( command ls -d ${cvsroot}/${prefix}/!(CVSROOT) ) )
else
COMPREPLY=( $( command ls -d ${cvsroot}/!(CVSROOT) ) )
@ -39,9 +39,8 @@ _cvs_roots()
{
local -a cvsroots
cvsroots=( $CVSROOT )
[ -r ~/.cvspass ] && \
cvsroots+=( $( awk '{ print $2 }' ~/.cvspass ) )
[ -r CVS/Root ] && mapfile -tO ${#cvsroots[@]} cvsroots < CVS/Root
[[ -r ~/.cvspass ]] && cvsroots+=( $( awk '{ print $2 }' ~/.cvspass ) )
[[ -r CVS/Root ]] && mapfile -tO ${#cvsroots[@]} cvsroots < CVS/Root
COMPREPLY=( $( compgen -W '${cvsroots[@]}' -- "$cur" ) )
__ltrim_colon_completions "$cur"
}
@ -56,12 +55,12 @@ _cvs()
count=0
for i in "${words[@]}"; do
[ $count -eq $cword ] && break
[[ $count -eq $cword ]] && break
# Last parameter was the CVSROOT, now go back to mode selection
if [[ "${words[((count))]}" == "$cvsroot" && "$mode" == cvsroot ]]; then
mode=""
fi
if [ -z "$mode" ]; then
if [[ -z $mode ]]; then
case $i in
-H|--help)
COMPREPLY=( $( compgen -W "$( _cvs_commands )" -- "$cur" ) )
@ -152,7 +151,7 @@ _cvs()
if [[ "$cur" != -* ]]; then
_cvs_entries
[ -z "$cur" ] && files=( !(CVS) ) || \
[[ -z $cur ]] && files=( !(CVS) ) || \
files=( $( command ls -d ${cur}* 2>/dev/null ) )
local f
for i in ${!files[@]}; do
@ -221,7 +220,7 @@ _cvs()
esac
if [[ "$cur" != -* ]]; then
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
[[ -z $cvsroot ]] && cvsroot=$CVSROOT
COMPREPLY=( $( cvs -d "$cvsroot" co -c 2> /dev/null | \
awk '{print $1}' ) )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
@ -244,7 +243,7 @@ _cvs()
# if $COMP_CVS_REMOTE is not null, 'cvs commit' will
# complete on remotely checked-out files (requires
# passwordless access to the remote repository
if [ -n "${COMP_CVS_REMOTE:-}" ]; then
if [[ -n ${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
@ -298,7 +297,7 @@ _cvs()
esac
if [[ "$cur" != -* ]]; then
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
[[ -z $cvsroot ]] && cvsroot=$CVSROOT
COMPREPLY=( $( cvs -d "$cvsroot" co -c | awk '{print $1}' ) )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
else
@ -318,9 +317,9 @@ _cvs()
if [[ "$cur" != -* ]]; then
# starts with same algorithm as checkout
[ -z "$cvsroot" ] && cvsroot=$CVSROOT
[[ -z $cvsroot ]] && cvsroot=$CVSROOT
local prefix=${cur%/*}
if [ -r ${cvsroot}/${prefix} ]; then
if [[ -r ${cvsroot}/${prefix} ]]; then
_cvs_modules
COMPREPLY=( ${COMPREPLY[@]#$cvsroot} )
COMPREPLY=( ${COMPREPLY[@]#\/} )
@ -337,7 +336,7 @@ _cvs()
_cvs_entries
# find out what files are missing
for i in "${entries[@]}"; do
[ ! -r "$i" ] && miss+=( $i )
[[ ! -r $i ]] && miss+=( $i )
done
COMPREPLY=( $( compgen -W '${miss[@]:-}' -- "$cur" ) )
else

View File

@ -17,17 +17,17 @@ _dict()
case ${words[i]} in
-h|--host)
host=${words[i+1]}
[ -n "$host" ] && host="-h $host"
[[ -n $host ]] && host="-h $host"
i=$((++i))
;;
-p|--port)
port=${words[i+1]}
[ -n "$port" ] && port="-p $port"
[[ -n $port ]] && port="-p $port"
i=$((++i))
;;
-d|--database)
db=${words[i+1]}
[ -n "$db" ] && host="-d $db"
[[ -n $db ]] && host="-d $db"
i=$((++i))
;;
*)
@ -54,7 +54,7 @@ _dict()
esac
local dictfile=/usr/share/dict/words
[ -r $dictfile ] && \
[[ -r $dictfile ]] && \
COMPREPLY=( $( compgen -W '$( cat $dictfile )' -- "$cur" ) )
} &&
complete -F _dict -o default dict rdict

View File

@ -5,7 +5,7 @@ _e2label()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
cur=${cur:=/dev/}
_filedir
fi

View File

@ -46,7 +46,7 @@ _feh()
-T|--theme)
local conf_path=~/.config/feh/themes
local theme_name theme_opts
[ -r "$conf_path" ] || return
[[ -r $conf_path ]] || return
while read theme_name theme_opts; do
if [[ "$theme_name" == '#'* || "$theme_name" == "" ]]; then
continue

View File

@ -6,12 +6,12 @@ _function()
_init_completion || return
if [[ $1 == @(declare|typeset) ]]; then
if [ "$prev" = -f ]; then
if [[ $prev == -f ]]; then
COMPREPLY=( $( compgen -A function -- "$cur" ) )
elif [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-a -f -F -i -r -x -p' -- "$cur" ) )
fi
elif [ $cword -eq 1 ]; then
elif [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -A function -- "$cur" ) )
else
COMPREPLY=( "() $( type -- ${words[1]} | sed -e 1,2d )" )

View File

@ -5,7 +5,7 @@ _gdb()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
local IFS
compopt -o filenames
if [[ "$cur" == */* ]]; then
@ -24,7 +24,7 @@ _gdb()
-mindepth 1 -maxdepth 1 -not -type d -executable \
-printf "%f\\n" 2>/dev/null)' -- "$cur" ) )
fi
elif [ $cword -eq 2 ]; then
elif [[ $cword -eq 2 ]]; then
COMPREPLY=( $( compgen -W "$( command ps axo comm,pid | \
awk '{if ($1 ~ /^'"${prev##*/}"'/) print $2}' )" -- "$cur" ) )
compopt -o filenames

View File

@ -20,7 +20,7 @@ _gpg()
-r|--recipient)
COMPREPLY=( $( compgen -W "$( gpg --list-keys 2>/dev/null | \
sed -ne 's@^.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ))
if [ -e ~/.gnupg/gpg.conf ]; then
if [[ -e ~/.gnupg/gpg.conf ]]; then
COMPREPLY+=( $( compgen -W "$( sed -ne \
's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' \
~/.gnupg/gpg.conf )" -- "$cur") )

View File

@ -24,7 +24,7 @@ _gpg2()
-r|--recipient)
COMPREPLY=( $( compgen -W "$( gpg2 --list-keys 2>/dev/null | \
sed -ne 's@^.*<\([^>]*\)>.*$@\1@p')" -- "$cur" ))
if [ -e ~/.gnupg/gpg.conf ]; then
if [[ -e ~/.gnupg/gpg.conf ]]; then
COMPREPLY+=( $( compgen -W "$( sed -ne \
's@^[ \t]*group[ \t][ \t]*\([^=]*\).*$@\1@p' \
~/.gnupg/gpg.conf)" -- "$cur"))

View File

@ -2,7 +2,7 @@
_bluetooth_adresses()
{
if [ -n "${COMP_BLUETOOTH_SCAN:-}" ]; then
if [[ -n ${COMP_BLUETOOTH_SCAN:-} ]]; then
COMPREPLY+=( $( compgen -W "$( hcitool scan | \
awk '/^\t/{print $1}' )" -- "$cur" ) )
fi
@ -51,7 +51,7 @@ _hcitool()
local arg
_get_first_arg
if [ -z $arg ]; then
if [[ -z $arg ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
else
@ -63,7 +63,7 @@ _hcitool()
case $arg in
name|info|dc|rssi|lq|afh|auth|key|clkoff|lst)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
fi
;;
@ -72,14 +72,14 @@ _hcitool()
COMPREPLY=( $( compgen -W '--role --pkt-type' -- "$cur" ) )
else
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
fi
fi
;;
sr)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
else
COMPREPLY=( $( compgen -W 'master slave' -- "$cur" ) )
@ -87,7 +87,7 @@ _hcitool()
;;
cpt)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
else
_bluetooth_packet_types
@ -95,7 +95,7 @@ _hcitool()
;;
tpl|enc|clock)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
else
COMPREPLY=( $( compgen -W '0 1' -- "$cur" ) )
@ -122,7 +122,7 @@ _sdptool()
local arg
_get_first_arg
if [ -z $arg ]; then
if [[ -z $arg ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
else
@ -206,7 +206,7 @@ _rfcomm()
local arg
_get_first_arg
if [ -z $arg ]; then
if [[ -z $arg ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
else
@ -215,12 +215,12 @@ _rfcomm()
fi
else
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_devices
else
case $arg in
connect|bind)
if [ $args -eq 3 ]; then
if [[ $args -eq 3 ]]; then
_bluetooth_adresses
fi
;;
@ -245,7 +245,7 @@ _ciptool()
local arg
_get_first_arg
if [ -z $arg ]; then
if [[ -z $arg ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
else
@ -256,7 +256,7 @@ _ciptool()
case $arg in
connect|release|loopback)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
fi
;;
@ -302,7 +302,7 @@ _hciconfig()
local arg
_get_first_arg
if [ -z $arg ]; then
if [[ -z $arg ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --all' -- "$cur" ) )
else
@ -318,20 +318,20 @@ _hciconfig()
case $arg in
putkey|delkey)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_adresses
fi
;;
lm)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
COMPREPLY=( $( compgen -W 'MASTER \
SLAVE NONE ACCEPT' -- "$cur" ) )
fi
;;
ptype)
_count_args
if [ $args -eq 2 ]; then
if [[ $args -eq 2 ]]; then
_bluetooth_packet_types
fi
;;

View File

@ -7,7 +7,7 @@ _ifupdown()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
_configured_interfaces
COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") )
fi

View File

@ -45,12 +45,12 @@ _info()
if [[ $INFOPATH == *: ]]; then
infopath=${INFOPATH}${infopath}
elif [ ${INFOPATH:+set} ]; then
elif [[ ${INFOPATH:+set} ]]; then
infopath=$INFOPATH
fi
infopath=$infopath:
if [ -n "$cur" ]; then
if [[ -n $cur ]]; then
infopath="${infopath//://$cur* }"
else
infopath="${infopath//:// }"
@ -62,9 +62,7 @@ _info()
COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
# weed out info dir file
for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
if [ "${COMPREPLY[$i]}" == 'dir' ]; then
unset COMPREPLY[$i]
fi
[[ ${COMPREPLY[$i]} == dir ]] && unset COMPREPLY[$i]
done
# strip suffix from info pages
COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2|xz|lzma)} )

View File

@ -9,8 +9,8 @@ _invoke_rc_d()
local sysvdir services options valid_options
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d
[[ -d /etc/rc.d/init.d ]] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d
services=( $( printf '%s ' $sysvdir/!(README*|*.sh|$_backup_glob) ) )
services=( ${services[@]#$sysvdir/} )
@ -24,7 +24,7 @@ _invoke_rc_d()
| sort | uniq -u \
) )
COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- "$cur" ) )
elif [ -x $sysvdir/$prev ]; then
elif [[ -x $sysvdir/$prev ]]; then
COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
-ne "s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
$sysvdir/$prev`' -- "$cur" ) )

View File

@ -71,11 +71,11 @@ _ipmitool()
for (( i=1; i < ${#words[@]}-1; i++ )); do
[[ -n $cmd ]] && subcmd=${words[i]} && break
for c in ${cmds[@]}; do
[ ${words[i]} = $c ] && cmd=$c && break
[[ ${words[i]} == $c ]] && cmd=$c && break
done
done
if [ -z "$cmd" ]; then
if [[ -z $cmd ]]; then
COMPREPLY=( $( compgen -W '${cmds[@]}' -- "$cur" ) )
return 0
fi
@ -100,11 +100,11 @@ _ipmitool()
print|set)
;;
alert)
[ "$prev" = alert ] && \
[[ $prev == alert ]] && \
COMPREPLY=( $( compgen -W 'print set' -- "$cur" ) )
;;
stats)
[ "$prev" = stats ] && \
[[ $prev == stats ]] && \
COMPREPLY=( $( compgen -W 'print set' -- "$cur" ) )
;;
*)
@ -161,7 +161,7 @@ _ipmitool()
_filedir
;;
time)
[ "$prev" = time ] && \
[[ $prev == time ]] && \
COMPREPLY=( $( compgen -W 'get set' -- "$cur" ) )
;;
*)
@ -176,7 +176,7 @@ _ipmitool()
summary|list|disable|enable|priv|test)
;;
set)
[ "$prev" = set ] && \
[[ $prev == set ]] && \
COMPREPLY=( $( compgen -W 'name password' -- "$cur" ) )
;;
*)
@ -187,7 +187,7 @@ _ipmitool()
;;
set)
[ "$prev" = set ] && \
[[ $prev == set ]] && \
COMPREPLY=( $( compgen -W 'hostname username password privlvl
authtype localaddr targetaddr port csv verbose' \
-- "$cur" ) )

View File

@ -18,7 +18,7 @@ _ipsec_freeswan()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look manual \
pluto ranbits rsasigkey setup showdefaults showhostkey spi spigrp \
tncfg whack' -- "$cur" ) )
@ -55,7 +55,7 @@ _ipsec_strongswan()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'down irdumm leases listaacerts listacerts \
listalgs listall listcacerts listcainfos listcards listcerts \
listcrls listgroups listocsp listocspcerts listpubkeys openac pki

View File

@ -29,12 +29,12 @@ _iptables()
`iptables $table -nL | sed -ne "$chain" \
-e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \
"$cur" ) )
elif [ "$table" = "-t nat" ]; then
elif [[ $table == "-t nat" ]]; then
COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
MIRROR SNAT DNAT MASQUERADE `iptables $table -nL | \
sed -ne "$chain" -e "s/OUTPUT|PREROUTING|POSTROUTING//"`' \
-- "$cur" ) )
elif [ "$table" = "-t mangle" ]; then
elif [[ $table == "-t mangle" ]]; then
COMPREPLY=( $( compgen -W 'ACCEPT DROP LOG ULOG REJECT \
MARK TOS `iptables $table -nL | sed -ne "$chain" \
-e "s/INPUT|OUTPUT|FORWARD|PREROUTING|POSTROUTING//"`' -- \

View File

@ -6,7 +6,7 @@ _isql()
local cur prev words cword
_init_completion || return
[ -f "$ODBCINI" ] \
[[ -f $ODBCINI ]] \
&& COMPREPLY=( $( command grep \\["$cur" "$ODBCINI" | tr -d \\[\\] ) )
} &&
complete -F _isql isql

View File

@ -13,7 +13,7 @@ _iwconfig()
;;
essid)
COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
if [[ -n ${COMP_IWLIST_SCAN:-} ]]; then
COMPREPLY+=( $( compgen -W \
"$( iwlist ${words[1]} scan | \
awk -F'\"' '/ESSID/ {print $2}' )" -- "$cur" ) )
@ -37,7 +37,7 @@ _iwconfig()
;;
ap)
COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
if [[ -n ${COMP_IWLIST_SCAN:-} ]]; then
COMPREPLY+=( $( compgen -W \
"$( iwlist ${words[1]} scan | \
awk -F ': ' '/Address/ {print $2}' )" -- "$cur" ) )
@ -73,7 +73,7 @@ _iwconfig()
;;
esac
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else

View File

@ -5,7 +5,7 @@ _iwlist()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else

View File

@ -16,7 +16,7 @@ _iwpriv()
;;
esac
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else

View File

@ -5,7 +5,7 @@ _iwspy()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else

View File

@ -21,10 +21,10 @@ _java_find_classpath()
done
# default to environment
[ -z "$classpath" ] && classpath=$CLASSPATH
[[ -z $classpath ]] && classpath=$CLASSPATH
# default to current directory
[ -z "$classpath" ] && classpath=.
[[ -z $classpath ]] && classpath=.
}
# exact sourcepath determination
@ -41,7 +41,7 @@ _java_find_sourcepath()
done
# default to classpath
if [ -z "$sourcepath" ]; then
if [[ -z $sourcepath ]]; then
local classpath
_java_find_classpath
sourcepath=$classpath
@ -69,7 +69,7 @@ _java_classes()
command grep '^[^$]*\.class$' ) )
fi
elif [ -d $i ]; then
elif [[ -d $i ]]; then
COMPREPLY+=(
$( compgen -d -- "$i/$cur" | sed -e "s|^$i/\(.*\)|\1.|" )
$( compgen -f -X '!*.class' -- "$i/$cur" | \
@ -101,7 +101,7 @@ _java_packages()
cur=${cur//.//}
# parse each sourcepath element for packages
for i in ${sourcepath//:/ }; do
if [ -d $i ]; then
if [[ -d $i ]]; then
COMPREPLY+=( $( command ls -F -d $i/$cur* 2>/dev/null | \
sed -e 's|^'$i'/||' ) )
fi

View File

@ -8,7 +8,7 @@ _kldload()
_init_completion || return
local moddir=/modules/
[ -d $moddir ] || moddir=/boot/kernel/
[[ -d $moddir ]] || moddir=/boot/kernel/
compopt -o filenames
COMPREPLY=( $( compgen -f "$moddir$cur" ) )

View File

@ -18,7 +18,7 @@ _links()
-source -version -help' -- "$cur" ) )
;;
*)
if [ -r ~/.links/links.his ]; then
if [[ -r ~/.links/links.his ]]; then
COMPREPLY=( $( compgen -W '$( < ~/.links/links.his )' \
-- "$cur" ) )
fi

View File

@ -314,7 +314,7 @@ _vgcreate()
--verbose --version' -- "$cur" ) )
else
_args
if [ $args -eq 0 ]; then
if [[ $args -eq 0 ]]; then
_volumegroups
else
_physicalvolumes
@ -373,7 +373,7 @@ _vgreduce()
else
_args
if [ $args -eq 0 ]; then
if [[ $args -eq 0 ]]; then
_volumegroups
else
_physicalvolumes
@ -402,7 +402,7 @@ _vgextend()
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_args
if [ $args -eq 0 ]; then
if [[ $args -eq 0 ]]; then
_volumegroups
else
_physicalvolumes
@ -686,7 +686,7 @@ _lvcreate()
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_args
if [ $args -eq 0 ]; then
if [[ $args -eq 0 ]]; then
_volumegroups
else
_physicalvolumes
@ -779,7 +779,7 @@ _lvresize()
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_args
if [ $args -eq 0 ]; then
if [[ $args -eq 0 ]]; then
_logicalvolumes
else
_physicalvolumes
@ -808,7 +808,7 @@ _lvextend()
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_args
if [ $args -eq 0 ]; then
if [[ $args -eq 0 ]]; then
_logicalvolumes
else
_physicalvolumes
@ -822,7 +822,7 @@ _lvm()
local cur prev words cword
_init_completion || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'dumpconfig help lvchange \
lvcreate lvdisplay lvextend lvmchange \
lvmdiskscan lvmsadc lvmsar lvreduce \

View File

@ -58,8 +58,8 @@ _make()
fi
done
[ -n "$makef" ] && makef="-f ${makef}"
[ -n "$makef_dir" ] && makef_dir="-C ${makef_dir}"
[[ -n $makef ]] && makef="-f ${makef}"
[[ -n $makef_dir ]] && makef_dir="-C ${makef_dir}"
COMPREPLY=( $( compgen -W "$( make -qp $makef $makef_dir 2>/dev/null | \
awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ \

View File

@ -63,7 +63,7 @@ _man()
manpath=$MANPATH
fi
if [ -z "$manpath" ]; then
if [[ -z $manpath ]]; then
COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0
fi
@ -72,7 +72,7 @@ _man()
[[ "$prev" == $mansect ]] && sect=$prev || sect='*'
manpath=$manpath:
if [ -n "$cur" ]; then
if [[ -n $cur ]]; then
manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
else
manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"

View File

@ -29,11 +29,10 @@ _minicom()
return 0
else
local confdir
[ -n "$( command ls /etc/minirc.* 2>/dev/null)" ] \
&& confdir=/etc
[ -n "$( command ls /etc/minicom/minirc.* 2>/dev/null)" ] \
[[ -n $( command ls /etc/minirc.* 2>/dev/null ) ]] && confdir=/etc
[[ -n $( command ls /etc/minicom/minirc.* 2>/dev/null ) ]] \
&& confdir=/etc/minicom
if [ -n "$confdir" ]; then
if [[ -n $confdir ]]; then
COMPREPLY=( $( compgen -W '$( printf "%s\n" $confdir/minirc.* | \
sed -e "s|$confdir/minirc.||")' -- "$cur" ) )
return 0

View File

@ -92,7 +92,7 @@ _mount()
if [[ "$cur" == *:* ]]; then
for sm in "$(type -P showmount)" {,/usr}/{,s}bin/showmount; do
[ -x "$sm" ] || continue
[[ -x $sm ]] || continue
COMPREPLY=( $( compgen -W "$( "$sm" -e ${cur%%:*} | \
awk 'NR>1 {print $1}' )" -- "${cur#*:}" ) )
return 0
@ -102,24 +102,24 @@ _mount()
if [[ "$cur" == //* ]]; then
host=${cur#//}
host=${host%%/*}
if [ -n "$host" ]; then
if [[ -n $host ]]; then
COMPREPLY=( $( compgen -P "//$host" -W \
"$( smbclient -d 0 -NL $host 2>/dev/null |
sed -ne '/^['"$'\t '"']*Sharename/,/^$/p' |
sed -ne '3,$s|^[^A-Za-z]*\([^'"$'\t '"']*\).*$|/\1|p' )" \
-- "${cur#//$host}" ) )
fi
elif [ -r /etc/vfstab ]; then
elif [[ -r /etc/vfstab ]]; then
# Solaris
COMPREPLY=( $( compgen -W "$( awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' /etc/vfstab )" -- "$cur" ) )
elif [ ! -e /etc/fstab ]; then
elif [[ ! -e /etc/fstab ]]; then
# probably Cygwin
COMPREPLY=( $( compgen -W "$( mount | awk '! /^[ \t]*#/ {if ($3 ~ /\//) print $3}' )" -- "$cur" ) )
else
# probably Linux
if [ "$prev" = -L ]; then
if [[ $prev == -L ]]; then
_linux_fstab -L < /etc/fstab
elif [ "$prev" = -U ]; then
elif [[ $prev == -U ]]; then
COMPREPLY=( $( compgen -W '$(sed -ne "s/^[[:space:]]*UUID=\([^[:space:]]*\).*/\1/p" /etc/fstab )' -- "$cur" ) )
else
_linux_fstab < /etc/fstab

View File

@ -30,7 +30,7 @@ _mplayer()
return 0
;;
-font|-subfont)
if [ "$prev" = -font ]; then
if [[ $prev == -font ]]; then
_filedir '@(desc|ttf)'
else
_filedir ttf
@ -67,7 +67,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 [[ -n $MPLAYER_SKINS_DIR ]]; then
dirs=($MPLAYER_SKINS_DIR)
else
dirs=(/usr/share/mplayer/skins /usr/local/share/mplayer/skins)

View File

@ -20,7 +20,7 @@ _mtx()
drives=${drives//:Full}
drives=${drives//:Empty}
if [ $cword -gt 1 ]; then
if [[ $cword -gt 1 ]]; then
case $prev in
load)
COMPREPLY=( $( compgen -W "$tapes" -- "$cur" ) )

View File

@ -21,23 +21,23 @@ _muttrc()
{
# Search COMP_WORDS for '-F muttrc' or '-Fmuttrc' argument
set -- "${words[@]}"
while [ $# -gt 0 ]; do
while [[ $# -gt 0 ]]; do
if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then
if [[ ${#1} -gt 2 ]]; then
muttrc="$(dequote "${1:2}")"
else
shift
[ "$1" ] && muttrc="$(dequote "$1")"
[[ $1 ]] && muttrc="$(dequote "$1")"
fi
break
fi
shift
done
if [ -z "$muttrc" ]; then
if [ -f ~/.${muttcmd}rc ]; then
if [[ -z $muttrc ]]; then
if [[ -f ~/.${muttcmd}rc ]]; then
muttrc="~/.${muttcmd}rc"
elif [ -f ~/.${muttcmd}/${muttcmd}rc ]; then
elif [[ -f ~/.${muttcmd}/${muttcmd}rc ]]; then
muttrc="~/.${muttcmd}/${muttcmd}rc"
fi
fi
@ -77,7 +77,7 @@ _muttaliases()
local -a conffiles aliases
muttrc=$(_muttrc)
[ -z "$muttrc" ] && return 0
[[ -z $muttrc ]] && return 0
conffiles=( $(eval _muttconffiles $muttrc $muttrc) )
aliases=( $( sed -n 's|^alias[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*$|\1|p' \
@ -125,10 +125,10 @@ _muttfiledir()
COMPREPLY=( $( compgen -f -- "$folder/${cur:1}" ) )
COMPREPLY=( ${COMPREPLY[@]#$folder/} )
return 0
elif [ "$cur" == !* ]; then
elif [[ $cur == !* ]]; then
spoolfile="$( $muttcmd -F "$muttrc" -Q spoolfile 2>/dev/null | \
sed -e 's|^spoolfile=\"\(.*\)\"$|\1|' )"
[ ! -z "$spoolfile" ] && eval cur="${cur/^!/$spoolfile}"
[[ ! -z $spoolfile ]] && eval cur="${cur/^!/$spoolfile}"
fi
_filedir

View File

@ -20,7 +20,7 @@ _mysql()
return 0
;;
--default-character-set)
[ -d /usr/share/mysql/charsets ] && \
[[ -d /usr/share/mysql/charsets ]] && \
COMPREPLY=( $( compgen -W "$(command ls /usr/share/mysql/charsets|sed -e '/^\(README\|Index\.xml\)$/d' -e 's/.xml$//') utf8" -- "$cur" ) )
return 0
;;

View File

@ -13,14 +13,14 @@ _openssl_sections()
done
# if no config given, check some usual default locations
if [ -z "$config" ]; then
if [[ -z $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
[[ -f $f ]] && config=$f && break
done
fi
[ ! -f "$config" ] && return 0
[[ ! -f $config ]] && return 0
COMPREPLY=( $( compgen -W "$( awk '/\[.*\]/ {print $2}' $config )" \
-- "$cur" ) )
@ -48,7 +48,7 @@ _openssl()
rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb rc4 \
rc4-40'
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
else
command=${words[1]}

View File

@ -14,9 +14,9 @@ _p4()
uresource uxbinary xbinary xltext xtempobj xtext \
text binary resource"
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W "$p4commands" -- "$cur" ) )
elif [ $cword -eq 2 ]; then
elif [[ $cword -eq 2 ]]; then
case $prev in
help)
COMPREPLY=( $( compgen -W "simple commands \
@ -29,7 +29,7 @@ _p4()
*)
;;
esac
elif [ $cword -gt 2 ]; then
elif [[ $cword -gt 2 ]]; then
case $prev in
-t)
case ${words[$cword-2]} in

View File

@ -40,7 +40,7 @@ _povray()
*.ini\[|*.ini\[*[^]]) # sections in .ini files
cur="${povcur#*\[}"
pfx="${povcur%\["$cur"}" # prefix == filename
[ -r "$pfx" ] || return 0
[[ -r $pfx ]] || return 0
COMPREPLY=( $(sed -e 's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/' \
-e 't' -e 'd' -- "$pfx") )
# to prevent [bar] expand to nothing. can be done more easily?

View File

@ -13,7 +13,7 @@ _pg_users()
# -w was introduced in 8.4, https://launchpad.net/bugs/164772
COMPREPLY=( $( compgen -W "$( psql -Atqwc 'select usename from pg_user' \
template1 2>/dev/null )" -- "$cur" ) )
[ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- "$cur" ) )
[[ ${#COMPREPLY[@]} -eq 0 ]] && COMPREPLY=( $( compgen -u -- "$cur" ) )
}
# createdb(1) completion

View File

@ -2,7 +2,7 @@
_puppet_logdest()
{
if [ -z "$cur" ]; then
if [[ -z $cur ]]; then
COMPREPLY=( $( compgen -W 'syslog console /' -- "$cur" ) )
else
COMPREPLY=( $( compgen -W 'syslog console' -- "$cur" ) )

View File

@ -5,7 +5,7 @@ _qdbus()
local cur prev words cword
_init_completion || return
[ -n "$cur" ] && unset words[${#words[@]}-1]
[[ -n $cur ]] && unset words[${#words[@]}-1]
COMPREPLY=( $( compgen -W '$( command ${words[@]} 2>/dev/null | \
sed s/\(.*\)// )' -- "$cur" ) )
} &&

View File

@ -11,7 +11,7 @@ _rcs()
dir=${cur%/*}
# deal with relative directory
[ "$file" = "$dir" ] && dir=.
[[ $file == $dir ]] && dir=.
COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) )

View File

@ -5,10 +5,10 @@ ri_get_methods()
{
local regex
if [ "$ri_version" = integrated ]; then
if [ -z "$separator" ]; then
if [[ $ri_version == integrated ]]; then
if [[ -z $separator ]]; then
regex="(Instance|Class)"
elif [ "$separator" = "#" ]; then
elif [[ $separator == "#" ]]; then
regex=Instance
else
regex=Class
@ -45,7 +45,7 @@ _ri()
# -W0 is required here to stop warnings from older versions of ri
# from being captured when used with Ruby 1.8.1 and later
ri_version="$(ruby -W0 $ri_path -v 2>&1)" || ri_version=integrated
[ "$ri_version" != "${ri_version%200*}" ] && ri_version=integrated
[[ $ri_version != ${ri_version%200*} ]] && ri_version=integrated
# need to also split on commas
IFS=$', \n\t'
@ -60,11 +60,11 @@ _ri()
return 0
fi
if [ "$ri_version" = integrated ]; then
if [[ $ri_version == integrated ]]; then
# integrated ri from Ruby 1.9
classes=( $( ri -c 2>/dev/null | ruby -ne 'if /^\s*$/..$stdin.eof then \
if /, [A-Z]+/ then print; end; end' 2>/dev/null ) )
elif [ "$ri_version" = "ri 1.8a" ]; then
elif [[ $ri_version == "ri 1.8a" ]]; then
classes=( $( ruby -W0 $ri_path | \
ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \
if /^ .*[A-Z]/ then print; end; end' ))

View File

@ -7,7 +7,7 @@ _route()
local cur prev words cword
_init_completion || return
if [ "$prev" = dev ]; then
if [[ $prev == dev ]]; then
_available_interfaces
return 0
fi
@ -18,7 +18,7 @@ _route()
dyn reinstate dev default gw; do
found=false
for (( i=1; i < ${#words[@]}-1; i++ )); do
[ "${words[i]}" = "$opt" ] && found=true && break
[[ ${words[i]} == $opt ]] && found=true && break
done
$found || COMPREPLY[${#COMPREPLY[@]}]="$opt"
done

View File

@ -11,7 +11,7 @@ _rpcdebug_flags()
fi
done
if [ -n "$module" ]; then
if [[ -n $module ]]; then
COMPREPLY=( $( compgen -W "$( rpcdebug -vh 2>&1 | \
sed -ne 's/^'$module'[[:space:]]\{1,\}//p' )" -- "$cur" ) )
fi

View File

@ -48,7 +48,7 @@ _rpm()
local cur prev words cword split
_init_completion -s || return
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
# first parameter on line
case $cur in
--*)

View File

@ -5,7 +5,7 @@ _rrdtool ()
local cur prev words cword
_init_completion || return
if [ ${#words[@]} -eq 2 ]; then
if [[ ${#words[@]} -eq 2 ]]; then
COMPREPLY=( $( compgen -W 'create update updatev graph dump restore \
last lastupdate first info fetch tune resize xport' -- "$cur" ) )
else

View File

@ -74,7 +74,7 @@ _rsync()
break
fi
done
[ "$shell" = ssh ] && _xfunc ssh _scp_remote_files
[[ $shell == ssh ]] && _xfunc ssh _scp_remote_files
;;
*)
_known_hosts_real -c -a "$cur"

View File

@ -45,7 +45,7 @@ _sbopkg()
fi
done
if [ ! -r "$config" ]; then
if [[ ! -r $config ]]; then
return 0
fi
@ -63,7 +63,7 @@ _sbopkg()
esac
done
if [ ! -r "$REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT" ]; then
if [[ ! -r $REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT ]]; then
return 0
fi
COMPREPLY=( $( sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p}"\

View File

@ -40,7 +40,7 @@ _sitecopy()
;;
esac
if [ -r ~/.sitecopyrc ]; then
if [[ -r ~/.sitecopyrc ]]; then
COMPREPLY=( $( compgen -W "$($1 -v | \
command sed -n '/^Site:/s/Site: //p')" -- "$cur" ) )
fi

View File

@ -43,7 +43,7 @@ _slackpkg()
local confdir="/etc/slackpkg"
local config="$confdir/slackpkg.conf"
if [ ! -r "$config" ]; then
if [[ ! -r $config ]]; then
return 0
fi
. "$config"
@ -62,7 +62,7 @@ _slackpkg()
return 0
;;
install-template|remove-template)
if [ -e "$confdir/templates" ]; then
if [[ -e $confdir/templates ]]; then
COMPREPLY=( $( cd "$confdir/templates"; \
compgen -f -X "!*.template" -- "$cur" ) )
COMPREPLY=( ${COMPREPLY[@]%.template} )

View File

@ -48,7 +48,7 @@ _slapt_get()
break
fi
done
if [ ! -r "$config" ]; then
if [[ ! -r $config ]]; then
return
fi

View File

@ -30,7 +30,7 @@ _slapt_src()
break
fi
done
if [ "$t" != "all" ]; then
if [[ $t != all ]]; then
return 0
fi
@ -42,7 +42,7 @@ _slapt_src()
break
fi
done
if [ ! -r "$config" ]; then
if [[ ! -r $config ]]; then
return 0
fi

View File

@ -7,14 +7,14 @@ _samba_resolve_order()
_samba_domains()
{
if [ -n "${COMP_SAMBA_SCAN:-}" ]; then
if [[ -n ${COMP_SAMBA_SCAN:-} ]]; then
COMPREPLY=( $( compgen -W '$( smbtree -N -D )' -- "$cur" ) )
fi
}
_samba_hosts()
{
if [ -n "${COMP_SAMBA_SCAN:-}" ]; then
if [[ -n ${COMP_SAMBA_SCAN:-} ]]; then
COMPREPLY=( $( compgen -W "$( smbtree -N -S | \
sed -ne 's/^[[:space:]]*\\\\*\([^[:space:]]*\).*/\1/p' \
)" -- $cur ) )

View File

@ -157,20 +157,20 @@ _ssh()
else
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${words[@]}"
while [ $# -gt 0 ]; do
while [[ $# -gt 0 ]]; do
if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then
if [[ ${#1} -gt 2 ]]; then
configfile="$(dequote "${1:2}")"
else
shift
[ "$1" ] && configfile="$(dequote "$1")"
[[ $1 ]] && configfile="$(dequote "$1")"
fi
break
fi
shift
done
_known_hosts_real -a -F "$configfile" "$cur"
if [ $cword -ne 1 ]; then
if [[ $cword -ne 1 ]]; then
compopt -o filenames
COMPREPLY+=( $( compgen -c -- "$cur" ) )
fi
@ -220,13 +220,13 @@ _sftp()
else
# Search COMP_WORDS for '-F configfile' argument
set -- "${words[@]}"
while [ $# -gt 0 ]; do
while [[ $# -gt 0 ]]; do
if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then
if [[ ${#1} -gt 2 ]]; then
configfile="$(dequote "${1:2}")"
else
shift
[ "$1" ] && configfile="$(dequote "$1")"
[[ $1 ]] && configfile="$(dequote "$1")"
fi
break
fi
@ -258,12 +258,12 @@ _scp_remote_files()
path=$( sed -e 's/\\\\\\\('$_scp_path_esc'\)/\\\1/g' <<<"$path" )
# default to home dir of specified user on remote host
if [ -z "$path" ]; then
if [[ -z $path ]]; then
path=$(ssh -o 'Batchmode yes' $userhost pwd 2>/dev/null)
fi
local files
if [ "$1" = -d ] ; then
if [[ $1 == -d ]]; then
# escape problematic characters; remove non-dirs
files=$( ssh -o 'Batchmode yes' $userhost \
command ls -aF1d "$path*" 2>/dev/null | \
@ -288,7 +288,7 @@ _scp_local_files()
local IFS=$'\n'
local dirsonly=false
if [ "$1" = -d ]; then
if [[ $1 == -d ]]; then
dirsonly=true
shift
fi
@ -350,13 +350,13 @@ _scp()
else
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${words[@]}"
while [ $# -gt 0 ]; do
while [[ $# -gt 0 ]]; do
if [[ $1 == -F* ]]; then
if [ ${#1} -gt 2 ]; then
if [[ ${#1} -gt 2 ]]; then
configfile="$(dequote "${1:2}")"
else
shift
[ "$1" ] && configfile="$(dequote "$1")"
[[ $1 ]] && configfile="$(dequote "$1")"
fi
break
fi

View File

@ -21,7 +21,7 @@ _strace()
break
done
if [ $offset -gt 0 ]; then
if [[ $offset -gt 0 ]]; then
_command_offset $offset
else

View File

@ -7,7 +7,7 @@ _tar()
local ext regex tar untar
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'c t x u r d A' -- "$cur" ) )
return 0
fi

View File

@ -5,10 +5,10 @@ _unace()
local cur prev words cword
_init_completion || return
if [[ "$cur" == -* ]] ; then
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-c -c- -f -f- -o -o- -p -y -y-' -- "$cur" ) )
else
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'e l t v x' -- "$cur" ) )
else
_filedir ace

View File

@ -5,12 +5,12 @@ _unrar()
local cur prev words cword
_init_completion || return
if [[ "$cur" == -* ]] ; then
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-ad -ap -av- -c- -cfg- -cl -cu \
-dh -ep -f -idp -ierr -inul -kb -o+ -o- -ow -p -p- -r -ta \
-tb -tn -to -u -v -ver -vp -x -x@ -y' -- "$cur" ) )
else
if [ $cword -eq 1 ]; then
if [[ $cword -eq 1 ]]; then
COMPREPLY=( $( compgen -W 'e l lb lt p t v vb vt x' -- "$cur" ) )
else
_filedir rar

View File

@ -5,7 +5,7 @@ _installed_alternatives()
local admindir
# find the admin dir
for i in alternatives dpkg/alternatives rpm/alternatives; do
[ -d /var/lib/$i ] && admindir=/var/lib/$i && break
[[ -d /var/lib/$i ]] && admindir=/var/lib/$i && break
done
for (( i=1; i < cword; i++ )); do
if [[ "${words[i]}" == --admindir ]]; then

View File

@ -9,8 +9,8 @@ _update_rc_d()
local sysvdir services options valid_options
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d
[[ -d /etc/rc.d/init.d ]] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d
services=( $(printf '%s ' $sysvdir/!(README*|*.sh|$_backup_glob)) )
services=( ${services[@]#$sysvdir/} )

View File

@ -67,8 +67,8 @@ _cdrecord()
-copy -nocopy -scms isrc= index= padsize= pregap= tsize= )
# look if previous was either a file or a track option
track_mode=0
if [ $cword -gt 1 ]; then
if [ -f "$prev" ]; then
if [[ $cword -gt 1 ]]; then
if [[ -f $prev ]]; then
track_mode=1
else
for (( i=0; i < ${#track_options[@]}; i++ )); do
@ -85,7 +85,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 -eq 0 ]; then
if [[ $track_mode -eq 0 ]]; then
COMPREPLY+=( $( compgen -W '${generic_options[@]}' -- "$cur" ) )
fi
[[ $COMPREPLY == *= ]] && compopt -o nospace

View File

@ -6,19 +6,19 @@ _wtf()
local cur prev words cword
_init_completion || return
[ "$prev" = -f ] && _filedir && return 0
[[ "$cur" == -* ]] && COMPREPLY=( -f ) && return 0
[[ $prev == -f ]] && _filedir && return 0
[[ $cur == -* ]] && COMPREPLY=( -f ) && return 0
local db
set -- "${words[@]}"
while [ $# -gt 0 ]; do
if [ "$1" = -f ]; then
while [[ $# -gt 0 ]]; do
if [[ $1 == -f ]]; then
shift ; db=$1 ; break
fi
shift
done
[ -z $db ] && db=${ACRONYMDB:-/usr/share/misc/acronyms*}
[[ -z $db ]] && db=${ACRONYMDB:-/usr/share/misc/acronyms*}
COMPREPLY=( $( compgen -W "$( cut -f 1 -s $db ) -f" -- "${cur^^}" ) )
} &&

View File

@ -29,13 +29,8 @@ doesn't confuse editors as bad as the latter, and is concise enough.
&#91;[ ]] vs [ ]
----------------
Use [[ ]] instead of [ ] when testing multiple conditions. [ ] is fine
for single conditions where the syntax works. Rationale: [[ ]] has
short circuit behavior within one test containing multiple conditions
separated by && or ||, while [ ] with -a or -o does not. Thus it can
be more efficient in some cases and may reduce need for nesting
conditions, and it's cleaner to write for example [[ ... && ... ]]
than [ ... ] && [ ... ], and in general [[ ]] has more features.
Always use [[ ]] instead of [ ]. Rationale: the former is less error
prone, more featureful, and slightly faster.
Line wrapping
-------------