Introduce channel timer lock
[lttng-tools.git] / extras / lttng-bash_completion
CommitLineData
fc256d99
DG
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_add_context() {
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 --event|-e)
36 return
37 ;;
38 --type|-t)
39 return
40 ;;
41 esac
42
43 case $cur in
44 -*)
45 COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
46 return
47 ;;
48 esac
49}
50
51_lttng_cmd_create() {
52 local create_opts
53 create_opts=$(lttng create --list-options)
54
55 case $prev in
56 --output|-o)
57 _filedir -d
58 return
59 ;;
60 esac
61
62 case $cur in
63 -*)
64 COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) )
65 return
66 ;;
67 esac
68}
69
70_lttng_cmd_destroy() {
71 local destroy_opts
72 destroy_opts=$(lttng destroy --list-options)
73
74 case $cur in
75 -*)
76 COMPREPLY=( $(compgen -W "${destroy_opts}" -- $cur) )
77 ;;
78 *)
79 _lttng_complete_sessions
80 ;;
81 esac
82}
83
84_lttng_cmd_enablechannel() {
85 local enable_channel_opts
86 enable_channel_opts=$(lttng enable-channel --list-options)
87
88 case $prev in
89 --session|-s)
90 _lttng_complete_sessions
91 return
92 ;;
93 esac
94
95 case $cur in
96 -*)
97 COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
98 return
99 ;;
100 esac
101}
102
103_lttng_cmd_enableevent() {
104 local enable_event_opts
105 enable_event_opts=$(lttng enable-event --list-options)
106
107 case $prev in
108 --session|-s)
109 _lttng_complete_sessions
110 return
111 ;;
112 --channel|-c)
113 return
114 ;;
115 --probe)
116 return
117 ;;
118 --function)
119 return
120 ;;
121 esac
122
123 case $cur in
124 -*)
125 COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
126 return
127 ;;
128 esac
129}
130
14c8c23f
DG
131_lttng_cmd_enableconsumer() {
132 local enable_consumer_opts
133 enable_consumer_opts=$(lttng enable-consumer --list-options)
134
135 case $prev in
136 --session|-s)
137 _lttng_complete_sessions
138 return
139 ;;
140 esac
141
142 case $cur in
143 -*)
144 COMPREPLY=( $(compgen -W "${enable_consumer_opts}" -- $cur) )
145 return
146 ;;
147 esac
148}
149
150_lttng_cmd_disableconsumer() {
151 local disable_consumer_opts
152 disable_consumer_opts=$(lttng disable-consumer --list-options)
153
154 case $prev in
155 --session|-s)
156 _lttng_complete_sessions
157 return
158 ;;
159 esac
160
161 case $cur in
162 -*)
163 COMPREPLY=( $(compgen -W "${disable_consumer_opts}" -- $cur) )
164 return
165 ;;
166 esac
167}
168
fc256d99
DG
169_lttng_cmd_disablechannel() {
170 local disable_channel_opts
171 disable_channel_opts=$(lttng disable-channel --list-options)
172
173 case $prev in
174 --session|-s)
175 _lttng_complete_sessions
176 return
177 ;;
178 esac
179
180 case $cur in
181 -*)
182 COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
183 return
184 ;;
185 esac
186}
187
188_lttng_cmd_disable_event() {
189 local disable_event_opts
190 disable_channel_opts=$(lttng disable-event --list-options)
191
192 case $prev in
193 --session|-s)
194 _lttng_complete_sessions
195 return
196 ;;
197 --channel|-c)
198 return
199 ;;
200 esac
201
202 case $cur in
203 -*)
204 COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
205 return
206 ;;
207 esac
208}
209
210_lttng_cmd_list() {
211 local list_opts
39f49fee 212 list_opts=$(lttng list --list-options)
fc256d99
DG
213
214 case $prev in
215 --channel|-c)
216 return
217 ;;
218 esac
219
220 case $cur in
221 -*)
222 COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
223 return
224 ;;
225 esac
226}
227
228_lttng_cmd_set_session() {
229 local set_session_opts
230 set_session_opts=$(lttng set-session --list-options)
231
232 case $cur in
233 -*)
234 COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
235 return
236 ;;
237 esac
238}
239
240_lttng_cmd_start() {
241 local start_opts
242 start_opts=$(lttng start --list-options)
243
244 case $cur in
245 -*)
246 COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
247 ;;
248 *)
249 _lttng_complete_sessions
250 ;;
251 esac
252}
253
254_lttng_cmd_stop() {
255 local stop_opts
256 stop_opts=$(lttng stop --list-options)
257
258 case $cur in
259 -*)
260 COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
261 ;;
262 *)
263 _lttng_complete_sessions
264 ;;
265 esac
266}
267
268_lttng_cmd_version() {
269 local version_opts
270 version_opts=$(lttng version --list-options)
271
272 case $cur in
273 -*)
274 COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
275 ;;
276 esac
277}
278
279_lttng_cmd_calibrate() {
280 local calibrate_opts
281 calibrate_opts=$(lttng calibrate --list-options)
282
283 case $cur in
284 -*)
285 COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
286 ;;
287 esac
288}
289
0c95f5b2
DG
290_lttng_cmd_view() {
291 local view_opts
292 view_opts=$(lttng view --list-options)
293
294 case $cur in
295 -*)
296 COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
297 ;;
298 esac
299}
300
fc256d99
DG
301_lttng_opts() {
302 local opts
303 opts=$(lttng --list-options)
304
305 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
306}
307
308_lttng_commands() {
309 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
310}
311
312_lttng_before_command() {
313 # Check if the previous word should alter the behavior
314 case $prev in
315 --group|-g)
316 COMPREPLY=( $(compgen -g -- $cur) )
317 return
318 ;;
319 --sessiond-path)
320 _filedir
321 return
322 ;;
323 esac
324
325 case $cur in
326 -*)
327 # If the current word starts with a dash, complete with options
328 _lttng_opts
329 ;;
330 *)
331 # Otherwise complete with commands
332 _lttng_commands
333 ;;
334 esac
335}
336
337_lttng_after_command() {
338 local cmd_name
339
340 cmd_name=_lttng_cmd_${command//-/}
341
342 type -t $cmd_name | grep -q 'function' && $cmd_name
343}
344
345_lttng_is_command() {
346 for command in $commands; do
347 if [ "$1" == "$command" ]; then
348 return 0
349 fi
350 done
351
352 return 1
353}
354
355_lttng() {
356 local cur prev commands command_found command_found_index
357
358 # Get the current and previous word
359 _get_comp_words_by_ref cur prev
360
361 # Get the valid LTTng commands
362 commands=$(lttng --list-commands)
363
364 # The text of the found command
365 command_found=""
366
367 # The index of the found command in COMP_WORDS
368 command_found_index=-1
369
370 for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
371 _lttng_is_command ${COMP_WORDS[$i]}
372 if [ $? -eq 0 ]; then
373 command_found=${COMP_WORDS[$i]}
374 command_found_index=$i
375 break
376 fi
377
378 done
379
380 # Check if the cursor is before or after the command keyword
381 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
382 _lttng_after_command
383 else
384 _lttng_before_command
385 fi
386}
387
388complete -F _lttng lttng
This page took 0.061307 seconds and 4 git commands to generate.