From 6c1fb551ba0973c9a86e1ea479d553d66c6bf6b7 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 15 Apr 1999 18:24:09 +0000 Subject: zsh-3.1.5-pws-14 --- Completion/Core/_match | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Completion/Core/_match (limited to 'Completion/Core/_match') diff --git a/Completion/Core/_match b/Completion/Core/_match new file mode 100644 index 000000000..3c639935c --- /dev/null +++ b/Completion/Core/_match @@ -0,0 +1,53 @@ +#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. +# +# Configuration key used: +# +# match_original +# If this is set to a `only', pattern matching will only be tried +# with the string from the line. If it is set to any other non-empty +# string, the original pattern will be tried first and if that yields +# no completions, matching will be tried again with a `*' inserted +# at the cursor position. If this key is not set or set to an empty +# string, matching will only be attempted with the `*' inserted. + +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]" + + (( ret )) && return 0 +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]" + +return 1-ret -- cgit 1.4.1