Add the lttng view command
[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
131_lttng_cmd_disablechannel() {
132 local disable_channel_opts
133 disable_channel_opts=$(lttng disable-channel --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 "${disable_channel_opts}" -- $cur) )
145 return
146 ;;
147 esac
148}
149
150_lttng_cmd_disable_event() {
151 local disable_event_opts
152 disable_channel_opts=$(lttng disable-event --list-options)
153
154 case $prev in
155 --session|-s)
156 _lttng_complete_sessions
157 return
158 ;;
159 --channel|-c)
160 return
161 ;;
162 esac
163
164 case $cur in
165 -*)
166 COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
167 return
168 ;;
169 esac
170}
171
172_lttng_cmd_list() {
173 local list_opts
39f49fee 174 list_opts=$(lttng list --list-options)
fc256d99
DG
175
176 case $prev in
177 --channel|-c)
178 return
179 ;;
180 esac
181
182 case $cur in
183 -*)
184 COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
185 return
186 ;;
187 esac
188}
189
190_lttng_cmd_set_session() {
191 local set_session_opts
192 set_session_opts=$(lttng set-session --list-options)
193
194 case $cur in
195 -*)
196 COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
197 return
198 ;;
199 esac
200}
201
202_lttng_cmd_start() {
203 local start_opts
204 start_opts=$(lttng start --list-options)
205
206 case $cur in
207 -*)
208 COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
209 ;;
210 *)
211 _lttng_complete_sessions
212 ;;
213 esac
214}
215
216_lttng_cmd_stop() {
217 local stop_opts
218 stop_opts=$(lttng stop --list-options)
219
220 case $cur in
221 -*)
222 COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
223 ;;
224 *)
225 _lttng_complete_sessions
226 ;;
227 esac
228}
229
230_lttng_cmd_version() {
231 local version_opts
232 version_opts=$(lttng version --list-options)
233
234 case $cur in
235 -*)
236 COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
237 ;;
238 esac
239}
240
241_lttng_cmd_calibrate() {
242 local calibrate_opts
243 calibrate_opts=$(lttng calibrate --list-options)
244
245 case $cur in
246 -*)
247 COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
248 ;;
249 esac
250}
251
0c95f5b2
DG
252_lttng_cmd_view() {
253 local view_opts
254 view_opts=$(lttng view --list-options)
255
256 case $cur in
257 -*)
258 COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
259 ;;
260 esac
261}
262
fc256d99
DG
263_lttng_opts() {
264 local opts
265 opts=$(lttng --list-options)
266
267 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
268}
269
270_lttng_commands() {
271 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
272}
273
274_lttng_before_command() {
275 # Check if the previous word should alter the behavior
276 case $prev in
277 --group|-g)
278 COMPREPLY=( $(compgen -g -- $cur) )
279 return
280 ;;
281 --sessiond-path)
282 _filedir
283 return
284 ;;
285 esac
286
287 case $cur in
288 -*)
289 # If the current word starts with a dash, complete with options
290 _lttng_opts
291 ;;
292 *)
293 # Otherwise complete with commands
294 _lttng_commands
295 ;;
296 esac
297}
298
299_lttng_after_command() {
300 local cmd_name
301
302 cmd_name=_lttng_cmd_${command//-/}
303
304 type -t $cmd_name | grep -q 'function' && $cmd_name
305}
306
307_lttng_is_command() {
308 for command in $commands; do
309 if [ "$1" == "$command" ]; then
310 return 0
311 fi
312 done
313
314 return 1
315}
316
317_lttng() {
318 local cur prev commands command_found command_found_index
319
320 # Get the current and previous word
321 _get_comp_words_by_ref cur prev
322
323 # Get the valid LTTng commands
324 commands=$(lttng --list-commands)
325
326 # The text of the found command
327 command_found=""
328
329 # The index of the found command in COMP_WORDS
330 command_found_index=-1
331
332 for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
333 _lttng_is_command ${COMP_WORDS[$i]}
334 if [ $? -eq 0 ]; then
335 command_found=${COMP_WORDS[$i]}
336 command_found_index=$i
337 break
338 fi
339
340 done
341
342 # Check if the cursor is before or after the command keyword
343 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
344 _lttng_after_command
345 else
346 _lttng_before_command
347 fi
348}
349
350complete -F _lttng lttng
This page took 0.040252 seconds and 4 git commands to generate.