threads / discuss / 19252

[PATCHv2 0/2] completion: config --unset/get

Subject: [PATCHv2 0/2] completion: config --unset/get

## tl;dr

9 messages between May 9, 2009 and May 13, 2009.

replies: 8people: 3as markdown or json

Stephen Boyd· May 9, 2009, 01:23 UTC · lore
Changes since version 1:
    - Simplified into one function
    - Config file search done in reverse
    - No longer messes up your config file
Stephen Boyd (2):
  completion: add __git_config_get_set_variables() to get config
    variables
  completion: complete config variables for
    --get/getall/unset/unset-all
 contrib/completion/git-completion.bash |   33 ++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
Stephen Boyd· May 9, 2009, 01:23 UTC · re: Stephen Boyd · lore

[PATCHv2 1/2] completion: add __git_config_get_set_variables() to get config variables

This function retrieves the set configuration variables from the appropriate configuration file. For example, if the user has previously specified --global only the global variables are returned. The same applies for --system, and --file. If no location has been specified, all set variables are returned.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 contrib/completion/git-completion.bash |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 1683e6d..e73359c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1322,6 +1322,35 @@ _git_send_email ()
 	COMPREPLY=()
 }
 
+__git_config_get_set_variables ()
+{
+	local prevword word config_file= c=$COMP_CWORD
+	while [ $c -gt 1 ]; do
+		word="${COMP_WORDS[c]}"
+		case "$word" in
+		--global|--system|--file=*)
+			config_file="$word"
+			break
+			;;
+		-f|--file)
+			config_file="$word $prevword"
+			break
+			;;
+		esac
+		prevword=$word
+		c=$((--c))
+	done
+
+	for i in $(git --git-dir="$(__gitdir)" config $config_file --list \
+			2>/dev/null); do
+		case "$i" in
+		*.*)
+			echo "${i/=*/}"
+			;;
+		esac
+	done
+}
+
 _git_config ()
 {
 	local cur="${COMP_WORDS[COMP_CWORD]}"
-- 
1.6.3
Stephen Boyd· May 9, 2009, 01:23 UTC · re: Stephen Boyd · lore

[PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

This should make it easier for users to get and unset their configuration variables without having to open documentation or dig through their configuration file.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
 contrib/completion/git-completion.bash |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e73359c..ad26b7c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1417,6 +1417,10 @@ _git_config ()
 		__gitcomp "$__git_send_email_suppresscc_options"
 		return
 		;;
+	--get|--get-all|--unset|--unset-all)
+		__gitcomp "$(__git_config_get_set_variables)"
+		return
+		;;
 	*.*)
 		COMPREPLY=()
 		return
-- 
1.6.3
Shawn O. Pearce· May 9, 2009, 03:44 UTC · re: Stephen Boyd · lore

Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

Stephen Boyd <bebarino@gmail.com> wrote:
Show 8 quoted lines
> This should make it easier for users to get and unset their
> configuration variables without having to open documentation or dig
> through their configuration file.
> 
> Signed-off-by: Stephen Boyd <bebarino@gmail.com>
> ---
>  contrib/completion/git-completion.bash |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)

These probably could have been one patch, since the function is introduced only to support this one usage, and this patch is only 4 lines larger than the function definition anyway...

But yea, this series is better.
Acked-by: Shawn O. Pearce <spearce@spearce.org>
Show 18 quoted lines
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index e73359c..ad26b7c 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1417,6 +1417,10 @@ _git_config ()
>  		__gitcomp "$__git_send_email_suppresscc_options"
>  		return
>  		;;
> +	--get|--get-all|--unset|--unset-all)
> +		__gitcomp "$(__git_config_get_set_variables)"
> +		return
> +		;;
>  	*.*)
>  		COMPREPLY=()
>  		return
> -- 
> 1.6.3
> 
-- 
Shawn.
Stephen Boyd· May 12, 2009, 05:20 UTC · re: Shawn O. Pearce · lore

Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

Shawn O. Pearce wrote:
> These probably could have been one patch, since the function
> is introduced only to support this one usage, and this patch
> is only 4 lines larger than the function definition anyway...

