-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathack_completion
More file actions
executable file
·186 lines (175 loc) · 4.14 KB
/
ack_completion
File metadata and controls
executable file
·186 lines (175 loc) · 4.14 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# vim: et ft=sh sts=2 sw=2 ts=2
#
# Copyright 2008-2009 Adam James <atj@pulsewidth.org.uk>
# All rights reserved.
# This program is free software; you can redistribute it and/or modify it
# under the same terms as ack itself.
#
# This file requires functions from the bash-completion package, which is
# available at http://bash-completion.alioth.debian.org
#
#
# Thanks to John Purnell for pointing out some missed options.
# ack-grep on Debian distros
# please accept my apologies for polluting the environment!
__ack_types=$(ack --help=types 2>/dev/null | perl -ne 'print "$1 no$1 " if /^\s+--\[no\](\S+)\s+/' 2>/dev/null)
__ack_typeopts=""
for type in $__ack_types ; do
__ack_typeopts="${__ack_typeopts} --${type}"
done
_ack() {
local lngopt shtopt clropt
local cur prev
COMPREPLY=()
cur=$(_get_cword "=")
prev="${COMP_WORDS[COMP_CWORD-1]}"
_expand || return 0
# these options are final
if [[ ${COMP_WORDS[@]} == *+([[:space:]])--@(help|man|th+([pt])+(t)|version)+([[:space:]])* ]] ; then
return 0
fi
lngopt='
--after-context=
--all-types
--before-context=
--break
--nobreak
--color
--nocolor
--colour
--nocolour
--color-filename=
--color-match=
--column
--context=
--count
--env
--noenv
--files-with-matches
--files-without-matches
--flush
--follow
--nofollow
--group
--nogroup
--heading
--noheading
--ignore-case
--ignore-dir=
--noignore-dir=
--invert-match
--line=
--literal
--match
--max-count=
--no-filename
--output=
--pager=
--nopager
--passthru
--print0
--recurse
--norecurse
--rc=
--smart-case
--nosmart-case
--sort-files
--type=
--type-add
--type-set
--unrestricted
--with-filename
--word-regexp
'
fnlopt='
--help
--man
--thpppt
--version
'
shtopt='
-a -A -B -C -c
-f -G -g -H -h
-i -l -L -m -n
-o -Q -r -R -u
-v -w -1
'
clropt='
clear
reset
dark
bold
underline
underscore
blink
reverse
concealed
black
red
green
yellow
blue
magenta
on_black
on_red
on_green
on_yellow
on_blue
on_magenta
on_cyan
on_white
'
# these options require an argument
if [[ "${prev}" == -@(A|B|C|G|g|-match) ]] ; then
return 0
fi
case "${cur}" in
--?*=*)
_split_longopt || return 0
case "${prev}" in
--?(no)ignore-dir) # directory completion
_filedir -d
return 0;;
--pager) # command completion
COMPREPLY=( $(compgen -c -- "${cur}") )
return 0;;
--rc) # file completion
_filedir
return 0;;
--color-@(filename|match)) # color completion
COMPREPLY=( $(compgen -W "${clropt}" -- "${cur}") )
return 0;;
--type) # type completion
COMPREPLY=( $(compgen -W "${__ack_types}" -- "${cur}") )
return 0;;
esac;;
-*)
# -a and -u negate the use of type options
if [[ " ${COMP_WORDS[@]} " == *" -a "* || " ${COMP_WORDS[@]} " == *" -u "* ]] ; then
if [[ "${COMP_CWORD}" -eq 1 ]] ; then
COMPREPLY=( $(compgen -W \
"${lngopt} ${shtopt} ${fnlopt}" -- "${cur}") )
else
COMPREPLY=( $(compgen -W \
"${lngopt} ${shtopt}" -- "${cur}") )
fi
else
if [[ "${COMP_CWORD}" -eq 1 ]] ; then
COMPREPLY=( $(compgen -W \
"${lngopt} ${shtopt} ${fnlopt} ${__ack_typeopts}" -- "${cur}") )
else
COMPREPLY=( $(compgen -W \
"${lngopt} ${shtopt} ${__ack_typeopts}" -- "${cur}") )
fi
fi
return 0;;
*)
if [[ " ${COMP_WORDS[@]} " == *" -f "* ]] ; then
_filedir -d
elif [[ "${prev}" != -* ]] ; then
_filedir
fi
return 0;;
esac
}
complete -F _ack ${nospace} ack