2 # Copyright (c) - 2012 Simon Marchi <simon.marchi@polymtl.ca>
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.
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
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.
18 _lttng_complete_sessions() {
19 # TODO, maybe have a lttng list --simple or something like that
23 _lttng_cmd_add_context() {
24 local add_context_opts
25 add_context_opts=$(lttng add-context --list-options)
29 _lttng_complete_sessions
45 COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
53 create_opts=$(lttng create --list-options)
64 COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) )
70 _lttng_cmd_destroy() {
72 destroy_opts=$(lttng destroy --list-options)
76 COMPREPLY=( $(compgen -W "${destroy_opts}" -- $cur) )
79 _lttng_complete_sessions
84 _lttng_cmd_enablechannel() {
85 local enable_channel_opts
86 enable_channel_opts=$(lttng enable-channel --list-options)
90 _lttng_complete_sessions
97 COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
103 _lttng_cmd_enableevent() {
104 local enable_event_opts
105 enable_event_opts=$(lttng enable-event --list-options)
109 _lttng_complete_sessions
125 COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
131 _lttng_cmd_enableconsumer() {
132 local enable_consumer_opts
133 enable_consumer_opts=$(lttng enable-consumer --list-options)
137 _lttng_complete_sessions
144 COMPREPLY=( $(compgen -W "${enable_consumer_opts}" -- $cur) )
150 _lttng_cmd_disableconsumer() {
151 local disable_consumer_opts
152 disable_consumer_opts=$(lttng disable-consumer --list-options)
156 _lttng_complete_sessions
163 COMPREPLY=( $(compgen -W "${disable_consumer_opts}" -- $cur) )
169 _lttng_cmd_disablechannel() {
170 local disable_channel_opts
171 disable_channel_opts=$(lttng disable-channel --list-options)
175 _lttng_complete_sessions
182 COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
188 _lttng_cmd_disable_event() {
189 local disable_event_opts
190 disable_channel_opts=$(lttng disable-event --list-options)
194 _lttng_complete_sessions
204 COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
212 list_opts=$(lttng list --list-options)
222 COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
228 _lttng_cmd_set_session() {
229 local set_session_opts
230 set_session_opts=$(lttng set-session --list-options)
234 COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
242 start_opts=$(lttng start --list-options)
246 COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
249 _lttng_complete_sessions
256 stop_opts=$(lttng stop --list-options)
260 COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
263 _lttng_complete_sessions
268 _lttng_cmd_version() {
270 version_opts=$(lttng version --list-options)
274 COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
279 _lttng_cmd_calibrate() {
281 calibrate_opts=$(lttng calibrate --list-options)
285 COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
292 view_opts=$(lttng view --list-options)
296 COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
303 opts=$(lttng --list-options)
305 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
309 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
312 _lttng_before_command() {
313 # Check if the previous word should alter the behavior
316 COMPREPLY=( $(compgen -g -- $cur) )
327 # If the current word starts with a dash, complete with options
331 # Otherwise complete with commands
337 _lttng_after_command() {
340 cmd_name=_lttng_cmd_${command//-/}
342 type -t $cmd_name | grep -q 'function' && $cmd_name
345 _lttng_is_command() {
346 for command in $commands; do
347 if [ "$1" == "$command" ]; then
356 local cur prev commands command_found command_found_index
358 # Get the current and previous word
359 _get_comp_words_by_ref cur prev
361 # Get the valid LTTng commands
362 commands=$(lttng --list-commands)
364 # The text of the found command
367 # The index of the found command in COMP_WORDS
368 command_found_index=-1
370 for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
371 _lttng_is_command ${COMP_WORDS[$i]}
372 if [ $? -eq 0 ]; then
373 command_found=${COMP_WORDS[$i]}
374 command_found_index=$i
380 # Check if the cursor is before or after the command keyword
381 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
384 _lttng_before_command
388 complete -F _lttng lttng