Seeing that this hasn't been picked up yet, I'm fine with this being squashed into one commit. Could you use this combination of the two messages for the commit?

---8<----
Subject: completion: complete config variables for
--get/getall/unset/unset-all

This should make it easier for users to get and unset their configuration variables without having to open documentation or dig through their configuration file.

__git_config_get_set_variables() retrieves the set configuration variables
 from the appropriate configuration file. For example, if the user has
previously specified --global only the global variables are returned. The
same applies for --system, and --file. If no location has been
specified, all
set variables are returned.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Junio C Hamano· May 12, 2009, 08:12 UTC · re: Stephen Boyd · lore

Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

Stephen Boyd <bebarino@gmail.com> writes:
Show 13 quoted lines
> Shawn O. Pearce wrote:
>> These probably could have been one patch, since the function
>> is introduced only to support this one usage, and this patch
>> is only 4 lines larger than the function definition anyway...
>
> Seeing that this hasn't been picked up yet, I'm fine with this being
> squashed into one commit. Could you use this combination of the two
> messages for the commit?
>
> ---8<----
>
> Subject: completion: complete config variables for
> --get/getall/unset/unset-all
Hmm, shouldn't this just be
    Subject: completion: complete variable names for "git config" command
?
Stephen Boyd· May 12, 2009, 19:05 UTC · re: Junio C Hamano · lore

Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

On Tue, May 12, 2009 at 1:12 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
> Stephen Boyd <bebarino@gmail.com> writes:
>
>> Shawn O. Pearce wrote:
>>> These probably could have been one patch, since the function
>>> is introduced only to support this one usage, and this patch
>>> is only 4 lines larger than the function definition anyway...
>>
>> Seeing that this hasn't been picked up yet, I'm fine with this being
>> squashed into one commit. Could you use this combination of the two
>> messages for the commit?
>>
>> ---8<----
>>
>> Subject: completion: complete config variables for
>> --get/getall/unset/unset-all
>
> Hmm, shouldn't this just be
>
>    Subject: completion: complete variable names for "git config" command
>
> ?
>

This patch adds completion for set variable names when --get, --get-all, --set, or --set-all has been specified. Completion of variable names for git config already exists. Maybe this would be more clear:

Subject: completion: complete set variable names for git config
--get/get-all/set-set-all
Junio C Hamano· May 13, 2009, 18:33 UTC · re: Stephen Boyd · lore

Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

Stephen Boyd <bebarino@gmail.com> writes:
Show 17 quoted lines
>>> Subject: completion: complete config variables for
>>> --get/getall/unset/unset-all
>>
>> Hmm, shouldn't this just be
>>
>>    Subject: completion: complete variable names for "git config" command
>>
>> ?
>>
>
> This patch adds completion for set variable names when --get,
> --get-all, --set, or --set-all has been specified. Completion of
> variable names for git config already exists. Maybe this would be more
> clear:
>
> Subject: completion: complete set variable names for git config
> --get/get-all/set-set-all
Actually I was shooting for shorter description.  It is more like
	bash: complete variable names for "git config" with options
perhaps?
Stephen Boyd· May 13, 2009, 18:50 UTC · re: Junio C Hamano · lore

Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all

On Wed, May 13, 2009 at 11:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 27 quoted lines
> Stephen Boyd <bebarino@gmail.com> writes:
>
>>>> Subject: completion: complete config variables for
>>>> --get/getall/unset/unset-all
>>>
>>> Hmm, shouldn't this just be
>>>
>>>    Subject: completion: complete variable names for "git config" command
>>>
>>> ?
>>>
>>
>> This patch adds completion for set variable names when --get,
>> --get-all, --set, or --set-all has been specified. Completion of
>> variable names for git config already exists. Maybe this would be more
>> clear:
>>
>> Subject: completion: complete set variable names for git config
>> --get/get-all/set-set-all
>
> Actually I was shooting for shorter description.  It is more like
>
>        bash: complete variable names for "git config" with options
>
> perhaps?
>
>
Heh, ok. This sounds fine.

← back to recent threads