Skip to contentSkip to conversation

completion: config --unset/get

PATCH In review Stephen Boyd 3 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

v2 cover completion: config --unset/get

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(-)
#1 lore raw

PATCH v2 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.

---
 contrib/completion/git-completion.bash |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
contrib/completion/git-completion.bash +29 -0
index 1683e6d..e73359c 100755
@@ -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]}"
Signature · 1 line
1.6.3
#2 lore raw

PATCH v2 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.

---
 contrib/completion/git-completion.bash |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
contrib/completion/git-completion.bash +4 -0
index e73359c..ad26b7c 100755
@@ -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
Signature · 1 line
1.6.3
Acked-by on v2 2/2
#3 lore raw

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

Quoted 8 lines · Stephen Boyd

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.

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

Quoted 18 lines
contrib/completion/git-completion.bash +4 -0
index e73359c..ad26b7c 100755
@@ -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
Signature · 1 line
1.6.3
Signature · 1 line
Shawn.
#4 lore raw

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

Quoted 3 lines · Shawn O. Pearce

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.

#5 lore raw

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

Quoted 5 lines · Stephen Boyd
Quoted 3 lines · Shawn O. Pearce

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

Quoted 8 lines

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

?

#6 lore raw

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

Quoted 13 lines · Junio C Hamano
Quoted 11 lines · Stephen Boyd
Quoted 3 lines · Shawn O. Pearce

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

Quoted 9 lines
Quoted 2 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

#7 lore raw

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

Quoted 10 lines · Stephen Boyd
Quoted 9 lines
Quoted 2 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

?

Quoted 7 lines

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?

#8 lore raw

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

Quoted 17 lines · Junio C Hamano
Quoted 15 lines · Stephen Boyd
Quoted 9 lines
Quoted 2 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:

Quoted 10 lines
Quoted 2 lines

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.