From: "Gabriel F. T. Gomes" <gabriel@inconstante.eti.br>
Subject: _filedir_xspec: Fallback to suggesting all files if requested
Origin: vendor, https://bugs.debian.org/550676
Bug-Debian: https://bugs.debian.org/550676
Forwarded: yes, https://github.com/scop/bash-completion/pull/260

When completions generated by _filedir fail to produce an output with
xspec, they fallback to completing without any filters, provided that
the environment variable COMP_FILEDIR_FALLBACK is set and not-null.

This patch adds the same behavior to _filedir_xspec, so that it works
for the use case presented in message #45 in Debian bug #550676 [1],
as suggested in message #55 [2].

Before this patch, unzip completion would not complete:

  $ ls[ENTER]
  file  file.ext

  $ unzip [TAB][TAB][...]
  (no output)

After this patch, it completes:

  $ unzip [TAB]
  file      file.ext

In both cases, when a *.zip file exists, completion favours it:

  $ ls[ENTER]
  file  file.ext  file.zip

  $ unzip [TAB]
  $ unzip file.zip [CURSOR]

[1] https://bugs.debian.org/550676#45
[2] https://bugs.debian.org/550676#55
---
 bash_completion | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/bash_completion b/bash_completion
index 546cc39b..ee65196e 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1938,6 +1938,13 @@ _filedir_xspec()
         }
         ))
 
+    # Try without filter if it failed to produce anything and configured to
+    [[ -n ${COMP_FILEDIR_FALLBACK:-} && ${#toks[@]} -lt 1 ]] && {
+        local reset=$(shopt -po noglob); set -o noglob
+        toks+=( $( compgen -f -- "$(quote_readline "$cur")" ) )
+        IFS=' '; $reset; IFS=$'\n'
+    }
+
     if [[ ${#toks[@]} -ne 0 ]]; then
         compopt -o filenames
         COMPREPLY=( "${toks[@]}" )
-- 
2.20.0.rc1

