perf tools: Bash completion update
Namhyung Kim
maintainercover perf tools: Bash completion update
Hi,
This patchset improves bash completion support for perf tools. Some option names are really painful to type so here comes a support for completing those long option names. But I still think the --showcpuutilization option needs to be renamed (at least adding a couple of dashes in it).
Thanks,
Namhyung
Namhyung Kim (3):
perf tools: Check existence of _get_comp_words_by_ref when bash completing perf tools: Complete long option names of perf command
perf tools: Long option completion support for each subcommands
tools/perf/bash_completion | 36 +++++++++++++++++++++++++++++------- tools/perf/util/parse-options.c | 8 ++++++++ tools/perf/util/parse-options.h | 1 + 3 files changed, 38 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 1/3 perf tools: Check existence of _get_comp_words_by_ref when bash completing
The '_get_comp_words_by_ref' function is available from the bash completion v1.2 so that earlier version emits following warning:
$ perf re<TAB>_get_comp_words_by_ref: command not found
Use older '_get_cword' method when the above function doesn't exist.
--- tools/perf/bash_completion | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
tools/perf/bash_completion +13 -2
@@ -1,12 +1,23 @@ # perf completion +function_exists() +{ + declare -F $1 > /dev/null + return $? +} + have perf && _perf() { - local cur cmd + local cur prev cmd COMPREPLY=() - _get_comp_words_by_ref cur prev + if function_exists _get_comp_words_by_ref; then + _get_comp_words_by_ref cur prev + else + cur=$(_get_cword) + prev=${COMP_WORDS[COMP_CWORD-1]} + fi cmd=${COMP_WORDS[0]}
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 3/3 perf tools: Long option completion support for each subcommands
In reply to Namhyung KimAdd internal --list-opts option to print all of long option names to stdout so that it can be used for bash completion engine.
--- tools/perf/bash_completion | 9 +++++++-- tools/perf/util/parse-options.c | 8 ++++++++ tools/perf/util/parse-options.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-)
tools/perf/bash_completion +7 -2
@@ -33,8 +33,13 @@ _perf() fi # List possible events for -e option elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then - cmds=$($cmd list --raw-dump) - COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + evts=$($cmd list --raw-dump) + COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) ) + # List long option names + elif [[ $cur == --* ]]; then + subcmd=${COMP_WORDS[1]} + opts=$($cmd $subcmd --list-opts) + COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) ) # Fall down to list regular files else _filedir
tools/perf/util/parse-options.c +8 -0
@@ -384,6 +384,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,return usage_with_options_internal (usagestr, options,1 );if (internal_help && !strcmp (arg +2 ,"help" ))return parse_options_usage (usagestr, options); +if (!strcmp (arg +2 ,"list-opts" )) +return PARSE_OPT_LIST ;switch (parse_long_opt (ctx, arg +2 , options)) {case -1 :return parse_options_usage (usagestr, options);
@@ -422,6 +424,12 @@ int parse_options(int argc, const char **argv, const struct option *options,exit (129 );case PARSE_OPT_DONE :break ; +case PARSE_OPT_LIST : +while (options->type !=OPTION_END ) { +printf ("--%s " , options->long_name); + options++; + } +exit (130 );default :/* PARSE_OPT_UNKNOWN */ if (ctx.argv[0 ][1 ] =='-' ) {error ("unknown option `%s'" , ctx.argv[0 ] +2 );
tools/perf/util/parse-options.h +1 -0
@@ -140,6 +140,7 @@ extern NORETURN void usage_with_options(const char * const *usagestr,enum {PARSE_OPT_HELP =-1 ,PARSE_OPT_DONE , +PARSE_OPT_LIST ,PARSE_OPT_UNKNOWN , };
Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerPATCH 2/3 perf tools: Complete long option names of perf command
In reply to Namhyung KimThe main perf binary can receive a number of options that configure working environment. Add them to the completion script.
--- tools/perf/bash_completion | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
tools/perf/bash_completion +9 -3
@@ -21,10 +21,16 @@ _perf() cmd=${COMP_WORDS[0]} - # List perf subcommands + # List perf subcommands or long options if [ $COMP_CWORD -eq 1 ]; then - cmds=$($cmd --list-cmds) - COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + if [[ $cur == --* ]]; then + COMPREPLY=( $( compgen -W '--help --version \ + --exec-path --html-path --paginate --no-pager \ + --perf-dir --work-tree --debugfs-dir' -- "$cur" ) ) + else + cmds=$($cmd --list-cmds) + COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + fi # List possible events for -e option elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then cmds=$($cmd list --raw-dump)
Signature · 1 line
1.7.9.2
Re: [PATCH 1/3] perf tools: Check existence of _get_comp_words_by_ref when bash completing
In reply to Namhyung KimQuoted 6 lines · Namhyung Kim
The '
_get_comp_words_by_ref' function is available from the bash completion v1.2 so that earlier version emits following warning:$ perf re<TAB>_get_comp_words_by_ref: command not foundUse older '
_get_cword' method when the above function doesn't exist.
May be only use _get_cword then, if it works everywhere?
Quoted 41 lines
Cc Frederic Weisbecker <[email protected]>Cc David Ahern <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/bash_completion | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)tools/perf/bash_completion +13
-2@@ -1,12 +1,23 @@ # perf completion +function_exists() +{ + declare -F $1 > /dev/null + return $? +} + have perf && _perf() { - local cur cmd + local cur prev cmd COMPREPLY=() - _get_comp_words_by_ref cur prev + if function_exists _get_comp_words_by_ref; then + _get_comp_words_by_ref cur prev + else + cur=$(_get_cword) + prev=${COMP_WORDS[COMP_CWORD-1]} + fi cmd=${COMP_WORDS[0]}Signature · 1 line
1.7.9.2
Quoted 10 lines · Namhyung Kim
Hi,
This patchset improves bash completion support for perf tools. Some option names are really painful to type so here comes a support for completing those long option names. But I still think the --showcpuutilization option needs to be renamed (at least adding a couple of dashes in it).
Thanks,
Namhyung
Thanks Namhyung!
Quoted 15 lines
Namhyung Kim (3):
perf tools: Check existence of_get_comp_words_by_refwhen bash completing perf tools: Complete long option names of perf command
perf tools: Long option completion support for each subcommandstools/perf/bash_completion | 36 +++++++++++++++++++++++++++++------- tools/perf/util/parse-options.c | 8 ++++++++ tools/perf/util/parse-options.h | 1 + 3 files changed, 38 insertions(+), 7 deletions(-)Signature · 1 line
1.7.9.2
Namhyung Kim
maintainerRe: [PATCH 1/3] perf tools: Check existence of _get_comp_words_by_ref when bash completing
In reply to Frederic WeisbeckerHi Frederic,
Quoted 9 lines · Frederic Weisbecker
Quoted 6 lines · Namhyung Kim
The '
_get_comp_words_by_ref' function is available from the bash completion v1.2 so that earlier version emits following warning:$ perf re<TAB>_get_comp_words_by_ref: command not foundUse older '
_get_cword' method when the above function doesn't exist.May be only use
_get_cwordthen, if it works everywhere?
It'll work but it's deprecated.
Thanks,
Namhyung
Re: [PATCH 1/3] perf tools: Check existence of _get_comp_words_by_ref when bash completing
Quoted 7 lines · Namhyung Kim
Hi Frederic,
Quoted 4 lines · Frederic Weisbecker
Quoted 3 lines · Namhyung Kim
The '
_get_comp_words_by_ref' function is available from the bash completion v1.2 so that earlier version emits following warning:
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
$ perf re<TAB>_get_comp_words_by_ref: command not foundUse older '
_get_cword' method when the above function doesn't exist.May be only use
_get_cwordthen, if it works everywhere?It'll work but it's deprecated.
Ok.
tip-bot for Namhyung Kim
maintainer[tip:perf/urgent] perf tools: Check existence of _get_comp_words_by_ref when bash completing
In reply to Namhyung KimCommit-ID: a1d668c3ffd38d611f8446615e8f797dcfdfc397 Gitweb: http://git.kernel.org/tip/a1d668c3ffd38d611f8446615e8f797dcfdfc397 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 3 Oct 2012 00:21:32 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 2 Oct 2012 18:36:42 -0300
perf tools: Check existence of _get_comp_words_by_ref when bash completing
The '_get_comp_words_by_ref' function is available from the bash completion v1.2 so that earlier version emits following warning:
$ perf re<TAB>_get_comp_words_by_ref: command not found
Use older '_get_cword' method when the above function doesn't exist.
--- tools/perf/bash_completion | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/bash_completion +13 -2
@@ -1,12 +1,23 @@ # perf completion +function_exists() +{ + declare -F $1 > /dev/null + return $? +} + have perf && _perf() { - local cur cmd + local cur prev cmd COMPREPLY=() - _get_comp_words_by_ref cur prev + if function_exists _get_comp_words_by_ref; then + _get_comp_words_by_ref cur prev + else + cur=$(_get_cword) + prev=${COMP_WORDS[COMP_CWORD-1]} + fi cmd=${COMP_WORDS[0]}
tip-bot for Namhyung Kim
maintainer[tip:perf/urgent] perf tools: Complete long option names of perf command
In reply to Namhyung KimCommit-ID: 35c2fde1155cc7225361edf43d8efd0aabd28a0c Gitweb: http://git.kernel.org/tip/35c2fde1155cc7225361edf43d8efd0aabd28a0c Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 3 Oct 2012 00:21:33 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 2 Oct 2012 18:36:43 -0300
perf tools: Complete long option names of perf command
The main perf binary can receive a number of options that configure working environment. Add them to the completion script.
--- tools/perf/bash_completion | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
tools/perf/bash_completion +9 -3
@@ -21,10 +21,16 @@ _perf() cmd=${COMP_WORDS[0]} - # List perf subcommands + # List perf subcommands or long options if [ $COMP_CWORD -eq 1 ]; then - cmds=$($cmd --list-cmds) - COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + if [[ $cur == --* ]]; then + COMPREPLY=( $( compgen -W '--help --version \ + --exec-path --html-path --paginate --no-pager \ + --perf-dir --work-tree --debugfs-dir' -- "$cur" ) ) + else + cmds=$($cmd --list-cmds) + COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + fi # List possible events for -e option elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then cmds=$($cmd list --raw-dump)
tip-bot for Namhyung Kim
maintainer[tip:perf/urgent] perf tools: Long option completion support for each subcommands
In reply to Namhyung KimCommit-ID: 4d8061faca7a50010f037374410f0c3647c3ecf8 Gitweb: http://git.kernel.org/tip/4d8061faca7a50010f037374410f0c3647c3ecf8 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 3 Oct 2012 00:21:34 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 2 Oct 2012 18:36:44 -0300
perf tools: Long option completion support for each subcommands
Add internal --list-opts option to print all of long option names to stdout so that it can be used for bash completion engine.
--- tools/perf/bash_completion | 9 +++++++-- tools/perf/util/parse-options.c | 8 ++++++++ tools/perf/util/parse-options.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-)
tools/perf/bash_completion +7 -2
@@ -33,8 +33,13 @@ _perf() fi # List possible events for -e option elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then - cmds=$($cmd list --raw-dump) - COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) + evts=$($cmd list --raw-dump) + COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) ) + # List long option names + elif [[ $cur == --* ]]; then + subcmd=${COMP_WORDS[1]} + opts=$($cmd $subcmd --list-opts) + COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) ) # Fall down to list regular files else _filedir
tools/perf/util/parse-options.c +8 -0
@@ -384,6 +384,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,return usage_with_options_internal (usagestr, options,1 );if (internal_help && !strcmp (arg +2 ,"help" ))return parse_options_usage (usagestr, options); +if (!strcmp (arg +2 ,"list-opts" )) +return PARSE_OPT_LIST ;switch (parse_long_opt (ctx, arg +2 , options)) {case -1 :return parse_options_usage (usagestr, options);
@@ -422,6 +424,12 @@ int parse_options(int argc, const char **argv, const struct option *options,exit (129 );case PARSE_OPT_DONE :break ; +case PARSE_OPT_LIST : +while (options->type !=OPTION_END ) { +printf ("--%s " , options->long_name); + options++; + } +exit (130 );default :/* PARSE_OPT_UNKNOWN */ if (ctx.argv[0 ][1 ] =='-' ) {error ("unknown option `%s'" , ctx.argv[0 ] +2 );
tools/perf/util/parse-options.h +1 -0
@@ -140,6 +140,7 @@ extern NORETURN void usage_with_options(const char * const *usagestr,enum {PARSE_OPT_HELP =-1 ,PARSE_OPT_DONE , +PARSE_OPT_LIST ,PARSE_OPT_UNKNOWN , };