diff mbox series

[3/3] trace-cmd completion: Add instance completion for -B

Message ID 20210417004637.3899514-4-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit f15ef5801d9c8ae42f998098fa3d1ead26364dd9
Headers show
Series trace-cmd: Updated bash tab completion | expand

Commit Message

Steven Rostedt April 17, 2021, 12:46 a.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

All commands but trace-cmd list use -B for instances. Since the list
command already has its own logic, make the default logic for all other
commands search the instances when -B is the previous command to complete.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-cmd.bash | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-cmd.bash b/tracecmd/trace-cmd.bash
index 9b0703b7..b01c7a07 100644
--- a/tracecmd/trace-cmd.bash
+++ b/tracecmd/trace-cmd.bash
@@ -225,7 +225,8 @@  __trace_cmd_dump_complete()
 __show_command_options()
 {
     local command="$1"
-    local cur="$2"
+    local prev="$2"
+    local cur="$3"
     local cmds=( $(trace-cmd --help 2>/dev/null | \
 		    grep " - " | sed 's/^ *//; s/ -.*//') )
 
@@ -233,7 +234,15 @@  __show_command_options()
 	if [ $cmd == "$command" ]; then
 	    local opts=$(trace-cmd $cmd -h 2>/dev/null|grep "^ *-" | \
 				 sed -e 's/ *\(-[^ ]*\).*/\1/')
-	    COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
+	    if [ "$prev" == "-B" ]; then
+		for opt in ${opts[@]}; do
+		    if [ "$opt" == "-B" ]; then
+			show_instances "$cur"
+			return 0
+		    fi
+		done
+	    fi
+	    COMPREPLY=( $(compgen -W "${opts}" -- "$cur"))
 	    return 0
 	fi
     done
@@ -290,7 +299,7 @@  _trace_cmd_complete()
 	    return 0
 	    ;;
         *)
-	    __show_command_options "$w" "${cur}"
+	    __show_command_options "$w" "${prev}" "${cur}"
             ;;
     esac
 }