Skip to contentSkip to conversation

Minor perf completion improvements

PATCH In review Ramkumar Ramachandra 4 participants 22 messages Jul 4, 2013 – Oct 15, 2013 perf events

lore
Share & tools
lore
#0 lore raw

cover Minor perf completion improvements

Hi,

So I just started using perf, and noticed the accompanying completion script. Having dabbled with git.git's completion script a bit, I thought I should contribute what I learnt from it.

[6/7] is the meat of the series, and the preceding patches work towards the same goal: to strip dependency on the bash-completion package.

Thanks.

Ramkumar Ramachandra (7):
perf completion: don't dictate perf install location perf completion: update __ltrim_colon_completions perf completion: strip dependency on _filedir perf completion: modernize style
perf completion: strip function_exists () perf completion: strip dependency on bash-completion perf completion: use more comp words

 tools/perf/bash_completion | 110 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 87 insertions(+), 23 deletions(-)
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#1 lore raw

PATCH 1/7 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.

---
 tools/perf/bash_completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/bash_completion +1 -1
index 56e6a12..50540cf 100644
@@ -19,7 +19,7 @@ __ltrim_colon_completions()
 	fi
 }
 
-have perf &&
+type perf &>/dev/null &&
 _perf()
 {
 	local cur prev cmd
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#2 lore raw

[tip:perf/core] perf completion: Don' t dictate perf install location

perf completion: Don't dictate perf install location
Commit-ID:  1ba6e01782fd2a94481e18b91b363636f8171565
Gitweb:     http://git.kernel.org/tip/1ba6e01782fd2a94481e18b91b363636f8171565
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Thu, 4 Jul 2013 18:11:25 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:11:40 -0300

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.

---
 tools/perf/bash_completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/bash_completion +1 -1
index 56e6a12..50540cf 100644
@@ -19,7 +19,7 @@ __ltrim_colon_completions()
 	fi
 }
 
-have perf &&
+type perf &>/dev/null &&
 _perf()
 {
 	local cur prev cmd
#3 lore raw

PATCH 2/7 perf completion: update __ltrim_colon_completions

In reply to Ramkumar Ramachandra

The function is taken from the bash-completion package; update it to use the latest version where colon_word doesn't miss quoting.

---
 tools/perf/bash_completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/bash_completion +1 -1
index 50540cf..b0cdd12 100644
@@ -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"}
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#4 lore raw

[tip:perf/core] perf completion: Update __ltrim_colon_completions

perf completion: Update __ltrim_colon_completions
Commit-ID:  30079d1d5ebcb8d706c6e05cacebb7facc60cd95
Gitweb:     http://git.kernel.org/tip/30079d1d5ebcb8d706c6e05cacebb7facc60cd95
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Thu, 4 Jul 2013 18:11:26 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:11:48 -0300

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.

---
 tools/perf/bash_completion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/bash_completion +1 -1
index 50540cf..b0cdd12 100644
@@ -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"}
#5 lore raw

PATCH 3/7 perf completion: strip dependency on _filedir

In reply to Ramkumar Ramachandra

_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.

---
 tools/perf/bash_completion | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/bash_completion +3 -4
index b0cdd12..d2598be 100644
@@ -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
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#6 lore raw

[tip:perf/core] perf completion: Strip dependency on _filedir

perf completion: Strip dependency on _filedir
Commit-ID:  7b6c48e16e5d312b0ebae78acfb3ff4f9c8c083c
Gitweb:     http://git.kernel.org/tip/7b6c48e16e5d312b0ebae78acfb3ff4f9c8c083c
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Thu, 4 Jul 2013 18:11:27 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:11:55 -0300

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.

---
 tools/perf/bash_completion | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/perf/bash_completion +3 -4
index b0cdd12..d2598be 100644
@@ -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
#7 lore raw

PATCH 4/7 perf completion: modernize style

In reply to Ramkumar Ramachandra
---
 tools/perf/bash_completion | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bash_completion +2 -2
index d2598be..8c04f5d 100644
@@ -7,7 +7,7 @@ function_exists()
 }
 
 function_exists __ltrim_colon_completions ||
-__ltrim_colon_completions()
+__ltrim_colon_completions ()
 {
 	if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
 		# Remove colon-word prefix from COMPREPLY items
@@ -20,7 +20,7 @@ __ltrim_colon_completions()
 }
 
 type perf &>/dev/null &&
