Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/3] trace-cmd: Updated bash tab completion
@ 2021-04-17  0:46 Steven Rostedt
  2021-04-17  0:46 ` [PATCH 1/3] trace-cmd record: Add bash tab completion for -A Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-04-17  0:46 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Played a bit with tab completion to fix some of the annoyances I've had,
and wanted with tab completion.

Steven Rostedt (VMware) (3):
  trace-cmd record: Add bash tab completion for -A
  trace-cmd record: Update -e event bash tab completion
  trace-cmd completion: Add instance completion for -B

 tracecmd/trace-cmd.bash | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] trace-cmd record: Add bash tab completion for -A
  2021-04-17  0:46 [PATCH 0/3] trace-cmd: Updated bash tab completion Steven Rostedt
@ 2021-04-17  0:46 ` Steven Rostedt
  2021-04-17  0:46 ` [PATCH 2/3] trace-cmd record: Update -e event bash tab completion Steven Rostedt
  2021-04-17  0:46 ` [PATCH 3/3] trace-cmd completion: Add instance completion for -B Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-04-17  0:46 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add a virsh lookup of guest names when -A is the option for trace-cmd
record and tab is done.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-cmd.bash | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/tracecmd/trace-cmd.bash b/tracecmd/trace-cmd.bash
index 85f6743b..e89c1a55 100644
--- a/tracecmd/trace-cmd.bash
+++ b/tracecmd/trace-cmd.bash
@@ -9,6 +9,17 @@ show_instances()
    return 0
 }
 
+show_virt()
+{
+    local cur="$1"
+    if ! which virsh &>/dev/null; then
+	return 1
+    fi
+    local virt=`virsh list | awk '/^ *[0-9]/ { print $2 }'`
+    COMPREPLY=( $(compgen -W "${virt}" -- "${cur}") )
+    return 0
+}
+
 show_options()
 {
    local cur="$1"
@@ -159,6 +170,11 @@ __trace_cmd_record_complete()
 	-O)
 	    show_options "$cur"
 	    ;;
+	-A)
+	    if ! show_virt "$cur"; then
+		cmd_options record "$cur"
+	    fi
+	    ;;
         *)
 	    # stream start and profile do not show all options
 	    cmd_options record "$cur"
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] trace-cmd record: Update -e event bash tab completion
  2021-04-17  0:46 [PATCH 0/3] trace-cmd: Updated bash tab completion Steven Rostedt
  2021-04-17  0:46 ` [PATCH 1/3] trace-cmd record: Add bash tab completion for -A Steven Rostedt
@ 2021-04-17  0:46 ` Steven Rostedt
  2021-04-17  0:46 ` [PATCH 3/3] trace-cmd completion: Add instance completion for -B Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-04-17  0:46 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Update the tab completion to find events instead of needing to know the
systems.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tracecmd/trace-cmd.bash | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tracecmd/trace-cmd.bash b/tracecmd/trace-cmd.bash
index e89c1a55..9b0703b7 100644
--- a/tracecmd/trace-cmd.bash
+++ b/tracecmd/trace-cmd.bash
@@ -142,10 +142,16 @@ __trace_cmd_record_complete()
 
     case "$prev" in
         -e)
-            local events=$(trace-cmd list -e)
+	    local list=$(trace-cmd list -e "$cur")
             local prefix=${cur%%:*}
+	    if [ -z "$cur" -o  "$cur" != "$prefix" ]; then
+		COMPREPLY=( $(compgen -W "all ${list}" -- "${cur}") )
+	    else
+		local events=$(for e in $list; do echo ${e/*:/}; done | sort -u)
+	        local systems=$(for s in $list; do echo ${s/:*/:}; done | sort -u)
 
-            COMPREPLY=( $(compgen -W "${events}" -- "${cur}") )
+		COMPREPLY=( $(compgen -W "all ${events} ${systems}" -- "${cur}") )
+	    fi
 
             # This is still to handle the "*:*" special case
             if [[ -n "$prefix" ]]; then
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] trace-cmd completion: Add instance completion for -B
  2021-04-17  0:46 [PATCH 0/3] trace-cmd: Updated bash tab completion Steven Rostedt
  2021-04-17  0:46 ` [PATCH 1/3] trace-cmd record: Add bash tab completion for -A Steven Rostedt
  2021-04-17  0:46 ` [PATCH 2/3] trace-cmd record: Update -e event bash tab completion Steven Rostedt
@ 2021-04-17  0:46 ` Steven Rostedt
  2 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2021-04-17  0:46 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

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 --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
 }
-- 
2.29.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-17  0:46 [PATCH 0/3] trace-cmd: Updated bash tab completion Steven Rostedt
2021-04-17  0:46 ` [PATCH 1/3] trace-cmd record: Add bash tab completion for -A Steven Rostedt
2021-04-17  0:46 ` [PATCH 2/3] trace-cmd record: Update -e event bash tab completion Steven Rostedt
2021-04-17  0:46 ` [PATCH 3/3] trace-cmd completion: Add instance completion for -B Steven Rostedt

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git