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

9 messages from 2009-05-09 to 2009-05-13. Participants: Stephen Boyd, Shawn O. Pearce, Junio C Hamano.
Thread: https://gitlist.dev/t/19252

## Stephen Boyd, 2009-05-09 01:23

Subject: [PATCHv2 0/2] completion: config --unset/get
Message-ID: <1241832213-23070-1-git-send-email-bebarino@gmail.com>
URL: https://gitlist.dev/e/1241832213-23070-1-git-send-email-bebarino%40gmail.com

```
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, 2009-05-09 01:23

Subject: [PATCHv2 1/2] completion: add __git_config_get_set_variables() to get config variables
Message-ID: <1241832213-23070-2-git-send-email-bebarino@gmail.com>
URL: https://gitlist.dev/e/1241832213-23070-2-git-send-email-bebarino%40gmail.com
In-Reply-To: <1241832213-23070-1-git-send-email-bebarino@gmail.com>

```
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, 2009-05-09 01:23

Subject: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <1241832213-23070-3-git-send-email-bebarino@gmail.com>
URL: https://gitlist.dev/e/1241832213-23070-3-git-send-email-bebarino%40gmail.com
In-Reply-To: <1241832213-23070-2-git-send-email-bebarino@gmail.com>

```
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, 2009-05-09 03:44

Subject: Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <20090509034438.GZ30527@spearce.org>
URL: https://gitlist.dev/e/20090509034438.GZ30527%40spearce.org
In-Reply-To: <1241832213-23070-3-git-send-email-bebarino@gmail.com>

```
Stephen Boyd <bebarino@gmail.com> wrote:
> 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>


> 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, 2009-05-12 05:20

Subject: Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <4A09071A.1030107@gmail.com>
URL: https://gitlist.dev/e/4A09071A.1030107%40gmail.com
In-Reply-To: <20090509034438.GZ30527@spearce.org>

```
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, 2009-05-12 08:12

Subject: Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <7vtz3q91up.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtz3q91up.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4A09071A.1030107@gmail.com>

```
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

?

```

## Stephen Boyd, 2009-05-12 19:05

Subject: Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <780e0a6b0905121205r7a57a99as2cb0b94ead73199d@mail.gmail.com>
URL: https://gitlist.dev/e/780e0a6b0905121205r7a57a99as2cb0b94ead73199d%40mail.gmail.com
In-Reply-To: <7vtz3q91up.fsf@alter.siamese.dyndns.org>

```
On Tue, May 12, 2009 at 1:12 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 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, 2009-05-13 18:33

Subject: Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <7vtz3o4zu2.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vtz3o4zu2.fsf%40alter.siamese.dyndns.org
In-Reply-To: <780e0a6b0905121205r7a57a99as2cb0b94ead73199d@mail.gmail.com>

```
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?

```

## Stephen Boyd, 2009-05-13 18:50

Subject: Re: [PATCHv2 2/2] completion: complete config variables for --get/getall/unset/unset-all
Message-ID: <780e0a6b0905131150q30e0bcacrff69cd78cd96ff34@mail.gmail.com>
URL: https://gitlist.dev/e/780e0a6b0905131150q30e0bcacrff69cd78cd96ff34%40mail.gmail.com
In-Reply-To: <7vtz3o4zu2.fsf@alter.siamese.dyndns.org>

```
On Wed, May 13, 2009 at 11:33 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 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.

```
