| 192 |
- |
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 IFS=$'\n'
|
|
|
12 |
|
|
|
13 |
_tilde "$cur" || return
|
|
|
14 |
|
|
|
15 |
local -a toks
|
|
|
16 |
local x tmp
|
|
|
17 |
|
|
|
18 |
x=$( compgen -d -- "$cur" ) &&
|
|
|
19 |
while read -r tmp; do
|
|
|
20 |
toks+=( "$tmp" )
|
|
|
21 |
done <<< "$x"
|
|
|
22 |
|
|
|
23 |
if [[ "$1" != -d ]]; then
|
|
|
24 |
local quoted
|
|
|
25 |
_quote_readline_by_ref "$cur" quoted
|
|
|
26 |
|
|
|
27 |
# Munge xspec to contain uppercase version too
|
|
|
28 |
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
|
|
|
29 |
local xspec=${1:+"!*.@($1|${1^^})"}
|
|
|
30 |
x=$( compgen -f -X "$xspec" -- $quoted ) &&
|
|
|
31 |
while read -r tmp; do
|
|
|
32 |
toks+=( "$tmp" )
|
|
|
33 |
done <<< "$x"
|
|
|
34 |
|
|
|
35 |
# Try without filter if it failed to produce anything and configured to
|
|
|
36 |
[[ -n ${COMP_FILEDIR_FALLBACK:-} && -n "$1" && ${#toks[@]} -lt 1 ]] && \
|
|
|
37 |
x=$( compgen -f -- $quoted ) &&
|
|
|
38 |
while read -r tmp; do
|
|
|
39 |
toks+=( "$tmp" )
|
|
|
40 |
done <<< "$x"
|
|
|
41 |
fi
|
|
|
42 |
|
|
|
43 |
if [[ ${#toks[@]} -ne 0 ]]; then
|
|
|
44 |
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
|
|
|
45 |
compopt -o filenames 2>/dev/null
|
|
|
46 |
COMPREPLY+=( "${toks[@]}" )
|
|
|
47 |
fi
|
|
|
48 |
} # _filedir()
|