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