]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blame - bash-completion/bash-completion-1.99-redefine_filedir.bash
kernel: Update to 3.15.6.
[people/ms/ipfire-3.x.git] / bash-completion / bash-completion-1.99-redefine_filedir.bash
CommitLineData
b52dd7ea
MT
1# This is a copy of the _filedir function in bash_completion, included
2# and (re)defined separately here because some versions of Adobe
3# Reader, if installed, are known to override this function with an
4# incompatible version, causing various problems.
5#
6# https://bugzilla.redhat.com/677446
7# http://forums.adobe.com/thread/745833
8
9_filedir()
10{
11 local i IFS=$'\n' xspec
12
13 _tilde "$cur" || return 0
14
15 local -a toks
16 local quoted tmp
17
18 _quote_readline_by_ref "$cur" quoted
19 toks=( $(
20 compgen -d -- "$quoted" | {
21 while read -r tmp; do
22 # TODO: I have removed a "[ -n $tmp ] &&" before 'printf ..',
23 # and everything works again. If this bug suddenly
24 # appears again (i.e. "cd /b<TAB>" becomes "cd /"),
25 # remember to check for other similar conditionals (here
26 # and _filedir_xspec()). --David
27 printf '%s\n' $tmp
28 done
29 }
30 ))
31
32 if [[ "$1" != -d ]]; then
33 # Munge xspec to contain uppercase version too
34 # http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
35 xspec=${1:+"!*.@($1|${1^^})"}
36 toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
37 fi
38
39 # If the filter failed to produce anything, try without it if configured to
40 [[ -n ${COMP_FILEDIR_FALLBACK:-} && \
41 -n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
42 toks+=( $( compgen -f -- $quoted ) )
43
44 if [[ ${#toks[@]} -ne 0 ]]; then
45 # 2>/dev/null for direct invocation, e.g. in the _filedir unit test
46 compopt -o filenames 2>/dev/null
47 COMPREPLY+=( "${toks[@]}" )
48 fi
49} # _filedir()