Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 3/4] _git: Fix handling of aliases



* 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