linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] zsh support for perf completion
@ 2013-11-17 16:13 Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 1/5] perf completion: introduce a layer of indirection Ramkumar Ramachandra
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Ramkumar Ramachandra @ 2013-11-17 16:13 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Arnaldo Carvalho de Melo

Hi,

I'm pleased to announce zsh support for the perf completion script,
added this lazy Sunday afternoon. I'm not very good at shell
scripting, so these patches can definitely use more eyes. Frankly, I'm
mildly surprised that this hack even works: please test carefully and
report bugs.

[1/5] to [3/5] factors things out and prepares the stage for [4/5],
which is the focus of the series. [5/5] is just a pure rename.

Thanks.

Ramkumar Ramachandra (5):
  perf completion: introduce a layer of indirection
  perf completion: factor out compgen stuff
  perf completion: factor out call to __ltrim_colon_completions
  perf completion: introduce zsh support
  perf completion: rename file to reflect zsh support

 tools/perf/{bash_completion => perf-completion.sh} | 100 ++++++++++++++++++---
 1 file changed, 88 insertions(+), 12 deletions(-)
 rename tools/perf/{bash_completion => perf-completion.sh} (65%)

-- 
1.8.5.rc0.6.gfd75b41


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

* [PATCH 1/5] perf completion: introduce a layer of indirection
  2013-11-17 16:13 [PATCH 0/5] zsh support for perf completion Ramkumar Ramachandra
@ 2013-11-17 16:13 ` Ramkumar Ramachandra
  2013-11-30 12:49   ` [tip:perf/core] perf completion: Introduce " tip-bot for Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 2/5] perf completion: factor out compgen stuff Ramkumar Ramachandra
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Ramkumar Ramachandra @ 2013-11-17 16:13 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Ingo Molnar

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


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

* [PATCH 2/5] perf completion: factor out compgen stuff
  2013-11-17 16:13 [PATCH 0/5] zsh support for perf completion Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 1/5] perf completion: introduce a layer of indirection Ramkumar Ramachandra
@ 2013-11-17 16:13 ` Ramkumar Ramachandra
  2013-11-30 12:49   ` [tip:perf/core] perf completion: Factor " tip-bot for Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 3/5] perf completion: factor out call to __ltrim_colon_completions Ramkumar Ramachandra
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Ramkumar Ramachandra @ 2013-11-17 16:13 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Ingo Molnar

compgen is a bash-builtin; factor out the invocations into a separate
function to give us a chance to override it with a zsh equivalent in
future patches.

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 | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 3efdc84..82431268 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -89,6 +89,11 @@ __ltrim_colon_completions()
 	fi
 }
 
+__perfcomp ()
+{
+	COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
+}
+
 __perf_main ()
 {
 	local cmd
@@ -99,23 +104,23 @@ __perf_main ()
 	# List perf subcommands or long options
 	if [ $cword -eq 1 ]; then
 		if [[ $cur == --* ]]; then
-			COMPREPLY=( $( compgen -W '--help --version \
+			__perfcomp '--help --version \
 			--exec-path --html-path --paginate --no-pager \
-			--perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
+			--perf-dir --work-tree --debugfs-dir' -- "$cur"
 		else
 			cmds=$($cmd --list-cmds)
-			COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
+			__perfcomp "$cmds" "$cur"
 		fi
 	# List possible events for -e option
 	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
-		COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
+		__perfcomp "$evts" "$cur"
 		__ltrim_colon_completions $cur
 	# List long option names
 	elif [[ $cur == --* ]];  then
 		subcmd=${words[1]}
 		opts=$($cmd $subcmd --list-opts)
-		COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
+		__perfcomp "$opts" "$cur"
 	fi
 }
 
-- 
1.8.5.rc0.6.gfd75b41


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

* [PATCH 3/5] perf completion: factor out call to __ltrim_colon_completions
  2013-11-17 16:13 [PATCH 0/5] zsh support for perf completion Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 1/5] perf completion: introduce a layer of indirection Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 2/5] perf completion: factor out compgen stuff Ramkumar Ramachandra
@ 2013-11-17 16:13 ` Ramkumar Ramachandra
  2013-11-30 12:49   ` [tip:perf/core] perf completion: Factor " tip-bot for Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 4/5] perf completion: introduce zsh support Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 5/5] perf completion: rename file to reflect " Ramkumar Ramachandra
  4 siblings, 1 reply; 11+ messages in thread