-_perf()
+_perf ()
 {
 	local cur prev cmd
 
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#8 lore raw

Re: [PATCH 4/7] perf completion: modernize style

Em Thu, Jul 04, 2013 at 06:11:28PM +0530, Ramkumar Ramachandra escreveu:

Quoted 10 lines
---
 tools/perf/bash_completion | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bash_completion +0 -0
index d2598be..8c04f5d 100644

tools/perf/bash_completion function_exists() · line 10

Quoted 5 lines
tools/perf/bash_completion +1 -1
@@ -7,7 +7,7 @@ function_exists()
 }
 
 function_exists __ltrim_colon_completions ||
-__ltrim_colon_completions()
+__ltrim_colon_completions ()

Huh? Why would this be more "modern", if both are equivalent, I think applying the same rules as we have for C code applies here.

- Arnaldo

Quoted 20 lines
tools/perf/bash_completion +1 -1
 {
 	if [[ "$1" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
 		# Remove colon-word prefix from COMPREPLY items
@@ -20,7 +20,7 @@ __ltrim_colon_completions()
 }
 
 type perf &>/dev/null &&
-_perf()
+_perf ()
 {
 	local cur prev cmd
 
Signature · 7 lines
1.8.3.1.643.gebeea52.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#9 lore raw

Re: [PATCH 4/7] perf completion: modernize style

Quoted 2 lines · Arnaldo Carvalho de Melo

Huh? Why would this be more "modern", if both are equivalent, I think applying the same rules as we have for C code applies here.

It's the prevalent style in git.git, and I figured that it was picked up from linux.git but didn't check. Drop this part otherwise.

Thanks.

#10 lore raw

Re: [PATCH 4/7] perf completion: modernize style

Em Tue, Jul 16, 2013 at 10:52:55PM +0530, Ramkumar Ramachandra escreveu:

Quoted 6 lines
Quoted 2 lines · Arnaldo Carvalho de Melo

Huh? Why would this be more "modern", if both are equivalent, I think applying the same rules as we have for C code applies here.

It's the prevalent style in git.git, and I figured that it was picked up from linux.git but didn't check. Drop this part otherwise.

Can you check how is this in the current perf/core branch so that we can move forward while I process some other patches?

- Arnaldo

#11 lore raw

Re: [PATCH 4/7] perf completion: modernize style

Quoted 2 lines · Arnaldo Carvalho de Melo

Can you check how is this in the current perf/core branch so that we can move forward while I process some other patches?

This series (except this part) was merged into perf/completion of
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux 3 weeks ago, so I'm not sure what perf/core has to do with it.

To answer your question about prevalent style:

  $ git grep "[^ ]()" -- \*.sh

returns many more results than

  $ git grep " ()" -- \*.sh

This is different from what you will see in git.git.

Anyway, consistent style is important in shell scripts mainly because we don't have semantic parsers and have to rely on it being grep'able to find something. So, yeah: perf/completion is good as it is.

Thanks.

#12 lore raw

Re: [PATCH 4/7] perf completion: modernize style

In reply to Arnaldo Carvalho de Melo

Hi Arnaldo,

Quoted 2 lines · Arnaldo Carvalho de Melo

Can you check how is this in the current perf/core branch so that we can move forward while I process some other patches?

perf/completion is now 3 months old, and my more recent patches have already been merged into Linus' tree. Why is perf/completion being held up? It should be trivial enough to merge, no?

Thanks.

#13 lore raw

PATCH 5/7 perf completion: strip function_exists ()

In reply to Ramkumar Ramachandra

Use "type" to check existence consistently.

---
 tools/perf/bash_completion | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
tools/perf/bash_completion +1 -7
index 8c04f5d..852d444 100644
@@ -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
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#14 lore raw

[tip:perf/core] perf completion: Strip function_exists ()

perf completion: Strip function_exists ()
Commit-ID:  4685a6cfaeac6d2fe8ed10a9aa0cbff5026529cb
Gitweb:     http://git.kernel.org/tip/4685a6cfaeac6d2fe8ed10a9aa0cbff5026529cb
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Thu, 4 Jul 2013 18:11:29 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:12:06 -0300

perf completion: Strip function_exists ()

Use "type" to check existence consistently.

---
 tools/perf/bash_completion | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
tools/perf/bash_completion +1 -7
index d2598be..35fdda1 100644
@@ -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
#15 lore raw

PATCH 6/7 perf completion: strip dependency on bash-completion

In reply to Ramkumar Ramachandra

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.

Cc Namhyung Kim <[email protected]>
Cc Frederic Weisbecker <[email protected]>
---
 tools/perf/bash_completion | 83 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 77 insertions(+), 6 deletions(-)
tools/perf/bash_completion +77 -6
index 852d444..765fb2f 100644
@@ -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]}
 
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#16 lore raw

[tip:perf/core] perf completion: Strip dependency on bash-completion

perf completion: Strip dependency on bash-completion
Commit-ID:  c3fb6717e90049b93d0f5f5714a4d878799d89c2
Gitweb:     http://git.kernel.org/tip/c3fb6717e90049b93d0f5f5714a4d878799d89c2
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Thu, 4 Jul 2013 18:11:30 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:12:24 -0300

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.

---
 tools/perf/bash_completion | 83 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 77 insertions(+), 6 deletions(-)
tools/perf/bash_completion +77 -6
index 35fdda1..ee9c6d8 100644
@@ -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]}
 
