From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22149 invoked by alias); 29 Jul 2016 17:00:24 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 38964 Received: (qmail 21522 invoked from network); 29 Jul 2016 17:00:23 -0000 X-Qmail-Scanner-Diagnostics: from hermes.apache.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(140.211.11.3):SA:0(-1.3/5.0):. Processed in 0.402241 secs); 29 Jul 2016 17:00:23 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: danielsh@apache.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at apache.org does not designate permitted sender hosts) From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 4/4] _git-config: Complete option names present in the config file. Date: Fri, 29 Jul 2016 17:00:08 +0000 Message-Id: <1469811608-3870-4-git-send-email-danielsh@tarsus.local2> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1469811608-3870-1-git-send-email-danielsh@tarsus.local2> References: <1469811608-3870-1-git-send-email-danielsh@tarsus.local2> This patch lets . git config x.y.z value git config . 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.' 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