threads / patch / 13276

patchbash: Add completion for gitk --merge

Subject: [PATCH] bash: Add completion for gitk --merge

## tl;dr

4 messages between Apr 26, 2008 and Apr 27, 2008. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Richard Quirk· Apr 26, 2008, 23:32 UTC · lore
Option is only completed when .git/MERGE_HEAD is present.
Signed-off-by: Richard Quirk <richard.quirk@gmail.com>
---
 contrib/completion/git-completion.bash |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +6 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 665a895..2565aa6 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1346,9 +1346,14 @@ _git ()
 _gitk ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
+	local g="$(git rev-parse --git-dir 2>/dev/null)"
+	local merge=""
+	if [ -f $g/MERGE_HEAD ]; then
+		local merge="--merge"
+	fi
 	case "$cur" in
 	--*)
-		__gitcomp "--not --all"
+		__gitcomp "--not --all $merge"
 		return
 		;;
 	esac
-- 
1.5.5.1.79.g57cf
Shawn O. Pearce· Apr 27, 2008, 04:18 UTC · re: Richard Quirk · lore

Re: [PATCH] bash: Add completion for gitk --merge

Richard Quirk <richard.quirk@gmail.com> wrote:
Show 6 quoted lines
> Option is only completed when .git/MERGE_HEAD is present.
> 
> Signed-off-by: Richard Quirk <richard.quirk@gmail.com>
> ---
>  contrib/completion/git-completion.bash |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
Nice.
 
Show 12 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 665a895..2565aa6 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1346,9 +1346,14 @@ _git ()
>  _gitk ()
>  {
>  	local cur="${COMP_WORDS[COMP_CWORD]}"
> +	local g="$(git rev-parse --git-dir 2>/dev/null)"
> +	local merge=""
> +	if [ -f $g/MERGE_HEAD ]; then
> +		local merge="--merge"

I don't think the extra "local" is necessary within the if block; you have already declared it to be local when you initialized it to the empty string.

-- 
Shawn.
Richard Quirk· Apr 27, 2008, 15:35 UTC · re: Shawn O. Pearce · lore
Option is only completed when .git/MERGE_HEAD is present.
Signed-off-by: Richard Quirk <richard.quirk@gmail.com>
---
 contrib/completion/git-completion.bash |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
Show changes to contrib/completion/git-completion.bash +6 −1
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 665a895..23db664 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1346,9 +1346,14 @@ _git ()
 _gitk ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
+	local g="$(git rev-parse --git-dir 2>/dev/null)"
+	local merge=""
+	if [ -f $g/MERGE_HEAD ]; then
+		merge="--merge"
+	fi
 	case "$cur" in
 	--*)
-		__gitcomp "--not --all"
+		__gitcomp "--not --all $merge"
 		return
 		;;
 	esac
-- 
1.5.5.1.79.g57cf
Shawn O. Pearce· Apr 27, 2008, 17:19 UTC · re: Richard Quirk · lore

Re: [PATCH] bash: Add completion for gitk --merge

Richard Quirk <richard.quirk@gmail.com> wrote:
> Option is only completed when .git/MERGE_HEAD is present.
> 
> Signed-off-by: Richard Quirk <richard.quirk@gmail.com>
Thanks for fixing the unnecessary local and resubmitting.
Acked-by: Shawn O. Pearce <spearce@spearce.org>
Show 27 quoted lines
> ---
>  contrib/completion/git-completion.bash |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 665a895..23db664 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1346,9 +1346,14 @@ _git ()
>  _gitk ()
>  {
>  	local cur="${COMP_WORDS[COMP_CWORD]}"
> +	local g="$(git rev-parse --git-dir 2>/dev/null)"
> +	local merge=""
> +	if [ -f $g/MERGE_HEAD ]; then
> +		merge="--merge"
> +	fi
>  	case "$cur" in
>  	--*)
> -		__gitcomp "--not --all"
> +		__gitcomp "--not --all $merge"
>  		return
>  		;;
>  	esac
> -- 
> 1.5.5.1.79.g57cf
> 
-- 
Shawn.

← back to recent threads