diff options
author | Ville Skyttä <ville.skytta@iki.fi> | 2011-11-09 22:24:39 +0200 |
---|---|---|
committer | Ville Skyttä <ville.skytta@iki.fi> | 2011-11-09 22:46:21 +0200 |
commit | 1d48f79b9c6a9b9e9044741d300ded461d765135 (patch) | |
tree | eddb695374079fa285914a54a428e1b06a61cb2a | |
parent | d54db3507dc79624ea5db1a031fac677d4c0dabe (diff) | |
download | bash-completion-1d48f79b9c6a9b9e9044741d300ded461d765135.tar.gz |
Cleanups: use usual globs instead of substring matches or substitutions.
-rw-r--r-- | bash_completion | 17 | ||||
-rw-r--r-- | completions/info | 2 | ||||
-rw-r--r-- | completions/mutt | 5 | ||||
-rw-r--r-- | completions/ssh | 6 |
4 files changed, 13 insertions, 17 deletions
diff --git a/bash_completion b/bash_completion index 73ae920d..cb4f0bfd 100644 --- a/bash_completion +++ b/bash_completion @@ -256,14 +256,11 @@ __reassemble_comp_words_by_ref() # empty and is word made up of just word separator characters to # be excluded and is current word not preceded by whitespace in # original line? - while [[ $i -gt 0 && ${COMP_WORDS[$i]} && - ${COMP_WORDS[$i]//[^$exclude]} == ${COMP_WORDS[$i]} - ]]; do + while [[ $i -gt 0 && ${COMP_WORDS[$i]} == +([$exclude]) ]]; do # Is word separator not preceded by whitespace in original line # and are we not going to append to word 0 (the command # itself), then append to current word. - [[ ${line:0:1} != ' ' && ${line:0:1} != $'\t' ]] && - (( j >= 2 )) && ((j--)) + [[ $line != [$' \t']* ]] && (( j >= 2 )) && ((j--)) # Append word separator to current or new word ref="$2[$j]" eval $2[$j]=\${!ref}\${COMP_WORDS[i]} @@ -273,7 +270,7 @@ __reassemble_comp_words_by_ref() line=${line#*"${COMP_WORDS[$i]}"} # Start new word if word separator in original line is # followed by whitespace. - [[ ${line:0:1} == ' ' || ${line:0:1} == $'\t' ]] && ((j++)) + [[ $line == [$' \t']* ]] && ((j++)) # Indicate next word if available, else end *both* while and # for loop (( $i < ${#COMP_WORDS[@]} - 1)) && ((i++)) || break 2 @@ -537,7 +534,7 @@ __ltrim_colon_completions() # @param $2 Name of variable to return result to _quote_readline_by_ref() { - if [[ ${1:0:1} == "'" ]]; then + if [[ $1 == \'* ]]; then # Leave out first character printf -v $2 %s "${1:1}" else @@ -547,7 +544,7 @@ _quote_readline_by_ref() # If result becomes quoted like this: $'string', re-evaluate in order to # drop the additional quoting. See also: http://www.mail-archive.com/ # bash-completion-devel@lists.alioth.debian.org/msg01942.html - [[ ${!2:0:1} == '$' ]] && eval $2=${!2} + [[ ${!2} == \$* ]] && eval $2=${!2} } # _quote_readline_by_ref() @@ -939,9 +936,9 @@ _tilde() __expand_tilde_by_ref() { # Does $1 start with tilde (~)? - if [ "${!1:0:1}" = "~" ]; then + if [[ ${!1} == ~* ]]; then # Does $1 contain slash (/)? - if [ "${!1}" != "${!1//\/}" ]; then + if [[ ${!1} == */* ]]; then # Yes, $1 contains slash; # 1: Remove * including and after first slash (/), i.e. "~a/b" # becomes "~a". Double quotes allow eval. diff --git a/completions/info b/completions/info index aa16be69..71865809 100644 --- a/completions/info +++ b/completions/info @@ -43,7 +43,7 @@ _info() local i infopath=/usr/share/info - if [ "${INFOPATH: -1:1}" == ':' ]; then + if [[ $INFOPATH == *: ]]; then infopath=${INFOPATH}${infopath} elif [ ${INFOPATH:+set} ]; then infopath=$INFOPATH diff --git a/completions/mutt b/completions/mutt index 70699a15..f1fd6ff7 100644 --- a/completions/mutt +++ b/completions/mutt @@ -22,7 +22,7 @@ _muttrc() # Search COMP_WORDS for '-F muttrc' or '-Fmuttrc' argument set -- "${words[@]}" while [ $# -gt 0 ]; do - if [ "${1:0:2}" = -F ]; then + if [[ $1 == -F* ]]; then if [ ${#1} -gt 2 ]; then muttrc="$(dequote "${1:2}")" else @@ -60,8 +60,7 @@ _muttconffiles() newconffiles=( $(sed -n 's|^source[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*$|\1|p' $(eval echo $1) ) ) for file in "${newconffiles[@]}"; do __expand_tilde_by_ref file - [[ ! -f "$file" || "${sofar/ ${file} / }" != "$sofar" ]] && - continue + [[ ! -f "$file" || $sofar == *\ $file\ * ]] && continue sofar+=" $file" sofar=" $(eval _muttconffiles \"$sofar\" $file) " done diff --git a/completions/ssh b/completions/ssh index e30b9153..e62b13fd 100644 --- a/completions/ssh +++ b/completions/ssh @@ -158,7 +158,7 @@ _ssh() # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument set -- "${words[@]}" while [ $# -gt 0 ]; do - if [ "${1:0:2}" = -F ]; then + if [[ $1 == -F* ]]; then if [ ${#1} -gt 2 ]; then configfile="$(dequote "${1:2}")" else @@ -221,7 +221,7 @@ _sftp() # Search COMP_WORDS for '-F configfile' argument set -- "${words[@]}" while [ $# -gt 0 ]; do - if [ "${1:0:2}" = -F ]; then + if [[ $1 == -F* ]]; then if [ ${#1} -gt 2 ]; then configfile="$(dequote "${1:2}")" else @@ -351,7 +351,7 @@ _scp() # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument set -- "${words[@]}" while [ $# -gt 0 ]; do - if [ "${1:0:2}" = -F ]; then + if [[ $1 == -F* ]]; then if [ ${#1} -gt 2 ]; then configfile="$(dequote "${1:2}")" else |