[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-533-g1d48f79

Ville Skyttä ville.skytta at iki.fi
Wed Nov 9 20:55:54 UTC 2011


The following commit has been merged in the master branch:
commit 1d48f79b9c6a9b9e9044741d300ded461d765135
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Wed Nov 9 22:24:39 2011 +0200

    Cleanups: use usual globs instead of substring matches or substitutions.

diff --git a/bash_completion b/bash_completion
index 73ae920..cb4f0bf 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 at 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 aa16be6..7186580 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 70699a1..f1fd6ff 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 e30b915..e62b13f 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

-- 
bash-completion



More information about the Bash-completion-commits mailing list