From 1ba6e01782fd2a94481e18b91b363636f8171565 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 4 Jul 2013 18:11:25 +0530 Subject: perf completion: Don't dictate perf install location The statement have perf limits the locations in which to look for the perf program. Moreover, it depends on the bash-completion package to be installed. Replace it with a call to `type perf`. Signed-off-by: Ramkumar Ramachandra Cc: Frederic Weisbecker Link: http://lkml.kernel.org/r/1372941691-14684-2-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/bash_completion') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index 56e6a12aab59..50540cfe3d18 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -19,7 +19,7 @@ __ltrim_colon_completions() fi } -have perf && +type perf &>/dev/null && _perf() { local cur prev cmd -- cgit v1.2.3 From 30079d1d5ebcb8d706c6e05cacebb7facc60cd95 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 4 Jul 2013 18:11:26 +0530 Subject: perf completion: Update __ltrim_colon_completions The function is taken from the bash-completion package; update it to use the latest version where colon_word doesn't miss quoting. Signed-off-by: Ramkumar Ramachandra Cc: Frederic Weisbecker Link: http://lkml.kernel.org/r/1372941691-14684-3-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/bash_completion') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index 50540cfe3d18..b0cdd12bd5e4 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -11,7 +11,7 @@ __ltrim_colon_completions() { if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then # Remove colon-word prefix from COMPREPLY items - local colon_word=${1%${1##*:}} + local colon_word=${1%"${1##*:}"} local i=${#COMPREPLY[*]} while [[ $((--i)) -ge 0 ]]; do COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"} -- cgit v1.2.3 From 7b6c48e16e5d312b0ebae78acfb3ff4f9c8c083c Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 4 Jul 2013 18:11:27 +0530 Subject: perf completion: Strip dependency on _filedir _filedir is defined in the bash-completion package, but there is no need to depend on it. Instead, call complete with multiple -o arguments before the -F argument like in git.git's completion script. Signed-off-by: Ramkumar Ramachandra Cc: Frederic Weisbecker Link: http://lkml.kernel.org/r/1372941691-14684-4-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tools/perf/bash_completion') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index b0cdd12bd5e4..d2598be517fb 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -54,9 +54,8 @@ _perf() subcmd=${COMP_WORDS[1]} opts=$($cmd $subcmd --list-opts) COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) ) - # Fall down to list regular files - else - _filedir fi } && -complete -F _perf perf + +complete -o bashdefault -o default -o nospace -F _perf perf 2>/dev/null \ + || complete -o default -o nospace -F _perf perf -- cgit v1.2.3 From 4685a6cfaeac6d2fe8ed10a9aa0cbff5026529cb Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 4 Jul 2013 18:11:29 +0530 Subject: perf completion: Strip function_exists () Use "type" to check existence consistently. Signed-off-by: Ramkumar Ramachandra Cc: Frederic Weisbecker Link: http://lkml.kernel.org/r/1372941691-14684-6-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tools/perf/bash_completion') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index d2598be517fb..35fdda1540d8 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -1,12 +1,6 @@ # perf completion -function_exists() -{ - declare -F $1 > /dev/null - return $? -} - -function_exists __ltrim_colon_completions || +type __ltrim_colon_completions &>/dev/null || __ltrim_colon_completions() { if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then -- cgit v1.2.3 From c3fb6717e90049b93d0f5f5714a4d878799d89c2 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 4 Jul 2013 18:11:30 +0530 Subject: perf completion: Strip dependency on bash-completion The bash-completion package defines the _get_comp_words_by_ref function. There is no need to depend on it, as we can reimplement it like git.git has. Signed-off-by: Ramkumar Ramachandra Cc: Frederic Weisbecker Cc: Namhyung Kim Link: http://lkml.kernel.org/r/1372941691-14684-7-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 83 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 6 deletions(-) (limited to 'tools/perf/bash_completion') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index 35fdda1540d8..ee9c6d85f2c9 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -1,5 +1,81 @@ # perf completion +# Taken from git.git's completion script. +__my_reassemble_comp_words_by_ref() +{ + local exclude i j first + # Which word separators to exclude? + exclude="${1//[^$COMP_WORDBREAKS]}" + cword_=$COMP_CWORD + if [ -z "$exclude" ]; then + words_=("${COMP_WORDS[@]}") + return + fi + # List of word completion separators has shrunk; + # re-assemble words to complete. + for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + # Append each nonempty word consisting of just + # word separator characters to the current word. + first=t + while + [ $i -gt 0 ] && + [ -n "${COMP_WORDS[$i]}" ] && + # word consists of excluded word separators + [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] + do + # Attach to the previous token, + # unless the previous token is the command name. + if [ $j -ge 2 ] && [ -n "$first" ]; then + ((j--)) + fi + first= + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + if (($i < ${#COMP_WORDS[@]} - 1)); then + ((i++)) + else + # Done. + return + fi + done + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + done +} + +type _get_comp_words_by_ref &>/dev/null || +_get_comp_words_by_ref() +{ + local exclude cur_ words_ cword_ + if [ "$1" = "-n" ]; then + exclude=$2 + shift 2 + fi + __my_reassemble_comp_words_by_ref "$exclude" + cur_=${words_[cword_]} + while [ $# -gt 0 ]; do + case "$1" in + cur) + cur=$cur_ + ;; + prev) + prev=${words_[$cword_-1]} + ;; + words) + words=("${words_[@]}") + ;; + cword) + cword=$cword_ + ;; + esac + shift + done +} + type __ltrim_colon_completions &>/dev/null || __ltrim_colon_completions() { @@ -19,12 +95,7 @@ _perf() local cur prev cmd COMPREPLY=() - if function_exists _get_comp_words_by_ref; then - _get_comp_words_by_ref -n : cur prev - else - cur=$(_get_cword :) - prev=${COMP_WORDS[COMP_CWORD-1]} - fi + _get_comp_words_by_ref -n : cur prev cmd=${COMP_WORDS[0]} -- cgit v1.2.3 From 6e0dc374a2c912a8a967ea8a4f9696dd4b0a6d3e Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Thu, 4 Jul 2013 18:11:31 +0530 Subject: perf completion: Use more comp words The completion words $words and $cword are available, so we might as well use them instead of directly accessing COMP_WORDS. Signed-off-by: Ramkumar Ramachandra Cc: Frederic Weisbecker Link: http://lkml.kernel.org/r/1372941691-14684-8-git-send-email-artagnon@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bash_completion | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/perf/bash_completion') diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion index ee9c6d85f2c9..62e157db2e2b 100644 --- a/tools/perf/bash_completion +++ b/tools/perf/bash_completion @@ -92,15 +92,15 @@ __ltrim_colon_completions() type perf &>/dev/null && _perf() { - local cur prev cmd + local cur words cword prev cmd COMPREPLY=() - _get_comp_words_by_ref -n : cur prev + _get_comp_words_by_ref -n =: cur words cword prev - cmd=${COMP_WORDS[0]} + cmd=${words[0]} # List perf subcommands or long options - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then if [[ $cur == --* ]]; then COMPREPLY=( $( compgen -W '--help --version \ --exec-path --html-path --paginate --no-pager \ @@ -110,13 +110,13 @@ _perf() COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) ) fi # List possible events for -e option - elif [[ $prev == "-e" && "${COMP_WORDS[1]}" == @(record|stat|top) ]]; then + elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then evts=$($cmd list --raw-dump) COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) ) __ltrim_colon_completions $cur # List long option names elif [[ $cur == --* ]]; then - subcmd=${COMP_WORDS[1]} + subcmd=${words[1]} opts=$($cmd $subcmd --list-opts) COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) ) fi -- cgit v1.2.3