[PATCH 1/5] perf completion: introduce a layer of indirection

Ramkumar Ramachandra
2013-11-17T16:22:31Z

Define the variables cur, words, cword, and prev outside the main
completion function so that we have a chance to override it when we
introduce zsh support.

Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
tools/perf/bash_completion | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 62e157db..3efdc84 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -89,15 +89,12 @@ __ltrim_colon_completions()
fi
}

-type perf &>/dev/null &&
-_perf()
+__perf_main ()
{
- local cur words cword prev cmd
-
- COMPREPLY=()
- _get_comp_words_by_ref -n =: cur words cword prev
+ local cmd

cmd=${words[0]}
+ COMPREPLY=()

# List perf subcommands or long options
if [ $cword -eq 1 ]; then
@@ -120,6 +117,14 @@ _perf()
opts=$($cmd $subcmd --list-opts)
COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
fi
+}
+
+type perf &>/dev/null &&
+_perf()
+{
+ local cur words cword prev
+ _get_comp_words_by_ref -n =: cur words cword prev
+ __perf_main
} &&

complete -o bashdefault -o default -o nospace -F _perf perf 2>/dev/null \
--
1.8.5.rc0.6.gfd75b41