diff options
| author | Ville Skyttä <ville.skytta@iki.fi> | 2011-11-09 23:28:11 +0200 |
|---|---|---|
| committer | Ville Skyttä <ville.skytta@iki.fi> | 2011-11-09 23:28:11 +0200 |
| commit | 3b8ef29ef34d7ea009faca1a35023b454ab2dce1 (patch) | |
| tree | 0924cf066806adb3aa7d7b9dcd7f35303292f897 /bash_completion | |
| parent | 1d48f79b9c6a9b9e9044741d300ded461d765135 (diff) | |
| download | bash-completion-3b8ef29ef34d7ea009faca1a35023b454ab2dce1.tar.gz | |
Cleanups: Use [[ instead of [.
Diffstat (limited to 'bash_completion')
| -rw-r--r-- | bash_completion | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/bash_completion b/bash_completion index cb4f0bfd..1782bc6d 100644 --- a/bash_completion +++ b/bash_completion @@ -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[@]}" ) } |
