diff --git a/CHANGES b/CHANGES index e1225767..ffe2d80e 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 e6edf87b..2e56704a 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/ext/ii.E1 b/test/fixtures/_filedir/ext/ii.E1 new file mode 100644 index 00000000..e69de29b diff --git a/test/unit/_filedir.exp b/test/unit/_filedir.exp index 204d31cf..59d50854 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