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_addcontext() {
24 local add_context_opts
25 add_context_opts=$(lttng add-context --list-options)
29 _lttng_complete_sessions
42 COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
50 create_opts=$(lttng create --list-options)
61 COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) )
67 _lttng_cmd_destroy() {
69 destroy_opts=$(lttng destroy --list-options)
73 COMPREPLY=( $(compgen -W "${destroy_opts}" -- $cur) )
76 _lttng_complete_sessions
81 _lttng_cmd_enablechannel() {
82 local enable_channel_opts
83 enable_channel_opts=$(lttng enable-channel --list-options)
87 _lttng_complete_sessions
94 COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
100 _lttng_cmd_enableevent() {
101 local enable_event_opts
102 enable_event_opts=$(lttng enable-event --list-options)
106 _lttng_complete_sessions
122 COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
128 _lttng_cmd_enableconsumer() {
129 local enable_consumer_opts
130 enable_consumer_opts=$(lttng enable-consumer --list-options)
134 _lttng_complete_sessions
141 COMPREPLY=( $(compgen -W "${enable_consumer_opts}" -- $cur) )
147 _lttng_cmd_disableconsumer() {
148 local disable_consumer_opts
149 disable_consumer_opts=$(lttng disable-consumer --list-options)
153 _lttng_complete_sessions
160 COMPREPLY=( $(compgen -W "${disable_consumer_opts}" -- $cur) )
166 _lttng_cmd_disablechannel() {
167 local disable_channel_opts
168 disable_channel_opts=$(lttng disable-channel --list-options)
172 _lttng_complete_sessions
179 COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
185 _lttng_cmd_disableevent() {
186 local disable_event_opts
187 disable_channel_opts=$(lttng disable-event --list-options)
191 _lttng_complete_sessions
201 COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
209 list_opts=$(lttng list --list-options)
219 COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
225 _lttng_cmd_setsession() {
226 local set_session_opts
227 set_session_opts=$(lttng set-session --list-options)
231 COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
239 start_opts=$(lttng start --list-options)
243 COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
246 _lttng_complete_sessions
253 stop_opts=$(lttng stop --list-options)
257 COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
260 _lttng_complete_sessions
265 _lttng_cmd_version() {
267 version_opts=$(lttng version --list-options)
271 COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
276 _lttng_cmd_calibrate() {
278 calibrate_opts=$(lttng calibrate --list-options)
282 COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
289 view_opts=$(lttng view --list-options)
293 COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
300 opts=$(lttng --list-options)
302 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
306 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
309 _lttng_before_command() {
310 # Check if the previous word should alter the behavior
313 COMPREPLY=( $(compgen -g -- $cur) )
324 # If the current word starts with a dash, complete with options
328 # Otherwise complete with commands
334 _lttng_after_command() {
337 cmd_name=_lttng_cmd_${command//-/}
339 type -t $cmd_name | grep -q 'function' && $cmd_name
342 _lttng_is_command() {
343 for command in $commands; do
344 if [ "$1" == "$command" ]; then
353 local cur prev commands command_found command_found_index
355 # Get the current and previous word
356 _get_comp_words_by_ref cur prev
358 # Get the valid LTTng commands
359 commands=$(lttng --list-commands)
361 # The text of the found command
364 # The index of the found command in COMP_WORDS
365 command_found_index=-1
367 for (( i = 1 ; i < ${#COMP_WORDS[@]} ; i++ )); do
368 _lttng_is_command ${COMP_WORDS[$i]}
369 if [ $? -eq 0 ]; then
370 command_found=${COMP_WORDS[$i]}
371 command_found_index=$i
377 # Check if the cursor is before or after the command keyword
378 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
381 _lttng_before_command
385 complete -F _lttng lttng