From: Ramkumar Ramachandra @ 2013-11-17 16:13 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Ingo Molnar

In our sole callsite, __ltrim_colon_completions is called after
__perfcomp, to modify the COMPREPLY set by the invocation. This is
problematic, because in the zsh equivalent (using compset/ compadd),
we'll have to generate completions in one-shot. So factor out this
entire callsite into a special override'able __perfcomp_colon function;
we will override it when introducing 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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 82431268..573599b 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -94,6 +94,12 @@ __perfcomp ()
 	COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
 }
 
+__perfcomp_colon ()
+{
+	__perfcomp "$1" "$2"
+	__ltrim_colon_completions $cur
+}
+
 __perf_main ()
 {
 	local cmd
@@ -114,8 +120,7 @@ __perf_main ()
 	# List possible events for -e option
 	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
-		__perfcomp "$evts" "$cur"
-		__ltrim_colon_completions $cur
+		__perfcomp_colon "$evts" "$cur"
 	# List long option names
 	elif [[ $cur == --* ]];  then
 		subcmd=${words[1]}
-- 
1.8.5.rc0.6.gfd75b41


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

* [PATCH 4/5] perf completion: introduce zsh support
  2013-11-17 16:13 [PATCH 0/5] zsh support for perf completion Ramkumar Ramachandra
                   ` (2 preceding siblings ...)
  2013-11-17 16:13 ` [PATCH 3/5] perf completion: factor out call to __ltrim_colon_completions Ramkumar Ramachandra
@ 2013-11-17 16:13 ` Ramkumar Ramachandra
  2013-11-30 12:50   ` [tip:perf/core] perf completion: Introduce " tip-bot for Ramkumar Ramachandra
  2013-11-17 16:13 ` [PATCH 5/5] perf completion: rename file to reflect " Ramkumar Ramachandra
  4 siblings, 1 reply; 11+ messages in thread
From: Ramkumar Ramachandra @ 2013-11-17 16:13 UTC (permalink / raw)
  To: LKML
  Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim,
	Frederic Weisbecker, Ingo Molnar

__perfcomp(), __perfcomp_colon(), and _perf() have to be
overridden. Inspired by the way the git.git completion system is
structured.

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
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 | 63 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 573599b..4949488 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -1,4 +1,4 @@
-# perf completion
+# perf bash and zsh completion
 
 # Taken from git.git's completion script.
 __my_reassemble_comp_words_by_ref()
@@ -129,6 +129,67 @@ __perf_main ()
 	fi
 }
 
+if [[ -n ${ZSH_VERSION-} ]]; then
+	autoload -U +X compinit && compinit
+
+	__perfcomp ()
+	{
+		emulate -L zsh
+
+		local c IFS=$' \t\n'
+		local -a array
+
+		for c in ${=1}; do
+			case $c in
+			--*=*|*.) ;;
+			*) c="$c " ;;
+			esac
+			array[${#array[@]}+1]="$c"
+		done
+
+		compset -P '*[=:]'
+		compadd -Q -S '' -a -- array && _ret=0
+	}
+
+	__perfcomp_colon ()
+	{
+		emulate -L zsh
+
+		local cur_="${2-$cur}"
+		local c IFS=$' \t\n'
+		local -a array
+
+		if [[ "$cur_" == *:* ]]; then
+			local colon_word=${cur_%"${cur_##*:}"}
+		fi
+
+		for c in ${=1}; do
+			case $c in
+			--*=*|*.) ;;
+			*) c="$c " ;;
+			esac
+			array[$#array+1]=${c#"$colon_word"}
+		done
+
+		compset -P '*[=:]'
+		compadd -Q -S '' -a -- array && _ret=0
+	}
+
+	_perf ()
+	{
+		local _ret=1 cur cword prev
+		cur=${words[CURRENT]}
+		prev=${words[CURRENT-1]}
+		let cword=CURRENT-1
+		emulate ksh -c __perf_main
+		let _ret && _default && _ret=0
+		return _ret
+	}
+
+	compdef _perf perf
+	return
+fi
+
 type perf &>/dev/null &&
 _perf()
 {
-- 
1.8.5.rc0.6.gfd75b41


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

* [PATCH 5/5] perf completion: rename file to reflect zsh support
  2013-11-17 16:13 [PATCH 0/5] zsh support for perf completion Ramkumar Ramachandra
                   ` (3 preceding siblings ...)
  2013-11-17 16:13 ` [PATCH 4/5] perf completion: introduce zsh support Ramkumar Ramachandra
@ 2013-11-17 16:13 ` Ramkumar Ramachandra
  2013-11-30 12:50   ` [tip:perf/core] perf completion: Rename " tip-bot for Ramkumar Ramachandra
  4 siblings, 1 reply; 11+ messages in thread
From: Ramkumar Ramachandra @ 2013-11-17 16:13 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Ingo Molnar

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 => perf-completion.sh} | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename tools/perf/{bash_completion => perf-completion.sh} (100%)

diff --git a/tools/perf/bash_completion b/tools/perf/perf-completion.sh
similarity index 100%
rename from tools/perf/bash_completion
rename to tools/perf/perf-completion.sh
-- 
1.8.5.rc0.6.gfd75b41


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

* [tip:perf/core] perf completion: Introduce a layer of indirection
  2013-11-17 16:13 ` [PATCH 1/5] perf completion: introduce a layer of indirection Ramkumar Ramachandra
@ 2013-11-30 12:49   ` tip-bot for Ramkumar Ramachandra
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Ramkumar Ramachandra @ 2013-11-30 12:49 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, artagnon, tglx

Commit-ID:  2cf025e69543f5f4aa68e8549d60680515fef5ad
Gitweb:     http://git.kernel.org/tip/2cf025e69543f5f4aa68e8549d60680515fef5ad
Author:     Ramkumar Ramachandra <artagnon@gmail.com>
AuthorDate: Sun, 17 Nov 2013 21:43:23 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Nov 2013 14:58:35 -0300

perf completion: Introduce a layer of indirection

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.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1384704807-15779-2-git-send-email-artagnon@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.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 \

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

* [tip:perf/core] perf completion: Factor out compgen stuff
  2013-11-17 16:13 ` [PATCH 2/5] perf completion: factor out compgen stuff Ramkumar Ramachandra
@ 2013-11-30 12:49   ` tip-bot for Ramkumar Ramachandra
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Ramkumar Ramachandra @ 2013-11-30 12:49 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, artagnon, tglx

Commit-ID:  12f9dd5042483698c74a133d9004ff1d1a6474f9
Gitweb:     http://git.kernel.org/tip/12f9dd5042483698c74a133d9004ff1d1a6474f9
Author:     Ramkumar Ramachandra <artagnon@gmail.com>
AuthorDate: Sun, 17 Nov 2013 21:43:24 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Nov 2013 14:58:35 -0300

perf completion: Factor out compgen stuff

compgen is a bash-builtin; factor out the invocations into a separate
function to give us a chance to override it with a zsh equivalent in
future patches.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1384704807-15779-3-git-send-email-artagnon@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/bash_completion | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 3efdc84..82431268 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -89,6 +89,11 @@ __ltrim_colon_completions()
 	fi
 }
 
+__perfcomp ()
+{
+	COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
+}
+
 __perf_main ()
 {
 	local cmd
@@ -99,23 +104,23 @@ __perf_main ()
 	# List perf subcommands or long options
 	if [ $cword -eq 1 ]; then
 		if [[ $cur == --* ]]; then
-			COMPREPLY=( $( compgen -W '--help --version \
+			__perfcomp '--help --version \
 			--exec-path --html-path --paginate --no-pager \
-			--perf-dir --work-tree --debugfs-dir' -- "$cur" ) )
+			--perf-dir --work-tree --debugfs-dir' -- "$cur"
 		else
 			cmds=$($cmd --list-cmds)
-			COMPREPLY=( $( compgen -W '$cmds' -- "$cur" ) )
+			__perfcomp "$cmds" "$cur"
 		fi
 	# List possible events for -e option
 	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
-		COMPREPLY=( $( compgen -W '$evts' -- "$cur" ) )
+		__perfcomp "$evts" "$cur"
 		__ltrim_colon_completions $cur
 	# List long option names
 	elif [[ $cur == --* ]];  then
 		subcmd=${words[1]}
 		opts=$($cmd $subcmd --list-opts)
-		COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
+		__perfcomp "$opts" "$cur"
 	fi
 }
 

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

* [tip:perf/core] perf completion: Factor out call to __ltrim_colon_completions
  2013-11-17 16:13 ` [PATCH 3/5] perf completion: factor out call to __ltrim_colon_completions Ramkumar Ramachandra
@ 2013-11-30 12:49   ` tip-bot for Ramkumar Ramachandra
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Ramkumar Ramachandra @ 2013-11-30 12:49 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, artagnon, tglx

Commit-ID:  37e72c31061521d6f0e4b7fe47cd5748280ed691
Gitweb:     http://git.kernel.org/tip/37e72c31061521d6f0e4b7fe47cd5748280ed691
Author:     Ramkumar Ramachandra <artagnon@gmail.com>
AuthorDate: Sun, 17 Nov 2013 21:43:25 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Nov 2013 14:58:35 -0300

perf completion: Factor out call to __ltrim_colon_completions

In our sole callsite, __ltrim_colon_completions is called after
__perfcomp, to modify the COMPREPLY set by the invocation.

This is problematic, because in the zsh equivalent (using compset/
compadd), we'll have to generate completions in one-shot.

So factor out this entire callsite into a special override'able
__perfcomp_colon function; we will override it when introducing zsh
support.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1384704807-15779-4-git-send-email-artagnon@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/bash_completion | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 82431268..573599b 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -94,6 +94,12 @@ __perfcomp ()
 	COMPREPLY=( $( compgen -W "$1" -- "$2" ) )
 }
 
+__perfcomp_colon ()
+{
+	__perfcomp "$1" "$2"
+	__ltrim_colon_completions $cur
+}
+
 __perf_main ()
 {
 	local cmd
@@ -114,8 +120,7 @@ __perf_main ()
 	# List possible events for -e option
 	elif [[ $prev == "-e" && "${words[1]}" == @(record|stat|top) ]]; then
 		evts=$($cmd list --raw-dump)
-		__perfcomp "$evts" "$cur"
-		__ltrim_colon_completions $cur
+		__perfcomp_colon "$evts" "$cur"
 	# List long option names
 	elif [[ $cur == --* ]];  then
 		subcmd=${words[1]}

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

* [tip:perf/core] perf completion: Introduce zsh support
  2013-11-17 16:13 ` [PATCH 4/5] perf completion: introduce zsh support Ramkumar Ramachandra
@ 2013-11-30 12:50   ` tip-bot for Ramkumar Ramachandra
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Ramkumar Ramachandra @ 2013-11-30 12:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, namhyung, fweisbec, tglx, artagnon

Commit-ID:  f38ab8af794c184c15f5e001d0eaa16f4a120978
Gitweb:     http://git.kernel.org/tip/f38ab8af794c184c15f5e001d0eaa16f4a120978
Author:     Ramkumar Ramachandra <artagnon@gmail.com>
AuthorDate: Sun, 17 Nov 2013 21:43:26 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Nov 2013 14:58:35 -0300

perf completion: Introduce zsh support

__perfcomp(), __perfcomp_colon(), and _perf() have to be overridden.
Inspired by the way the git.git completion system is structured.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1384704807-15779-5-git-send-email-artagnon@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/bash_completion | 63 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/tools/perf/bash_completion b/tools/perf/bash_completion
index 573599b..4949488 100644
--- a/tools/perf/bash_completion
+++ b/tools/perf/bash_completion
@@ -1,4 +1,4 @@
-# perf completion
+# perf bash and zsh completion
 
 # Taken from git.git's completion script.
 __my_reassemble_comp_words_by_ref()
@@ -129,6 +129,67 @@ __perf_main ()
 	fi
 }
 
+if [[ -n ${ZSH_VERSION-} ]]; then
+	autoload -U +X compinit && compinit
+
+	__perfcomp ()
+	{
+		emulate -L zsh
+
+		local c IFS=$' \t\n'
+		local -a array
+
+		for c in ${=1}; do
+			case $c in
+			--*=*|*.) ;;
+			*) c="$c " ;;
+			esac
+			array[${#array[@]}+1]="$c"
+		done
+
+		compset -P '*[=:]'
+		compadd -Q -S '' -a -- array && _ret=0
+	}
+
+	__perfcomp_colon ()
+	{
+		emulate -L zsh
+
+		local cur_="${2-$cur}"
+		local c IFS=$' \t\n'
+		local -a array
+
+		if [[ "$cur_" == *:* ]]; then
+			local colon_word=${cur_%"${cur_##*:}"}
+		fi
+
+		for c in ${=1}; do
+			case $c in
+			--*=*|*.) ;;
+			*) c="$c " ;;
+			esac
+			array[$#array+1]=${c#"$colon_word"}
+		done
+
+		compset -P '*[=:]'
+		compadd -Q -S '' -a -- array && _ret=0
+	}
+
+	_perf ()
+	{
+		local _ret=1 cur cword prev
+		cur=${words[CURRENT]}
+		prev=${words[CURRENT-1]}
+		let cword=CURRENT-1
+		emulate ksh -c __perf_main
+		let _ret && _default && _ret=0
+		return _ret
+	}
+
+	compdef _perf perf
+	return
+fi
+
 type perf &>/dev/null &&
 _perf()
 {

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

* [tip:perf/core] perf completion: Rename file to reflect zsh support
  2013-11-17 16:13 ` [PATCH 5/5] perf completion: rename file to reflect " Ramkumar Ramachandra
@ 2013-11-30 12:50   ` tip-bot for Ramkumar Ramachandra
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Ramkumar Ramachandra @ 2013-11-30 12:50 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: acme, linux-kernel, hpa, mingo, artagnon, tglx

Commit-ID:  a8b4c7014cadfdacd4e1f4c963128593be6f20de
Gitweb:     http://git.kernel.org/tip/a8b4c7014cadfdacd4e1f4c963128593be6f20de
Author:     Ramkumar Ramachandra <artagnon@gmail.com>
AuthorDate: Sun, 17 Nov 2013 21:43:27 +0530
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Nov 2013 14:58:35 -0300

perf completion: Rename file to reflect zsh support

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1384704807-15779-6-git-send-email-artagnon@gmail.com
[ Fix 'make install' target ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Makefile.perf                           | 4 ++--
 tools/perf/{bash_completion => perf-completion.sh} | 0
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 7fc8f17..e416ccc 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -840,9 +840,9 @@ ifndef NO_LIBPYTHON
 		$(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python'; \
 		$(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin'
 endif
-	$(call QUIET_INSTALL, bash_completion-script) \
+	$(call QUIET_INSTALL, perf_completion-script) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \
-		$(INSTALL) bash_completion '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
+		$(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'
 	$(call QUIET_INSTALL, tests) \
 		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
 		$(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
diff --git a/tools/perf/bash_completion b/tools/perf/perf-completion.sh
similarity index 100%
rename from tools/perf/bash_completion
rename to tools/perf/perf-completion.sh

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

end of thread, other threads:[~2013-11-30 12:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-17 16:13 [PATCH 0/5] zsh support for perf completion Ramkumar Ramachandra
2013-11-17 16:13 ` [PATCH 1/5] perf completion: introduce a layer of indirection Ramkumar Ramachandra
2013-11-30 12:49   ` [tip:perf/core] perf completion: Introduce " tip-bot for Ramkumar Ramachandra
2013-11-17 16:13 ` [PATCH 2/5] perf completion: factor out compgen stuff Ramkumar Ramachandra
2013-11-30 12:49   ` [tip:perf/core] perf completion: Factor " tip-bot for Ramkumar Ramachandra
2013-11-17 16:13 ` [PATCH 3/5] perf completion: factor out call to __ltrim_colon_completions Ramkumar Ramachandra
2013-11-30 12:49   ` [tip:perf/core] perf completion: Factor " tip-bot for Ramkumar Ramachandra
2013-11-17 16:13 ` [PATCH 4/5] perf completion: introduce zsh support Ramkumar Ramachandra
2013-11-30 12:50   ` [tip:perf/core] perf completion: Introduce " tip-bot for Ramkumar Ramachandra
2013-11-17 16:13 ` [PATCH 5/5] perf completion: rename file to reflect " Ramkumar Ramachandra
2013-11-30 12:50   ` [tip:perf/core] perf completion: Rename " tip-bot for Ramkumar Ramachandra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).