Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 3/4] _git: Fix handling of aliases
- X-seq: zsh-workers 46141
- From: Miroslav Koškár <mk@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH 3/4] _git: Fix handling of aliases
- Date: Sat, 27 Jun 2020 08:12:17 +0200
- Arc-authentication-results: i=1; mx.zohomail.com; dkim=pass header.i=mkoskar.com; spf=pass smtp.mailfrom=mk@xxxxxxxxxxx; dmarc=pass header.from=<mk@xxxxxxxxxxx> header.from=<mk@xxxxxxxxxxx>
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593238404; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=KH4x9lgqFNCXEOpsBHpDjEqL0+LVdFQVqy/JDJvKpr0=; b=Blq/oXPfSAMk7cPxpE0oqprQrfLIz1P06Do/0yWpV9ITFd41tSJKBPUbZBwrnsDzicXtUFSyqMp7zFT3Gu41U/LpoXLAYPn5a+weboB8LyqIXViwTrtmYVav38Lk3fVE5Wm4Y+izdMwWJkRJoYyE642o2SFaoK6WPhRpVg0sLHs=
- Arc-seal: i=1; a=rsa-sha256; t=1593238404; cv=none; d=zohomail.com; s=zohoarc; b=RCeXjvuQbLQP3Uh45Q/oBEyohw8v6v2M63t6EVTfzOY1kasocZ2VJe39wnv7Ve3Fodn6Lvc0p2Q4M3Alh47WQCAAi8YyJiNWdxxyV+b6tqH4V1AHCsogtdh3sMCT24LOUuBs64YJkrt9rlFUjy8ypZkLr8b5a/Q6KZppKjZbNG8=
- Cc: d.s@xxxxxxxxxxxxxxxxxx
- In-reply-to: <cover.1593236365.git.mk@mkoskar.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <cover.1593236365.git.mk@mkoskar.com>
- Sender: zsh-workers@xxxxxxx
* nested aliases
* aliases preceded with options e.g., -c <name>=<value>
---
Completion/Unix/Command/_git | 73 ++++++++++++++++--------------------
1 file changed, 33 insertions(+), 40 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 602d0d0..e2d3d6e 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -8082,35 +8082,8 @@ __git_color_attributes () {
# Now, for the main drive...
_git() {
- if (( CURRENT > 2 )); then
- local -a aliases
- local -A git_aliases
- local a k v
- local endopt='!(-)--end-of-options'
- aliases=(${(0)"$(_call_program aliases git config -z --get-regexp '\^alias\\.')"})
- for a in ${aliases}; do
- k="${${a/$'\n'*}/alias.}"
- v="${a#*$'\n'}"
- git_aliases[$k]="$v"
- done
-
- if (( $+git_aliases[$words[2]] && !$+commands[git-$words[2]] && !$+functions[_git-$words[2]] )); then
- local -a tmpwords expalias
- expalias=(${(z)git_aliases[$words[2]]})
- tmpwords=(${words[1]} ${expalias})
- if [[ -n "${words[3,-1]}" ]] ; then
- tmpwords+=(${words[3,-1]})
- fi
- [[ -n ${words[$CURRENT]} ]] || tmpwords+=('')
- (( CURRENT += ${#expalias} - 1 ))
- words=("${tmpwords[@]}")
- unset tmpwords expalias
- fi
-
- unset git_aliases aliases
- fi
-
integer ret=1
+ local -a allwords=("${words[@]}")
if [[ $service == git ]]; then
local curcontext=$curcontext state line
@@ -8143,18 +8116,38 @@ _git() {
_git_commands && ret=0
;;
(option-or-argument)
- curcontext=${curcontext%:*:*}:git-$words[1]:
- (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}}
- (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(Q)${~opt_args[--work-tree]}}
- if ! _call_function ret _git-$words[1]; then
- if [[ $words[1] = \!* ]]; then
- words[1]=${words[1]##\!}
- _normal && ret=0
- elif zstyle -T :completion:$curcontext: use-fallback; then
- _default && ret=0
- else
- _message "unknown sub-command: $words[1]"
- fi
+ local -a aliases
+ local -A git_aliases
+ local a k v
+ local endopt='!(-)--end-of-options'
+ aliases=(${(0)"$(_call_program aliases git config -z --get-regexp '\^alias\\.')"})
+ for a in ${aliases}; do
+ k="${${a/$'\n'*}/alias.}"
+ v="${a#*$'\n'}"
+ git_aliases[$k]="$v"
+ done
+ local git_alias=git_aliases[\$words[1]]
+ if (( ${(P)+git_alias} && !$+commands[git-$words[1]] && !$+functions[_git-$words[1]] )); then
+ git_alias=${(P)git_alias}
+ local len=$#words
+ if [[ $git_alias = \!* ]]; then
+ words=("${(z)git_alias##\!}" "${words[@]:1}")
+ else
+ words=("${allwords[@]:0:-$#words}" "${(z)git_alias}" "${words[@]:1}")
+ fi
+ (( CURRENT += $#words - len ))
+ _normal && ret=0
+ else
+ curcontext=${curcontext%:*:*}:git-$words[1]:
+ (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}}
+ (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(Q)${~opt_args[--work-tree]}}
+ if ! _call_function ret _git-$words[1]; then
+ if zstyle -T :completion:$curcontext: use-fallback; then
+ _default && ret=0
+ else
+ _message "unknown sub-command: $words[1]"
+ fi
+ fi
fi
;;
(configuration)
--
2.27.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author