#17 lore raw

PATCH 7/7 perf completion: use more comp words

In reply to Ramkumar Ramachandra

The completion words $words and $cword are available, so we might as well use them instead of directly accessing COMP_WORDS.

---
 tools/perf/bash_completion | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/bash_completion +6 -6
index 765fb2f..9bb5f4d 100644
@@ -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
Signature · 1 line
1.8.3.1.643.gebeea52.dirty
#18 lore raw

[tip:perf/core] perf completion: Use more comp words

perf completion: Use more comp words
Commit-ID:  6e0dc374a2c912a8a967ea8a4f9696dd4b0a6d3e
Gitweb:     http://git.kernel.org/tip/6e0dc374a2c912a8a967ea8a4f9696dd4b0a6d3e
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Thu, 4 Jul 2013 18:11:31 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 9 Oct 2013 11:12:31 -0300

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.

---
 tools/perf/bash_completion | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/bash_completion +6 -6
index ee9c6d8..62e157db 100644
@@ -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
maintainer
#19 lore raw
In reply to Ramkumar Ramachandra
Quoted 9 lines · Ramkumar Ramachandra

Hi,

So I just started using perf, and noticed the accompanying completion script. Having dabbled with git.git's completion script a bit, I thought I should contribute what I learnt from it.

[6/7] is the meat of the series, and the preceding patches work towards the same goal: to strip dependency on the bash-completion package.

So the whole point of this patchset is removing dependency, and no functional change, right?

It'd be great if the completion script supports multiple events separated by comma esp. in a group syntax (i.e. surrounded be a pair of curly braces: -e '{cache-references,cache-misses}'). Could you take a look at that if possible?

Thanks,
Namhyung

#20 lore raw
Quoted 2 lines · Namhyung Kim

So the whole point of this patchset is removing dependency, and no functional change, right?

Yep, and to lay the groundwork for extensibility: I would like to add ZSH support in a future patchset, for instance.

Quoted 4 lines

It'd be great if the completion script supports multiple events separated by comma esp. in a group syntax (i.e. surrounded be a pair of curly braces: -e '{cache-references,cache-misses}'). Could you take a look at that if possible?

Sure, thanks.

#21 lore raw
In reply to Ramkumar Ramachandra

Ping?

Does this series look alright?

Quoted 27 lines · Ramkumar Ramachandra

Hi,

So I just started using perf, and noticed the accompanying completion script. Having dabbled with git.git's completion script a bit, I thought I should contribute what I learnt from it.

[6/7] is the meat of the series, and the preceding patches work towards the same goal: to strip dependency on the bash-completion package.

Thanks.

Ramkumar Ramachandra (7):
perf completion: don't dictate perf install location perf completion: update __ltrim_colon_completions perf completion: strip dependency on _filedir perf completion: modernize style
perf completion: strip function_exists () perf completion: strip dependency on bash-completion perf completion: use more comp words

 tools/perf/bash_completion | 110 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 87 insertions(+), 23 deletions(-)

--
1.8.3.1.643.gebeea52.dirty