trace-cmd: Updated bash tab completion
cover trace-cmd: Updated bash tab completion
From: "Steven Rostedt (VMware)" <[email protected]>
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(-)
Signature · 1 line
2.29.2
PATCH 1/3 trace-cmd record: Add bash tab completion for -A
From: "Steven Rostedt (VMware)" <[email protected]>
Add a virsh lookup of guest names when -A is the option for trace-cmd record and tab is done.
--- tracecmd/trace-cmd.bash | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tracecmd/trace-cmd.bash +16 -0
@@ -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"
Signature · 1 line
2.29.2
PATCH 2/3 trace-cmd record: Update -e event bash tab completion
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Update the tab completion to find events instead of needing to know the systems.
--- tracecmd/trace-cmd.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tracecmd/trace-cmd.bash +8 -2
@@ -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
Signature · 1 line
2.29.2
PATCH 3/3 trace-cmd completion: Add instance completion for -B
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
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.
--- tracecmd/trace-cmd.bash | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
tracecmd/trace-cmd.bash +12 -3
@@ -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 }
Signature · 1 line
2.29.2