1
0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-10-03 01:11:37 +02:00
zsh/Completion/Core/_match

52 lines
1.4 KiB
Plaintext
Raw Normal View History

1999-04-15 20:05:38 +02:00
#autoload
# This is intended to be used as a completer function after the normal
2000-04-01 22:43:43 +02:00
# completer as in: `zstyle ":completion:::::" completer _complete _match'.
1999-04-15 20:05:38 +02:00
# 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.
### Shouldn't be needed any more: [[ _matcher_num -gt 1 ]] && return 1
2000-04-01 22:43:43 +02:00
local tmp opm="$compstate[pattern_match]" ret=0 orig ins
1999-04-15 20:05:38 +02:00
2000-04-01 22:43:43 +02:00
# Do nothing if we don't have a pattern.
1999-04-15 20:05:38 +02:00
tmp="${${:-$PREFIX$SUFFIX}#[~=]}"
2000-04-01 22:43:43 +02:00
[[ "$tmp:q" = "$tmp" ]] && return 1
zstyle -s ":completion:${curcontext}:" match-original orig
zstyle -b ":completion:${curcontext}:" insert-unambiguous ins
1999-04-15 20:05:38 +02:00
# Try completion without inserting a `*'?
2000-04-01 22:43:43 +02:00
if [[ -n "$orig" ]]; then
1999-04-15 20:05:38 +02:00
compstate[pattern_match]='-'
_complete && ret=1
compstate[pattern_match]="$opm"
2000-04-01 22:43:43 +02:00
if (( ret )); then
[[ "$ins" = yes &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
compstate[pattern_insert]=unambiguous
return 0
fi
1999-04-15 20:05:38 +02:00
fi
# No completion with inserting `*'?
2000-04-01 22:43:43 +02:00
[[ "$orig" = only ]] && return 1
1999-04-15 20:05:38 +02:00
compstate[pattern_match]='*'
_complete && ret=1
compstate[pattern_match]="$opm"
2000-04-01 22:43:43 +02:00
[[ ret -eq 1 && "$ins" = yes &&
$#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] &&
compstate[pattern_insert]=unambiguous
1999-04-15 20:05:38 +02:00
return 1-ret