Improve bash completion with the use of mi and xmllint
authorJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Thu, 17 Jul 2014 18:13:20 +0000 (14:13 -0400)
committerJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Tue, 22 Jul 2014 20:14:57 +0000 (16:14 -0400)
Signed-off-by: Jonathan Rajotte Julien <jonathan.r.julien@gmail.com>
README
extras/lttng-bash_completion

diff --git a/README b/README
index 3e594a52c617dde18bc833717f1d1cc8beb6768b..716ae1f8a7f53744bd7022247d7d5c20eec53303 100644 (file)
--- a/README
+++ b/README
@@ -182,5 +182,6 @@ PACKAGE CONTENTS:
       Various documentations and quickstart guide.
 
     - extras
-      Contains extra data such as bash completion file. Python bindings for
-      liblttng-ctl are also available there.
+      Contains extra data such as bash completion file.
+               Note: the presence of xmllint is required for bash-completion.
+         Python bindings for liblttng-ctl are also available there.
index f5677e9bcef70f532867b490d6927bd805db6139..335e9d128454fe3da1b5312624c9d8515b54c0d1 100644 (file)
 
 # 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 |  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 | 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 | 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 | 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() {
@@ -178,12 +202,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.026462 seconds and 4 git commands to generate.