about summary refs log tree commit diff
path: root/Functions/Completion/_normal
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Completion/_normal')
-rw-r--r--Functions/Completion/_normal56
1 files changed, 56 insertions, 0 deletions
diff --git a/Functions/Completion/_normal b/Functions/Completion/_normal
new file mode 100644
index 000000000..22cc1decf
--- /dev/null
+++ b/Functions/Completion/_normal
@@ -0,0 +1,56 @@
+#autoload
+
+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" ]] || "$comp" "$@"
+  return
+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
+      "$val" "$@"
+      if (( $+COMPSKIP )); then
+        unset COMPSKIP
+        return
+      fi
+    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" ]] || "$comp" "$@"