Fix: sessiond: ust-app: uninitialized name logged on stream copy failure
[lttng-tools.git] / extras / lttng-bash_completion
CommitLineData
fc256d99 1#
90c106c6 2# Copyright (C) 2012 EfficiOS Inc.
fc256d99 3#
ab5be9fa 4# SPDX-License-Identifier: GPL-2.0-only
fc256d99
DG
5#
6
ba28686d 7# Generates COMPREPLY with the existing session names
fc256d99 8_lttng_complete_sessions() {
4a096a5b 9 local sessions
7f65573e 10 sessions=$(lttng --mi xml list | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/sessions/session/name" - 2>/dev/null | sed -e 's/<name>//g' -e $'s/<\/name>/\\n/g')
4a096a5b 11 COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
fc256d99
DG
12 return
13}
7335fad6
JRJ
14#
15
16# Generates COMPREPLY with the available kernel event
17_lttng_complete_kernel_events() {
18 local kernel_event
7f65573e 19 kernel_event=$(lttng --mi xml list -k |sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'KERNEL']/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
7335fad6
JRJ
20 COMPREPLY=( $(compgen -W "${kernel_event}" -- $cur) )
21 return
22}
23
24# Generates COMPREPLY with the available ust event
25_lttng_complete_ust_events() {
26 local ust_event
7f65573e 27 ust_event=$(lttng --mi xml list -u | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'UST']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
7335fad6
JRJ
28 COMPREPLY=( $(compgen -W "${ust_event}" -- $cur) )
29 return
30}
31
32# Generates COMPREPLY with the available jul event
33_lttng_complete_jul_events() {
34 local jul_event
7f65573e 35 jul_event=$(lttng --mi xml list -j | sed '2 s/xmlns/ignore/g' | xmllint --xpath "//command/output/domains/domain[./type = 'JUL']/pids/pid/events/event/name" - 2>/dev/null | sed -e "s/<name>//g" -e $"s/<\/name>/\\n/g")
7335fad6
JRJ
36 COMPREPLY=( $(compgen -W "${jul_event}" -- $cur) )
37 return
38}
39
40
fc256d99 41
ba28686d
SM
42# Generates COMPREPLY with whatever is in the $options variable.
43_lttng_complete_options() {
44 COMPREPLY=( $(compgen -W "${options}" -- $cur) )
45}
46
47# Generates COMPREPLY with whatever is in the $commands variable.
48_lttng_complete_commands() {
49 COMPREPLY=( $(compgen -W "${commands}" -- $cur) )
50}
51
6c806062 52_lttng_cmd_addcontext() {
ba28686d 53 options=$(lttng add-context --list-options)
fc256d99
DG
54
55 case $prev in
56 --session|-s)
57 _lttng_complete_sessions
58 return
59 ;;
60 --channel|-c)
61 return
62 ;;
fc256d99
DG
63 --type|-t)
64 return
65 ;;
66 esac
67
68 case $cur in
69 -*)
ba28686d 70 _lttng_complete_options
fc256d99
DG
71 return
72 ;;
73 esac
74}
75
76_lttng_cmd_create() {
ba28686d 77 options=$(lttng create --list-options)
fc256d99
DG
78
79 case $prev in
80 --output|-o)
81 _filedir -d
82 return
83 ;;
84 esac
85
86 case $cur in
87 -*)
ba28686d 88 _lttng_complete_options
fc256d99
DG
89 return
90 ;;
91 esac
92}
93
94_lttng_cmd_destroy() {
ba28686d 95 options=$(lttng destroy --list-options)
fc256d99
DG
96
97 case $cur in
98 -*)
ba28686d
SM
99 _lttng_complete_options
100 return
fc256d99
DG
101 ;;
102 *)
103 _lttng_complete_sessions
ba28686d 104 return
fc256d99
DG
105 ;;
106 esac
107}
07bd6635 108_lttng_cmd_disablechannel() {
ba28686d 109 options=$(lttng disable-channel --list-options)
fc256d99
DG
110
111 case $prev in
112 --session|-s)
113 _lttng_complete_sessions
114 return
115 ;;
116 esac
117
118 case $cur in
119 -*)
ba28686d 120 _lttng_complete_options
fc256d99
DG
121 return
122 ;;
123 esac
124}
07bd6635 125_lttng_cmd_disableevent() {
ba28686d 126 options=$(lttng disable-event --list-options)
fc256d99
DG
127
128 case $prev in
129 --session|-s)
130 _lttng_complete_sessions
131 return
132 ;;
133 --channel|-c)
134 return
135 ;;
fc256d99
DG
136 esac
137
138 case $cur in
139 -*)
ba28686d 140 _lttng_complete_options
fc256d99
DG
141 return
142 ;;
143 esac
144}
145
07bd6635 146_lttng_cmd_enablechannel() {
ba28686d 147 options=$(lttng enable-channel --list-options)
fc256d99
DG
148
149 case $prev in
150 --session|-s)
151 _lttng_complete_sessions
152 return
153 ;;
154 esac
155
156 case $cur in
157 -*)
ba28686d 158 _lttng_complete_options
fc256d99
DG
159 return
160 ;;
161 esac
162}
163
07bd6635 164_lttng_cmd_enableevent() {
ba28686d 165 options=$(lttng enable-event --list-options)
fc256d99
DG
166
167 case $prev in
168 --session|-s)
169 _lttng_complete_sessions
170 return
171 ;;
172 --channel|-c)
173 return
174 ;;
07bd6635
SM
175 --probe)
176 return
177 ;;
178 --function)
179 return
180 ;;
fc256d99
DG
181 esac
182
7335fad6
JRJ
183
184 #Check if we want kernel event completion
185 if [[ "$COMP_LINE" == *"-k"* ]]; then
186 _lttng_complete_kernel_events
187 return
188 fi
189
190 #Check if we want ust event completion
191 if [[ "$COMP_LINE" == *"-u"* ]]; then
192 _lttng_complete_ust_events
193 return
194 fi
195
196 #Check if we want jul event completion
197 if [[ "$COMP_LINE" == *"-j"* ]]; then
198 _lttng_complete_jul_events
199 return
200 fi
201
fc256d99
DG
202 case $cur in
203 -*)
ba28686d 204 _lttng_complete_options
fc256d99
DG
205 return
206 ;;
207 esac
7335fad6 208
fc256d99
DG
209}
210
211_lttng_cmd_list() {
ba28686d 212 options=$(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 -*)
ba28686d 222 _lttng_complete_options
fc256d99
DG
223 return
224 ;;
4a096a5b
SM
225 *)
226 _lttng_complete_sessions
227 return
fc256d99
DG
228 esac
229}
230
6c806062 231_lttng_cmd_setsession() {
ba28686d 232 options=$(lttng set-session --list-options)
fc256d99
DG
233
234 case $cur in
235 -*)
ba28686d 236 _lttng_complete_options
fc256d99
DG
237 return
238 ;;
4a096a5b
SM
239 *)
240 _lttng_complete_sessions
241 return
242 ;;
fc256d99
DG
243 esac
244}
245
ba28686d
SM
246_lttng_cmd_snapshot() {
247 options=$(lttng snapshot --list-options)
248 commands=$(lttng snapshot --list-commands)
249
250 _lttng_find_command $((command_found_index + 1))
251
252 if _lttng_cursor_is_after_command; then
253 case $prev in
254 --session|-s)
255 _lttng_complete_sessions
256 return
257 ;;
258 esac
259
260 case $cur in
261 -*)
262 _lttng_complete_options
263 ;;
264 esac
265 else
266 _lttng_complete_commands
267 fi
268}
269
fc256d99 270_lttng_cmd_start() {
ba28686d 271 options=$(lttng start --list-options)
fc256d99
DG
272
273 case $cur in
274 -*)
ba28686d
SM
275 _lttng_complete_options
276 return
fc256d99
DG
277 ;;
278 *)
279 _lttng_complete_sessions
ba28686d 280 return
fc256d99
DG
281 ;;
282 esac
283}
284
285_lttng_cmd_stop() {
ba28686d 286 options=$(lttng stop --list-options)
fc256d99
DG
287
288 case $cur in
289 -*)
ba28686d 290 _lttng_complete_options
fc256d99
DG
291 ;;
292 *)
293 _lttng_complete_sessions
294 ;;
295 esac
296}
297
298_lttng_cmd_version() {
ba28686d 299 options=$(lttng version --list-options)
fc256d99
DG
300
301 case $cur in
302 -*)
ba28686d 303 _lttng_complete_options
fc256d99
DG
304 ;;
305 esac
306}
307
0c95f5b2 308_lttng_cmd_view() {
ba28686d 309 options=$(lttng view --list-options)
0c95f5b2 310
ba28686d
SM
311 case $cur in
312 -*)
313 _lttng_complete_options
0c95f5b2
DG
314 ;;
315 esac
316}
317
fc256d99 318
fc256d99
DG
319
320_lttng_before_command() {
321 # Check if the previous word should alter the behavior
322 case $prev in
323 --group|-g)
324 COMPREPLY=( $(compgen -g -- $cur) )
325 return
326 ;;
327 --sessiond-path)
328 _filedir
329 return
330 ;;
331 esac
332
333 case $cur in
334 -*)
335 # If the current word starts with a dash, complete with options
ba28686d 336 _lttng_complete_options
fc256d99
DG
337 ;;
338 *)
339 # Otherwise complete with commands
ba28686d 340 _lttng_complete_commands
fc256d99
DG
341 ;;
342 esac
343}
344
345_lttng_after_command() {
346 local cmd_name
347
ba28686d 348 cmd_name=_lttng_cmd_${command_found//-/}
fc256d99
DG
349
350 type -t $cmd_name | grep -q 'function' && $cmd_name
351}
352
ba28686d
SM
353# Check if the word passed as the first parameter corresponds to a
354# command. $command must be set to the list of possible commands.
fc256d99
DG
355_lttng_is_command() {
356 for command in $commands; do
357 if [ "$1" == "$command" ]; then
358 return 0
359 fi
360 done
361
362 return 1
363}
364
ba28686d
SM
365# Try to find a command in the current command line. Possible commands
366# are passed in $commands.
367#
368# This function takes an optional parameter that indicates the index
369# where to start the search in COMP_WORDS. If omitted, it defaults to 1.
370#
371# If a command is found, $command_found is filled with the name of the
372# command and $command_found_index is set to the index of the command in
373# $COMP_WORDS. If no command is found, $command_found is an empty string
374# and $command_found_index is set to -1.
375_lttng_find_command() {
376 start=${1:-1}
fc256d99
DG
377
378 # The text of the found command
379 command_found=""
380
381 # The index of the found command in COMP_WORDS
382 command_found_index=-1
383
ba28686d 384 for (( i = start ; i < ${#COMP_WORDS[@]} ; i++ )); do
fc256d99
DG
385 _lttng_is_command ${COMP_WORDS[$i]}
386 if [ $? -eq 0 ]; then
387 command_found=${COMP_WORDS[$i]}
388 command_found_index=$i
389 break
390 fi
fc256d99 391 done
ba28686d
SM
392}
393
394_lttng_cursor_is_after_command() {
395 [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]
396}
397
398_lttng() {
399 local cur prev commands command_found command_found_index
400
401 # Get the current and previous word
402 _get_comp_words_by_ref cur prev
403
404 # Get the valid first-level LTTng commands and options
405 commands=$(lttng --list-commands)
406 options=$(lttng --list-options)
407
408 _lttng_find_command
fc256d99
DG
409
410 # Check if the cursor is before or after the command keyword
ba28686d 411 if _lttng_cursor_is_after_command; then
fc256d99
DG
412 _lttng_after_command
413 else
414 _lttng_before_command
415 fi
416}
417
418complete -F _lttng lttng
This page took 0.064594 seconds and 4 git commands to generate.