about summary refs log tree commit diff
path: root/Completion/Base/_first
blob: 386f67fa0008415e2a2fa604e3ad03e619e66b70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#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" = *,, ]] && _wanted history-words; then
#       local max i=1 expl
#     
#       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:-1} -gt 1 ]]; then
#         max=$NUMERIC
#         unset NUMERIC
#       else
#         # The default is to search the last 100 lines.
#         max=10
#       fi
#       # We first search in the last ten words, then in the last
#       # twenty words, and so on...
#       while [[ i -le max ]]; do
#         if zstyle -t ":completion:${curcontext}:history-words" sort; then
#           _description history-words expl "history ($n)"
#         else
#           _description -V history-words expl "history ($n)"
#         fi
#         if compadd "$expl[@]" -Q - \
#                "${(@)${(@)historywords:#[\$'\"]*}[1,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 _compskip.
#           compstate[insert]=menu
#           _compskip=all
#           return
#         fi
#         (( i++ ))
#       done
#     fi