Cleanup list command printout for loglevel
[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
252_lttng_opts() {
253 local opts
254 opts=$(lttng --list-options)
255
256 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
257}
258
259_lttng_commands() {
260 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
261}
262
263_lttng_before_command() {
264 # Check if the previous word should alter the behavior
265 case $prev in
266 --group|-g)
267 COMPREPLY=( $(compgen -g -- $cur) )
268 return
269 ;;
270 --sessiond-path)
271 _filedir
272 return
273 ;;
274 esac
275
276 case $cur in
277 -*)
278 # If the current word starts with a dash, complete with options
279 _lttng_opts
280 ;;
281 *)
282 # Otherwise complete with commands
283 _lttng_commands
284 ;;
285 esac
286}
287
288_lttng_after_command() {
289 local cmd_name
290
291 cmd_name=_lttng_cmd_${command//-/}
292
293 type -t $cmd_name | grep -q 'function' && $cmd_name
294}
295
296_lttng_is_command() {
297 for command in $commands; do
298 if [ "$1" == "$command" ]; then
299 return 0
300 fi
301 done
302
303 return 1
304}
305
306_lttng() {
307 local cur prev commands command_found command_found_index
308
309 # Get the current and previous word
310 _get_comp_words_by_ref cur prev
311
312 # Get the valid LTTng commands
313 commands=$(lttng --list-commands)
314
315 # The text of the found command
316 command_found=""
317
318 # The index of the found command in COMP_WORDS
319 command_found_index=-1
320
321 for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
322 _lttng_is_command ${COMP_WORDS[$i]}
323 if [ $? -eq 0 ]; then
324 command_found=${COMP_WORDS[$i]}
325 command_found_index=$i
326 break
327 fi
328
329 done
330
331 # Check if the cursor is before or after the command keyword
332 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
333 _lttng_after_command
334 else
335 _lttng_before_command
336 fi
337}
338
339complete -F _lttng lttng
This page took 0.034034 seconds and 4 git commands to generate.