* [PATCH 2/4] _git-config: No functional change: rename $git_options_static to $git_options in preparation for the after-next commit.
2016-07-29 17:00 [PATCH 1/4] _git-config: Document more line noise Daniel Shahaf
@ 2016-07-29 17:00 ` Daniel Shahaf
2016-07-29 17:00 ` [PATCH 3/4] _git-config: Run gettable-options earlier and in all codepaths Daniel Shahaf
2016-07-29 17:00 ` [PATCH 4/4] _git-config: Complete option names present in the config file Daniel Shahaf
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-07-29 17:00 UTC (permalink / raw)
To: zsh-workers
---
Completion/Unix/Command/_git | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 1952cb6..4eba428 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -1959,8 +1959,8 @@ _git-config () {
# TODO: Add support for merge.*. (merge driver), diff.*. (diff driver), and filter.*. (filter driver) options
# (see gitattributes(5)).
# TODO: .path options should take absolute paths.
- declare -a git_options_static
- git_options_static=(
+ declare -a git_options
+ git_options=(
advice.pushNonFastForward:'show advice when git push refuses non-fast-forward refs::->bool:true'
advice.pushUpdateRejected:'combined setting for advice.push*::->bool:true'
advice.pushNonFFCurrent:'show advice when git push fails due to a non-fast-forward update to the current branch::->bool:true'
@@ -2474,10 +2474,10 @@ _git-config () {
if compset -P '[^.]##.*.'; then
declare -a match mbegin mend
- # When completing 'remote.foo.<TAB>', offer 'bar' if $git_options_static contains 'remote.foo.bar'.
- options+=(${${${${(M)git_options_static:#(#i)${IPREFIX}[^.:]##:*}#(#i)${IPREFIX}}/#(#b)([^:]##:)([^\\:]#(\\?[^\\:]#)#:[^\\:]#(\\?[^\\:]#)#:->bool)/$match[1]whether or not to $match[2]}/#(#b)([^:]##:([^\\:]#(\\?[^\\:]#)#))*/$match[1]})
- # When completing 'remote.foo.<TAB>', offer 'bar' if $git_options_static contains 'remote.*.bar'.
- options+=(${${${${(M)git_options_static:#(#i)${IPREFIX%%.*}.\*.[^.:]##:*}#(#i)${IPREFIX%%.*}.\*.}/#(#b)([^:]##:)([^\\:]#(\\?[^\\:]#)#:[^\\:]#(\\?[^\\:]#)#:->bool)/$match[1]whether or not to $match[2]}/#(#b)([^:]##:([^\\:]#(\\?[^\\:]#)#))*/$match[1]})
+ # When completing 'remote.foo.<TAB>', offer 'bar' if $git_options contains 'remote.foo.bar'.
+ options+=(${${${${(M)git_options:#(#i)${IPREFIX}[^.:]##:*}#(#i)${IPREFIX}}/#(#b)([^:]##:)([^\\:]#(\\?[^\\:]#)#:[^\\:]#(\\?[^\\:]#)#:->bool)/$match[1]whether or not to $match[2]}/#(#b)([^:]##:([^\\:]#(\\?[^\\:]#)#))*/$match[1]})
+ # When completing 'remote.foo.<TAB>', offer 'bar' if $git_options contains 'remote.*.bar'.
+ options+=(${${${${(M)git_options:#(#i)${IPREFIX%%.*}.\*.[^.:]##:*}#(#i)${IPREFIX%%.*}.\*.}/#(#b)([^:]##:)([^\\:]#(\\?[^\\:]#)#:[^\\:]#(\\?[^\\:]#)#:->bool)/$match[1]whether or not to $match[2]}/#(#b)([^:]##:([^\\:]#(\\?[^\\:]#)#))*/$match[1]})
declare -a labels
labels=(
@@ -2511,8 +2511,8 @@ _git-config () {
elif compset -P '[^.]##.'; then
local opt
declare -a match mbegin mend
- for opt in ${${${${(M)git_options_static:#(#i)${IPREFIX}[^.:]##:*}#(#i)${IPREFIX}}/#(#b)([^:]##:)([^\\:]#(\\?[^\\:]#)#:[^\\:]#(\\?[^\\:]#)#:->bool)/$match[1]whether or not to $match[2]}/#(#b)([^:]##:([^\\:]#(\\?[^\\:]#)#))*/$match[1]}; do
- if (( ${git_options_static[(I)${opt%%:*}.*]} )); then
+ for opt in ${${${${(M)git_options:#(#i)${IPREFIX}[^.:]##:*}#(#i)${IPREFIX}}/#(#b)([^:]##:)([^\\:]#(\\?[^\\:]#)#:[^\\:]#(\\?[^\\:]#)#:->bool)/$match[1]whether or not to $match[2]}/#(#b)([^:]##:([^\\:]#(\\?[^\\:]#)#))*/$match[1]}; do
+ if (( ${git_options[(I)${opt%%:*}.*]} )); then
sections_and_options+=$opt
else
options+=$opt
@@ -2702,13 +2702,13 @@ _git-config () {
esac
local z=$'\0'
- # Set $parts to the $git_options_static element that corresponds to $line[1]
+ # Set $parts to the $git_options element that corresponds to $line[1]
# (the option name whose value is currently being completed). The elements
- # of $parts are the colon-separated elements of the $git_options_static element.
+ # of $parts are the colon-separated elements of the $git_options element.
declare -a parts
- parts=("${(S@0)${git_options_static[(r)(#i)${line[1]}:*]}//(#b)(*[^\\]|):/$match[1]$z}")
+ parts=("${(S@0)${git_options[(r)(#i)${line[1]}:*]}//(#b)(*[^\\]|):/$match[1]$z}")
if (( $#parts < 2 )) && [[ $line[1] == [^.]##.*.[^.]## ]]; then
- parts=("${(S@0)${git_options_static[(r)(#i)${line[1]%%.*}.\*.${line[1]##*.}:*]}//(#b)(*[^\\]|):/$match[1]$z}")
+ parts=("${(S@0)${git_options[(r)(#i)${line[1]%%.*}.\*.${line[1]##*.}:*]}//(#b)(*[^\\]|):/$match[1]$z}")
fi
(( $#parts >= 4 )) || return ret
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/4] _git-config: Run gettable-options earlier and in all codepaths.
2016-07-29 17:00 [PATCH 1/4] _git-config: Document more line noise Daniel Shahaf
2016-07-29 17:00 ` [PATCH 2/4] _git-config: No functional change: rename $git_options_static to $git_options in preparation for the after-next commit Daniel Shahaf
@ 2016-07-29 17:00 ` Daniel Shahaf
2016-07-29 17:00 ` [PATCH 4/4] _git-config: Complete option names present in the config file Daniel Shahaf
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-07-29 17:00 UTC (permalink / raw)
To: zsh-workers
No change to completions; this is preparation for the next commit.
---
Completion/Unix/Command/_git | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 4eba428..184d164 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -2454,6 +2454,11 @@ _git-config () {
user.signingkey:'default GPG key to use when creating signed tags::__git_gpg_secret_keys'
web.browser:'web browser to use::__git_browsers')
+ declare -a git_present_options # 'present' is an adjective
+ git_present_options=(
+ ${${${(0)"$(_call_program gettable-options git config -z --list)"}%%$'\n'*}//:/\\:}
+ )
+
case $state in
(section)
__git_config_sections -b '(|)' '^' section-names 'section name' $* && ret=0
@@ -2663,8 +2668,7 @@ _git-config () {
options -M 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' && ret=0
;;
(gettable-option)
- _wanted git-options expl option compadd -M 'r:|.=* r:|=*' - \
- ${${${(0)"$(_call_program gettable-options git config -z --list)"}%%$'\n'*}//:/\\:} && ret=0
+ _wanted git-options expl option compadd -M 'r:|.=* r:|=*' -a - git_present_options && ret=0
;;
(gettable-colorbool-option)
__git_config_sections -b '(|)' -a '(|)' '^color\.[^.]+$' gettable-colorbool-options option && ret=0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 4/4] _git-config: Complete option names present in the config file.
2016-07-29 17:00 [PATCH 1/4] _git-config: Document more line noise Daniel Shahaf
2016-07-29 17:00 ` [PATCH 2/4] _git-config: No functional change: rename $git_options_static to $git_options in preparation for the after-next commit Daniel Shahaf
2016-07-29 17:00 ` [PATCH 3/4] _git-config: Run gettable-options earlier and in all codepaths Daniel Shahaf
@ 2016-07-29 17:00 ` Daniel Shahaf
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Shahaf @ 2016-07-29 17:00 UTC (permalink / raw)
To: zsh-workers
This patch lets
.
git config x.y.z value
git config <TAB>
.
complete 'x.y.z', even if x.y.z isn't hardcoded into _git-config.
---
Completion/Unix/Command/_git | 46 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 184d164..f9918f1 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -2459,6 +2459,39 @@ _git-config () {
${${${(0)"$(_call_program gettable-options git config -z --list)"}%%$'\n'*}//:/\\:}
)
+ # Add to $git_options options from the config file that aren't already in $git_options.
+ () {
+ local -a -U sections_that_permit_arbitrary_subsection_names=(
+ alias
+ pager
+ pretty
+ remotes
+ ${(u)${(M)${git_options%%:*}:#*[.][*][.]*}%%.*}
+ )
+ local key
+ for key in $git_present_options ; do
+ if (( ${+git_options[(r)(#i)${(b)key}:*]} )); then
+ # $key is already in git_options
+ continue
+ elif (( ${+sections_that_permit_arbitrary_subsection_names[(r)${(b)key%%.*}]} )); then
+ if [[ $key == *.*.* ]]; then
+ # If $key isn't an instance of a known foo.*.bar:baz $git_options entry...
+ if ! (( ${+git_options[(r)(#i)${(b)key%%.*}.[*].${(b)key##*.}:*]} )); then
+ # ... then add it.
+ git_options+="${key}:unknown option name"
+ fi
+ else
+ # $key is of the form "foo.bar" where 'foo' is known
+ # No need to add it; "foo.<TAB>' will find 'bar' via another codepath later
+ # ### TODO: that "other codepath" will probably run git config -z again, redundantly.
+ continue
+ fi
+ else
+ git_options+="${key}:unknown option name"
+ fi
+ done
+ }
+
case $state in
(section)
__git_config_sections -b '(|)' '^' section-names 'section name' $* && ret=0
@@ -2539,6 +2572,8 @@ _git-config () {
# following functions don't generate any output in the case of
# multi-level options.
case $IPREFIX in
+ # Note: If you add a branch to this 'case' statement,
+ # update $sections_that_permit_arbitrary_subsection_names.
(alias.)
__git_aliases && ret=0
;;
@@ -2596,6 +2631,10 @@ _git-config () {
(svn-remote.)
__git_svn-remotes -S . && ret=0
;;
+ (*.)
+ local -a existing_subsections=( ${${${(M)git_present_options:#${IPREFIX}*.*}#${IPREFIX}}%.*} )
+ _describe -t existing-subsections "existing subsections" existing_subsections -S . && ret=0
+ ;;
esac
else
sections=(
@@ -2658,6 +2697,13 @@ _git-config () {
web:'web options'
svn:'git svn options'
svn-remote:'git svn remotes')
+ () {
+ local i
+ for i in ${(u)git_present_options%%.*}; do
+ (( ${+sections[(r)(#i)${(b)i}:*]} )) ||
+ sections+="${i}:unknown section name"
+ done
+ }
fi
# TODO: Add equivalent of -M 'r:|.=* r:|=*' here so that we can complete
^ permalink raw reply [flat|nested] 4+ messages in thread