_filedir: Avoid some unnecessary work with -d
This commit is contained in:
parent
f9115ce0bb
commit
40c764af57
@ -560,38 +560,38 @@ _quote_readline_by_ref()
|
|||||||
#
|
#
|
||||||
_filedir()
|
_filedir()
|
||||||
{
|
{
|
||||||
local IFS=$'\n' xspec
|
local IFS=$'\n'
|
||||||
|
|
||||||
_tilde "$cur" || return 0
|
_tilde "$cur" || return 0
|
||||||
|
|
||||||
local -a toks
|
local -a toks
|
||||||
local quoted x tmp
|
local x tmp
|
||||||
|
|
||||||
_quote_readline_by_ref "$cur" quoted
|
|
||||||
x=$( compgen -d -- "$cur" ) &&
|
x=$( compgen -d -- "$cur" ) &&
|
||||||
while read -r tmp; do
|
while read -r tmp; do
|
||||||
toks+=( "$tmp" )
|
toks+=( "$tmp" )
|
||||||
done <<< "$x"
|
done <<< "$x"
|
||||||
|
|
||||||
if [[ "$1" != -d ]]; then
|
if [[ "$1" != -d ]]; then
|
||||||
|
local quoted
|
||||||
|
_quote_readline_by_ref "$cur" quoted
|
||||||
|
|
||||||
# Munge xspec to contain uppercase version too
|
# Munge xspec to contain uppercase version too
|
||||||
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
|
# http://thread.gmane.org/gmane.comp.shells.bash.bugs/15294/focus=15306
|
||||||
xspec=${1:+"!*.@($1|${1^^})"}
|
local xspec=${1:+"!*.@($1|${1^^})"}
|
||||||
x=$( compgen -f -X "$xspec" -- $quoted ) &&
|
x=$( compgen -f -X "$xspec" -- $quoted ) &&
|
||||||
while read -r tmp; do
|
while read -r tmp; do
|
||||||
toks+=( "$tmp" )
|
toks+=( "$tmp" )
|
||||||
done <<< "$x"
|
done <<< "$x"
|
||||||
|
|
||||||
|
# Try without filter if it failed to produce anything and configured to
|
||||||
|
[[ -n ${COMP_FILEDIR_FALLBACK:-} && -n "$1" && ${#toks[@]} -lt 1 ]] && \
|
||||||
|
x=$( compgen -f -- $quoted ) &&
|
||||||
|
while read -r tmp; do
|
||||||
|
toks+=( "$tmp" )
|
||||||
|
done <<< "$x"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If the filter failed to produce anything, try without it if configured to
|
|
||||||
[[ -n ${COMP_FILEDIR_FALLBACK:-} && \
|
|
||||||
-n "$1" && "$1" != -d && ${#toks[@]} -lt 1 ]] && \
|
|
||||||
x=$( compgen -f -- $quoted ) &&
|
|
||||||
while read -r tmp; do
|
|
||||||
toks+=( "$tmp" )
|
|
||||||
done <<< "$x"
|
|
||||||
|
|
||||||
|
|
||||||
if [[ ${#toks[@]} -ne 0 ]]; then
|
if [[ ${#toks[@]} -ne 0 ]]; then
|
||||||
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
|
# 2>/dev/null for direct invocation, e.g. in the _filedir unit test
|
||||||
compopt -o filenames 2>/dev/null
|
compopt -o filenames 2>/dev/null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user