[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 7ea7d7b2686a1c37d4b43c81b42e07054ae34acd

Ville Skyttä ville.skytta at iki.fi
Sun Sep 19 09:30:38 UTC 2010


The following commit has been merged in the master branch:
commit c183a585b279dc29fcd8c5f18b9bab135cbdd358
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Sun Sep 19 12:06:53 2010 +0300

    Match uppercased versions of _filedir and _filedir_xspec arguments too.
    
    This provides a bit of case insensivity to file extension matching,
    allowing for example _filedir foo to match both *.foo and *.FOO.  Note
    that this is not real case insensivity; mixed case extensions like
    *.FOO.gz are not matched by _filedir foo.gz so those need to be
    handled like before this change.

diff --git a/CHANGES b/CHANGES
index e122576..ffe2d80 100644
--- a/CHANGES
+++ b/CHANGES
@@ -20,6 +20,8 @@ bash-completion (2.x)
     --all long options (RedHat: #630328).
   * Improve rpm query option completions.
   * Drop bad kompare filename completion (Alioth: #312708).
+  * Make _filedir and _filedir_xspec complete uppercase versions of their
+    filename extension arguments in addition to exact case matches.
 
   [ Freddy Vulto ]
   * Added _tilde(), fix ~username completion (Alioth: #312613, Debian: #587095)
diff --git a/bash_completion b/bash_completion
index e6edf87..2e56704 100644
--- a/bash_completion
+++ b/bash_completion
@@ -610,7 +610,8 @@ _quote_readline_by_ref()
 # This function performs file and directory completion. It's better than
 # simply using 'compgen -f', because it honours spaces in filenames.
 # @param $1  If `-d', complete only on directories.  Otherwise filter/pick only
-#            completions with `.$1' as file extension.
+#            completions with `.$1' and the uppercase version of it as file
+#            extension.
 #
 _filedir()
 {
@@ -636,7 +637,10 @@ _filedir()
     ))
 
     if [[ "$1" != -d ]]; then
-        xspec=${1:+"!*.$1"}
+        # Munge xspec to contain uppercase version too
+        [[ ${BASH_VERSINFO[0]} -ge 4 ]] && \
+            xspec=${1:+"!*.@($1|${1^^})"} || \
+            xspec=${1:+"!*.@($1|$(printf %s $1 | tr '[:lower:]' '[:upper:]'))"}
         toks=( ${toks[@]-} $( compgen -f -X "$xspec" -- $quoted) )
         if [ ${#toks[@]} -ne 0 ]; then
             # If `compopt' is available, set `-o filenames'
@@ -1586,8 +1590,19 @@ _filedir_xspec()
         }
         ))
 
+    # Munge xspec to contain uppercase version too
+    eval xspec="${xspec}"
+    local matchop=!
+    if [[ $xspec == !* ]]; then
+        xspec=${xspec#!}
+        matchop=@
+    fi
+    [[ ${BASH_VERSINFO[0]} -ge 4 ]] && \
+        xspec="$matchop($xspec|${xspec^^})" || \
+        xspec="$matchop($xspec|$(printf %s $xspec | tr '[:lower:]' '[:upper:]'))"
+
     toks=( ${toks[@]-} $(
-        eval compgen -f -X "$xspec" -- "\$(quote_readline "\$cur")" | {
+        eval compgen -f -X "!$xspec" -- "\$(quote_readline "\$cur")" | {
         while read -r tmp; do
             [ -n $tmp ] && printf '%s\n' $tmp
         done
diff --git a/test/fixtures/_filedir/a b/i b/test/fixtures/_filedir/ext/ii.E1
similarity index 100%
copy from test/fixtures/_filedir/a b/i
copy to test/fixtures/_filedir/ext/ii.E1
diff --git a/test/unit/_filedir.exp b/test/unit/_filedir.exp
index 204d31c..59d5085 100644
--- a/test/unit/_filedir.exp
+++ b/test/unit/_filedir.exp
@@ -242,7 +242,7 @@ foreach name {f f2} {
 
 
 set test "completing with filter '.e1' should show completions"
-assert_complete_dir {ee.e1 foo/ gg.e1} "g " "fixtures/_filedir/ext" $test
+assert_complete_dir {ee.e1 foo/ gg.e1 ii.E1} "g " "fixtures/_filedir/ext" $test
 
 
 sync_after_int

-- 
bash-completion



More information about the Bash-completion-commits mailing list