about summary refs log tree commit diff
path: root/Completion/Base
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/.distfiles2
-rw-r--r--Completion/Base/_brace_parameter14
-rw-r--r--Completion/Base/_first63
-rw-r--r--Completion/Base/_long_options10
4 files changed, 81 insertions, 8 deletions
diff --git a/Completion/Base/.distfiles b/Completion/Base/.distfiles
index 6c537c26b..ef1e9df73 100644
--- a/Completion/Base/.distfiles
+++ b/Completion/Base/.distfiles
@@ -1,6 +1,6 @@
 DISTFILES_SRC='
     .distfiles 
-    _brace_parameter _command_names _condition _default _equal
+    _brace_parameter _command_names _condition _default _equal _first
     _long_options _math _parameter _precommand _redirect _subscript
     _tilde _vars 
 '
diff --git a/Completion/Base/_brace_parameter b/Completion/Base/_brace_parameter
index d45e317be..f688e175a 100644
--- a/Completion/Base/_brace_parameter
+++ b/Completion/Base/_brace_parameter
@@ -1,9 +1,19 @@
 #compdef -brace-parameter-
 
+setopt localoptions extendedglob
+
+local lp ls n q suf=''
+
 if [[ "$SUFFIX" = *\}* ]]; then
   ISUFFIX="${SUFFIX#*\}}$ISUFFIX"
   SUFFIX="${SUFFIX%%\}*}"
-  _parameters -S '} ' -r '-:?#%+=[/'
 else
-  _parameters -S '} ' -r '-:?#%+=[/'
+  suf='} '
 fi
+
+lp="$LBUFFER[1,-${#PREFIX}-1]"
+ls="$RBUFFER[${#SUFFIX}+1,-1]"
+n=${(M)#ls##\"#}
+q=${(M)lp%%\"#}
+
+_parameters -s "${q[1,-n-1]}" -S "$suf" -r '-:?#%+=[/'
diff --git a/Completion/Base/_first b/Completion/Base/_first
new file mode 100644
index 000000000..d9e7ee82c
--- /dev/null
+++ b/Completion/Base/_first
@@ -0,0 +1,63 @@
+#compdef -first-
+
+# This function is called at the very beginning before any other
+# function for a specific context.
+#
+# This just gives some examples of things you might want to do here.
+#
+#
+# If you use the vared builtin and want completion in there to act the 
+# way completion on the right hand side of assignments is done, add
+# (or un-comment) this code:
+#
+#     if [[ -n $compstate[vared] ]]; then
+#       if [[ $compstate[vared] = *\[* ]]; then
+#         # vared on an array-element
+#         compstate[parameter]=${compstate[vared]%%\[*}
+#         compstate[context]=value
+#       else
+#         # vared on a parameter, let's see if it is an array
+#         compstate[parameter]=$compstate[vared]
+#         if [[ ${(tP)compstate[vared]} = *(array|assoc)* ]]; then
+#           compstate[context]=array_value
+#         else
+#           compstate[context]=value
+#         fi
+#       fi
+#       return
+#     fi
+#
+#
+#
+# Other things you can do here is to complete different things if the
+# word on the line matches a certain pattern. This example allows
+# completion of words from the history by adding two commas at the end 
+# and hitting TAB.
+#
+#     if [[ "$PREFIX" = *,, ]]; then
+#       local max i=1
+#     
+#       PREFIX="$PREFIX[1,-2]"
+#       # If a numeric prefix is given, we use it as the number of
+#       # lines (multiplied by ten below) in the history to search.
+#       if [[ NUMERIC -gt 1 ]]; then
+#         max=$NUMERIC
+#         NUMERIC=1
+#       else
+#         # The default is to search the last 100 lines.
+#         max=10
+#       fi
+#       # We first search in the last ten lines, then in the last
+#       # twenty lines, and so on...
+#       while [[ i -le max ]]; do
+#         if compgen -X "%Bhistory ($n):%b" -Q -H $(( i*10 )) ''; then
+#           # We have found at least one matching word, so we switch
+#           # on menu-completion and make sure that no other
+#           # completion function is called by setting _comp_skip.
+#           compstate[insert]=menu
+#           _comp_skip=1
+#           return
+#         fi
+#         (( i++ ))
+#       done
+#     fi
diff --git a/Completion/Base/_long_options b/Completion/Base/_long_options
index 6288fc3a0..a50edee1c 100644
--- a/Completion/Base/_long_options
+++ b/Completion/Base/_long_options
@@ -7,11 +7,11 @@
 # a command that does not support this option.
 #
 # For options that get an argument after a `=', the function also tries
-# to automatically find out what should be complete as the argument.
+# to automatically find out what should be completed as the argument.
 # The possible completions for option-arguments can be described with
 # the arguments to this function. This is done by giving pairs of
 # patterns and actions as consecutive arguments. The actions specify
-# what should be done to complete arguemts of those options that match 
+# what should be done to complete arguments of those options that match 
 # the pattern. The action may be a list of words in brackets or in
 # parentheses, separated by spaces. A list in brackets denotes
 # possible values for an optional argument, a list in parentheses
@@ -27,18 +27,18 @@
 # This makes `yes' and `no' be completed as the argument of options
 # whose description ends in a star, file names for options that
 # contain the substring `=FILE' in the description, and paths for
-# options whose description contains `=DIR'. Note the last two
+# options whose description contains `=DIR'. Note that the last two
 # patterns are not needed since this function always completes files
 # for option descriptions containing `=FILE' and paths for option
 # descriptions that contain `=DIR' or `=PATH'. These builtin patterns
 # can be overridden by patterns given as arguments, though.
 # 
-# This function accepts following options:
+# This function accepts the following options:
 #
 # -t   do completion only on words starting with two hyphens
 #
 # -i   list of patterns. Options, matching these patterns, are ignored.
-#      The list may be given as array name or as literal list in braces.
+#      The list may be given as a array name or as a literal list in braces.
 #      E.g. _long_options -i '(--(enable|disable)-FEATURE*)' will ignore
 #      --enable-FEATURE, that is listed in configure help output
 #