2 # LTTng Trace Control bash completion
5 _lttng_complete_sessions
() {
7 if ! _complete_as_root
; then
8 sessions
=$
(for i
in $
(ls -d ~
/.lttng
/*/); do basename $i; done)
9 COMPREPLY
=( $
(compgen
-W "${sessions}" -- $cur) )
11 # Permission denied, what should we do ?
12 # sessions=$(for i in $(ls -d ~root/.lttng/*/); do basename $i; done)
13 #COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
19 create_opts
="-h --help -o --output"
30 COMPREPLY
=( $
(compgen
-W "${create_opts}" -- $cur) )
38 start_stop_opts
="-h --help"
42 COMPREPLY
=( $
(compgen
-W "${start_stop_opts}" -- $cur) )
45 _lttng_complete_sessions
52 opts
=$
(lttng
--dump-options)
54 COMPREPLY
=( $
(compgen
-W "${opts}" -- $cur) )
58 COMPREPLY
=( $
(compgen
-W "$commands" -- $cur) )
61 _lttng_before_command
() {
62 # Check if the previous word should alter the behavior
65 COMPREPLY
=( $
(compgen
-g -- $cur) )
72 # If the current word starts with a dash, complete with options
76 # Otherwise complete with commands
82 _lttng_after_command
() {
83 case $command_found in
94 for command in $commands; do
95 if [ "$1" == "$command" ]; then
104 local cur prev commands command_found command_found_index
106 cur
="${COMP_WORDS[COMP_CWORD]}"
107 prev
="${COMP_WORDS[COMP_CWORD-1]}"
108 commands
=$
(lttng
--dump-commands)
111 command_found_index
=-1
113 for (( i
= 1 ; i
< ${#COMP_WORDS[@]} ; i
++ )); do
114 _lttng_is_command
${COMP_WORDS[$i]}
115 if [ $?
-eq 0 ]; then
116 command_found
=${COMP_WORDS[$i]}
117 command_found_index
=$i
123 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
126 _lttng_before_command
130 complete
-F _lttng lttng