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