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

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