test: utils: lttng_pgrep performs lookup on non-existing pid
[lttng-tools.git] / extras / lttng-bash_completion
index f5677e9bcef70f532867b490d6927bd805db6139..458748de11f36e599e51e0436964f4b7a03002b5 100644 (file)
@@ -1,30 +1,43 @@
 #
-# Copyright (c) - 2012 Simon Marchi <simon.marchi@polymtl.ca>
+# Copyright (C) 2012 Simon Marchi <simon.marchi@polymtl.ca>A
 #
-# This program is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by as published by
-# the Free Software Foundation; only version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# SPDX-License-Identifier: GPL-2.0-only
 #
 
 # Generates COMPREPLY with the existing session names
 _lttng_complete_sessions() {
-       # TODO
-       # This code does nothing for now. When there is a mecanism to get the
-       # existing sessions, use it to fill the sessions variable.
        local sessions
-       sessions=""
+       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')
        COMPREPLY=( $(compgen -W "${sessions}" -- $cur) )
        return
 }
+#
+
+# Generates COMPREPLY with the available kernel event
+_lttng_complete_kernel_events() {
+       local kernel_event
+       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")
+       COMPREPLY=( $(compgen -W "${kernel_event}" -- $cur) )
+       return
+}
+
+# Generates COMPREPLY with the available ust event
+_lttng_complete_ust_events() {
+       local ust_event
+       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")
+       COMPREPLY=( $(compgen -W "${ust_event}" -- $cur) )
+       return
+}
+
+# Generates COMPREPLY with the available jul event
+_lttng_complete_jul_events() {
+       local jul_event
+       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")
+       COMPREPLY=( $(compgen -W "${jul_event}" -- $cur) )
+       return
+}
+
+
 
 # Generates COMPREPLY with whatever is in the $options variable.
 _lttng_complete_options() {
@@ -60,17 +73,6 @@ _lttng_cmd_addcontext() {
        esac
 }
 
-_lttng_cmd_calibrate() {
-       options=$(lttng calibrate --list-options)
-
-       case $cur in
-       -*)
-               _lttng_complete_options
-               return
-               ;;
-       esac
-}
-
 _lttng_cmd_create() {
        options=$(lttng create --list-options)
 
@@ -178,12 +180,32 @@ _lttng_cmd_enableevent() {
                ;;
        esac
 
+
+       #Check if we want kernel event completion
+       if [[ "$COMP_LINE" == *"-k"* ]]; then
+               _lttng_complete_kernel_events
+               return
+       fi
+
+       #Check if we want ust event completion
+       if [[ "$COMP_LINE" == *"-u"* ]]; then
+               _lttng_complete_ust_events
+               return
+       fi
+
+       #Check if we want jul event completion
+       if [[ "$COMP_LINE" == *"-j"* ]]; then
+               _lttng_complete_jul_events
+               return
+       fi
+
        case $cur in
        -*)
                _lttng_complete_options
                return
                ;;
        esac
+
 }
 
 _lttng_cmd_list() {
This page took 0.02452 seconds and 4 git commands to generate.