From d49da606702363f0eb5615a341126c2dbe562849 Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Tue, 25 Apr 2000 09:48:08 +0000 Subject: make _arguments use more than one action when appropriate; add _argument_sets to complete different sets of arguments and options for the same command (10908) --- Completion/Base/_argument_sets | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Completion/Base/_argument_sets (limited to 'Completion/Base/_argument_sets') diff --git a/Completion/Base/_argument_sets b/Completion/Base/_argument_sets new file mode 100644 index 000000000..ad59effdc --- /dev/null +++ b/Completion/Base/_argument_sets @@ -0,0 +1,56 @@ +#autoload + +local all ret=1 end xor has_args had_args ostate ocontext oopt_args r +local opre="$PREFIX" oipre="$IPREFIX" ocur="$CURRENT" +local osuf="$SUFFIX" oisuf="$ISUFFIX" owords + +owords="$words[@]" + +end=$argv[(i)-] +[[ end -gt $# ]] && return 1 + +all=( "${(@)argv[1,end]}" ) + +shift end + +xor=() +ostate=() +ocontext=() + +while true; do + end=$argv[(i)-] + + _arguments -M xor "$1" "$all[@]" "${(@)argv[2,end-1]}" + r=$? + + oopt_args=( "$oopt_args[@]" "${(kv)opt_args}" ) + if [[ r -eq 300 ]]; then + ret=300 + ostate=( "$ostate[@]" "$state[@]" ) + ocontext=( "$ocontext[@]" "$context[@]" ) + PREFIX="$opre" SUFFIX="$osuf" + IPREFIX="$oipre" ISUFFIX="$oisuf" + CURRENT="$ocur" words=( "$owords[@]" ) + elif [[ "$r$ret" = 01 ]]; then + ret=0 + fi + + [[ end -gt $# ]] && break + + shift end +done + +opt_args=( "$oopt_args[@]" ) + +if [[ ret -eq 300 ]]; then + state=( "$ostate[@]" ) + context=( "$ocontext[@]" ) +elif [[ -z "$has_args" ]]; then + if [[ -n "$had_args" ]]; then + _message "no more arguments" + else + _message "no arguments" + fi +fi + +return ret -- cgit 1.4.1