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() {
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.
24 COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
28 _lttng_cmd_addcontext() {
29 local add_context_opts
30 add_context_opts=$(lttng add-context --list-options)
34 _lttng_complete_sessions
47 COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
55 create_opts=$(lttng create --list-options)
66 COMPREPLY=( $(compgen -W "${create_opts}" -- $cur) )
72 _lttng_cmd_destroy() {
74 destroy_opts=$(lttng destroy --list-options)
78 COMPREPLY=( $(compgen -W "${destroy_opts}" -- $cur) )
81 _lttng_complete_sessions
86 _lttng_cmd_enablechannel() {
87 local enable_channel_opts
88 enable_channel_opts=$(lttng enable-channel --list-options)
92 _lttng_complete_sessions
99 COMPREPLY=( $(compgen -W "${enable_channel_opts}" -- $cur) )
105 _lttng_cmd_enableevent() {
106 local enable_event_opts
107 enable_event_opts=$(lttng enable-event --list-options)
111 _lttng_complete_sessions
127 COMPREPLY=( $(compgen -W "${enable_event_opts}" -- $cur) )
133 _lttng_cmd_disablechannel() {
134 local disable_channel_opts
135 disable_channel_opts=$(lttng disable-channel --list-options)
139 _lttng_complete_sessions
146 COMPREPLY=( $(compgen -W "${disable_channel_opts}" -- $cur) )
152 _lttng_cmd_disableevent() {
153 local disable_event_opts
154 disable_event_opts=$(lttng disable-event --list-options)
158 _lttng_complete_sessions
168 COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
176 list_opts=$(lttng list --list-options)
186 COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
190 _lttng_complete_sessions
195 _lttng_cmd_setsession() {
196 local set_session_opts
197 set_session_opts=$(lttng set-session --list-options)
201 COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
205 _lttng_complete_sessions
213 start_opts=$(lttng start --list-options)
217 COMPREPLY=( $(compgen -W "${start_opts}" -- $cur) )
220 _lttng_complete_sessions
227 stop_opts=$(lttng stop --list-options)
231 COMPREPLY=( $(compgen -W "${stop_opts}" -- $cur) )
234 _lttng_complete_sessions
239 _lttng_cmd_version() {
241 version_opts=$(lttng version --list-options)
245 COMPREPLY=( $(compgen -W "${version_opts}" -- $cur) )
250 _lttng_cmd_calibrate() {
252 calibrate_opts=$(lttng calibrate --list-options)
256 COMPREPLY=( $(compgen -W "${calibrate_opts}" -- $cur) )
263 view_opts=$(lttng view --list-options)
267 COMPREPLY=( $(compgen -W "${view_opts}" -- $cur) )
274 opts=$(lttng --list-options)
276 COMPREPLY=( $(compgen -W "${opts}" -- $cur) )
280 COMPREPLY=( $(compgen -W "$commands" -- $cur) )
283 _lttng_before_command() {
284 # Check if the previous word should alter the behavior
287 COMPREPLY=( $(compgen -g -- $cur) )
298 # If the current word starts with a dash, complete with options
302 # Otherwise complete with commands
308 _lttng_after_command() {
311 cmd_name=_lttng_cmd_${command//-/}
313 type -t $cmd_name | grep -q 'function' && $cmd_name
316 _lttng_is_command() {
317 for command in $commands; do
318 if [ "$1" == "$command" ]; then
327 local cur prev commands command_found command_found_index
329 # Get the current and previous word
330 _get_comp_words_by_ref cur prev
332 # Get the valid LTTng commands
333 commands=$(lttng --list-commands)
335 # The text of the found command
338 # The index of the found command in COMP_WORDS
339 command_found_index=-1
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
351 # Check if the cursor is before or after the command keyword
352 if [ -n "$command_found" ] && [ "$COMP_CWORD" -gt "$command_found_index" ]; then
355 _lttng_before_command
359 complete -F _lttng lttng