mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-18 15:21:16 +02:00
52 lines
1.6 KiB
Text
52 lines
1.6 KiB
Text
#autoload
|
|
|
|
# This is intended to be used as a completer function after the normal
|
|
# completer as in: `compconf completer=_complete:_match'.
|
|
# It temporarily switches on pattern matching, allowing you to try
|
|
# completion on patterns without having to setopt glob_complete.
|
|
#
|
|
# Note, however, that this is only really useful if you don't use the
|
|
# expand-or-complete function because otherwise the pattern will
|
|
# be expanded using globbing.
|
|
|
|
local tmp opm="$compstate[pattern_match]" ret=0
|
|
|
|
# Do nothing if we don't have a pattern or there are still global
|
|
# match specifications to try.
|
|
|
|
tmp="${${:-$PREFIX$SUFFIX}#[~=]}"
|
|
[[ "$tmp:q" = "$tmp" ||
|
|
compstate[matcher] -ne compstate[total_matchers] ]] && return 1
|
|
|
|
# Try completion without inserting a `*'?
|
|
|
|
if [[ -n "$compconfig[match_original]" ]]; then
|
|
compstate[matcher]=-1
|
|
compstate[pattern_match]='-'
|
|
_complete && ret=1
|
|
compstate[pattern_match]="$opm"
|
|
compstate[matcher]="$compstate[total_matchers]"
|
|
|
|
if (( ret )); then
|
|
[[ "$compconfig[match_insert]" = unambig* &&
|
|
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
|
|
compstate[pattern_insert]=unambiguous
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
# No completion with inserting `*'?
|
|
|
|
[[ "$compconfig[match_original]" = only ]] && return 1
|
|
|
|
compstate[matcher]=-1
|
|
compstate[pattern_match]='*'
|
|
_complete && ret=1
|
|
compstate[pattern_match]="$opm"
|
|
compstate[matcher]="$compstate[total_matchers]"
|
|
|
|
[[ ret -eq 1 && "$compconfig[match_insert]" = unambig* &&
|
|
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
|
|
compstate[pattern_insert]=unambiguous
|
|
|
|
return 1-ret
|