6c1548a
# This is a copy of the _filedir function in bash_completion, included
6c1548a
# and (re)defined separately here because some versions of Adobe
6c1548a
# Reader, if installed, are known to override this function with an
6c1548a
# incompatible version, causing various problems.
6c1548a
#
6c1548a
# https://bugzilla.redhat.com/677446
6c1548a
# http://forums.adobe.com/thread/745833
6c1548a
6c1548a
_filedir()
6c1548a
{
6c1548a
    local i IFS=$'\n' xspec
6c1548a
6c1548a
    _tilde "$cur" || return 0
6c1548a
6c1548a
    local -a toks
6c1548a
    local quoted tmp
6c1548a
6c1548a
    _quote_readline_by_ref "$cur" quoted
6c1548a
    toks=( $(
6c1548a
        compgen -d -- "$quoted" | {
6c1548a
            while read -r tmp; do
6c1548a
                # TODO: I have removed a "[ -n $tmp ] &&" before 'printf ..',
6c1548a
                #       and everything works again. If this bug suddenly
6c1548a
                #       appears again (i.e. "cd /b<TAB>" becomes "cd /"),
6c1548a
                #       remember to check for other similar conditionals (here
6c1548a
                #       and _filedir_xspec()). --David
6c1548a
                printf '%s\n' $tmp
6c1548a
            done
6c1548a
        }
6c1548a
    ))
6c1548a
6c1548a
    if [[ "$1" != -d ]]; then
6c1548a
        # Munge xspec to contain uppercase version too
6c1548a
        # http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
6c1548a
        xspec=${1:+"!*.@($1|${1^^})"}
6c1548a
        toks+=( $( compgen -f -X "$xspec" -- $quoted ) )
6c1548a
    fi
6c1548a
6c1548a
    # If the filter failed to produce anything, try without it if configured to
6c1548a
    [[ -n ${COMP_FILEDIR_FALLBACK:-} && \
6c1548a
        -n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
6c1548a
        toks+=( $( compgen -f -- $quoted ) )
6c1548a
d1d1afa
    if [[ ${#toks[@]} -ne 0 ]]; then
d1d1afa
        # 2>/dev/null for direct invocation, e.g. in the _filedir unit test
d1d1afa
        compopt -o filenames 2>/dev/null
d1d1afa
        COMPREPLY+=( "${toks[@]}" )
d1d1afa
    fi
6c1548a
} # _filedir()