Hello,

Unfortunately the -X option to compgen/complete is case sensitive and I don't 
think bash provides any way to affect that.  As a result, a lot of our 
filename completions either contain redundantish information and are 
annoyingly hard to read, or we simply miss filename completions for files 
whose case doesn't happen to be the expected one (usually lowercase).

The attached patch provides some automatic case insensitivity to _filedir and 
_filedir_xspec by automatically matching all-uppercase versions of the passed 
patterns as well as the original ones.  The idea is that if this goes in, all 
glob arguments to _filedir and the _filedir_xspec things can be cleaned up to 
all lowercase and we'd get better case insensitivity support automatically 
even without this work.  The downsides are that this isn't exactly that 
pretty, and that strictly case sensitive (non-all-uppercase) completions would 
no longer be possible.  I don't think these are big issues at all.

Thoughts, objections?
diff --git a/bash_completion b/bash_completion
index d423753..56a133a 100644
--- a/bash_completion
+++ b/bash_completion
@@ -637,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=( ${to...@]-} $( compgen -f -X "$xspec" -- $quoted) )
         if [ ${#to...@]} -ne 0 ]; then
             # If `compopt' is available, set `-o filenames'
@@ -1587,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=( ${to...@]-} $(
-        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
_______________________________________________
Bash-completion-devel mailing list
Bash-completion-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/bash-completion-devel

Reply via email to