bash completion: Fix copy-paste typo
[lttng-tools.git] / extras / lttng-bash_completion
... / ...
CommitLineData
1#
2# Copyright (c) - 2012 Simon Marchi <simon.marchi@polymtl.ca>
3#
4# This program is free software; you can redistribute it and/or modify it under
5# the terms of the GNU General Public License as published by as published by
6# the Free Software Foundation; only version 2 of the License.
7#
8# This program is distributed in the hope that it will be useful, but WITHOUT
9# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11# more details.
12#
13# You should have received a copy of the GNU General Public License along with
14# this program; if not, write to the Free Software Foundation, Inc., 51
15# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17
18_lttng_complete_sessions() {
19 # TODO, maybe have a lttng list --simple or something like that
20 return
21}
22
23_lttng_cmd_addcontext() {
24 local add_context_opts
25 add_context_opts=$(lttng add-context --list-options)
26
27 case $prev in
28 --session|-s)
29 _lttng_complete_sessions
30 return
31 ;;
32 --channel|-c)
33 return
34 ;;
35 --type|-t)
36 return
37 ;;
38 esac
39
40 case $cur in
41 -*)
42 COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
43 return
44 ;;
45 esac
46}
47
48_lttng_cmd_create() {
49 local create_opts
50 create_opts=$(lttng create --list-options)
51
52 case $prev in
53 --output|-o)
54 _filedir -d
55 return
56 ;;
57 esac
58
59 case $cur in
60 -*)
61 COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) )
62 return
63 ;;
64 esac
65}
66
67_lttng_cmd_destroy() {
68 local destroy_opts
69 destroy_opts=$(lttng destroy --list-options)
70
71 case $cur in
72 -*)
73 COMPREPLY=( $(compgen -W "${destroy_opts}" -- $cur) )
74 ;;
75 *)
76 _lttng_complete_sessions
77 ;;
78 esac
79}
80
81_lttng_cmd_enablechannel() {
82 local enable_channel_opts
83 enable_channel_opts=$(lttng enable-channel --list-options)
84
85 case $prev in
86 --session|-s)
87 _lttng_complete_sessions
88 return
89 ;;
90 esac
91
92 case $cur in
93 -*)
94 COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
95 return
96 ;;
97 esac
98}
99
100_lttng_cmd_enableevent() {
101 local enable_event_opts
102 enable_event_opts=$(lttng enable-event --list-options)
103
104 case $prev in
105 --session|-s)
106 _lttng_complete_sessions
107 return
108 ;;
109 --channel|-c)
110 return
111 ;;
112 --probe)
113 return
114 ;;
115 --function)
116 return
117 ;;
118 esac
119
120 case $cur in
121 -*)
122 COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
123 return
124 ;;
125 esac
126}
127
128_lttng_cmd_disablechannel() {
129 local disable_channel_opts
130 disable_channel_opts=$(lttng disable-channel --list-options)
131
132 case $prev in
133 --session|-s)
134 _lttng_complete_sessions
135 return
136 ;;
137 esac
138
139 case $cur in
140 -*)
141 COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
142 return
143 ;;
144 esac
145}
146
147_lttng_cmd_disableevent() {
148 local disable_event_opts
149 disable_event_opts=$(lttng disable-event --list-options)
150
151 case $prev in
152 --session|-s)
153 _lttng_complete_sessions
154 return
155 ;;
156 --channel|-c)
157 return
158 ;;
159 esac
160
161 case $cur in
162 -*)
163 COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
164 return
165 ;;
166 esac
167}
168
169_lttng_cmd_list() {
170 local list_opts
171 list_opts=$(lttng list --list-options)
172
173 case $prev in
174 --channel|-c)
175 return
176 ;;
177 esac
178
179 case $cur in
180 -*)
181 COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
182 return
183 ;;
184 esac
185}
186
187_lttng_cmd_setsession() {
188 local set_session_opts
189 set_session_opts=$(lttng set-session --list-options)
190
191 case $cur in
192 -*)
193 COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
194 return
195 ;;
196 esac
197}
198
199_lttng_cmd_start() {
200 local start_opts
201 start_opts=$(lttng start --list-options)
202
203 case $cur in
204 -*)
205 COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
206 ;;
207 *)
208 _lttng_complete_sessions
209 ;;
210 esac
211}
212
213_lttng_cmd_stop() {
214 local stop_opts
215 stop_opts=$(lttng stop --list-options)
216
217 case $cur in
218 -*)
219 COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
220 ;;
221 *)
222 _lttng_complete_sessions
223 ;;
224 esac
225}
226
227_lttng_cmd_version() {
228 local version_opts
229 version_opts=$(lttng version --list-options)
230
231 case $cur in
232 -*)
233 COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
234 ;;
235 esac
236}
237
238_lttng_cmd_calibrate() {
239 local calibrate_opts
240 calibrate_opts=$(lttng calibrate --list-options)
241
242 case $cur in
243 -*)
244 COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
245 ;;
246 esac
247}
248
249_lttng_cmd_view() {
250 local view_opts
251 view_opts=$(lttng view --list-options)
252
253 case $cur in
254 -*)
255 COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
256 ;;
257 esac
258}
259
260_lttng_opts() {
261 local opts
262 opts=$(lttng --list-options)
263
264 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
265}
266
267_lttng_commands() {
268 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
269}
270
271_lttng_before_command() {
272 # Check if the previous word should alter the behavior
273 case $prev in
274 --group|-g)
275 COMPREPLY=( $(compgen -g -- $cur) )
276 return
277 ;;
278 --sessiond-path)
279 _filedir
280 return
281 ;;
282 esac
283
284 case $cur in
285 -*)
286 # If the current word starts with a dash, complete with options
287 _lttng_opts
288 ;;
289 *)
290 # Otherwise complete with commands
291 _lttng_commands
292 ;;
293 esac
294}
295
296_lttng_after_command() {
297 local cmd_name
298
299 cmd_name=_lttng_cmd_${command//-/}
300
301 type -t $cmd_name | grep -q 'function' && $cmd_name
302}
303
304_lttng_is_command() {
305 for command in $commands; do
306 if [ "$1" == "$command" ]; then
307 return 0
308 fi
309 done
310
311 return 1
312}
313
314_lttng() {
315 local cur prev commands command_found command_found_index
316
317 # Get the current and previous word
318 _get_comp_words_by_ref cur prev
319
320 # Get the valid LTTng commands
321 commands=$(lttng --list-commands)
322
323 # The text of the found command
324 command_found=""
325
326 # The index of the found command in COMP_WORDS
327 command_found_index=-1
328
329 for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
330 _lttng_is_command ${COMP_WORDS[$i]}
331 if [ $? -eq 0 ]; then
332 command_found=${COMP_WORDS[$i]}
333 command_found_index=$i
334 break
335 fi
336
337 done
338
339 # Check if the cursor is before or after the command keyword
340 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
341 _lttng_after_command
342 else
343 _lttng_before_command
344 fi
345}
346
347complete -F _lttng lttng
This page took 0.024784 seconds and 5 git commands to generate.