summaryrefslogtreecommitdiffstats
path: root/Functions/Completion/__normal
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:15:04 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-04-15 18:15:04 +0000
commitba4f5e80ec9d7e145718e79fed6e57a852c86c12 (patch)
treeae29f2dfb81bb4e20b015610d85ce5f5a2d96eda /Functions/Completion/__normal
parentzsh-3.1.5-pws-7 (diff)
downloadzsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.tar
zsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.tar.gz
zsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.tar.bz2
zsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.tar.lz
zsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.tar.xz
zsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.tar.zst
zsh-ba4f5e80ec9d7e145718e79fed6e57a852c86c12.zip
zsh-3.1.5-pws-8zsh-3.1.5-pws-8
Diffstat (limited to 'Functions/Completion/__normal')
-rw-r--r--Functions/Completion/__normal54
1 files changed, 54 insertions, 0 deletions
diff --git a/Functions/Completion/__normal b/Functions/Completion/__normal
new file mode 100644
index 000000000..7750563d1
--- /dev/null
+++ b/Functions/Completion/__normal
@@ -0,0 +1,54 @@
+#helper
+
+local comp cmd1 cmd2 pat val name
+
+# Completing in command position? If not we set up `cmd1' and `cmd2' as
+# two strings we have search in the completion definition arrays (e.g.
+# a path and the last path name component).
+
+if [[ $CONTEXT == command ]]; then
+ comp="$comps[--command--]"
+ [[ -z "$comp" ]] || callcomplete comps --command-- "$@" || return 1
+ return 0
+elif [[ "$COMMAND[1]" == '=' ]]; then
+ eval cmd1\=$COMMAND
+ cmd2="$COMMAND[2,-1]"
+elif [[ "$COMMAND" == */* ]]; then
+ cmd1="$COMMAND"
+ cmd2="${COMMAND:t}"
+else
+ cmd1="$COMMAND"
+ eval cmd2=$(whence -p $COMMAND)
+fi
+
+# See if there are any matching pattern completions.
+
+if (( $#patcomps )); then
+ for i in "$patcomps[@]"; do
+ pat="${i% *}"
+ val="${i#* }"
+ if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
+ callcomplete patcomps "$pat" "$@" || return 1
+ fi
+ done
+fi
+
+# Now look up the two names in the normal completion array.
+
+name="$cmd1"
+comp="$comps[$cmd1]"
+
+if [[ -z "$comp" ]]; then
+ name="$cmd2"
+ comp="$comps[$cmd2]"
+fi
+
+# And generate the matches, probably using default completion.
+
+if [[ -z "$comp" ]]; then
+ name=--default--
+ comp="$comps[--default--]"
+fi
+[[ -z "$comp" ]] || callcomplete comps "$name" "$@" || return 1
+
+return 0