Blame SOURCES/bash-completion-2.0-redefine_filedir.bash

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