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

[PATCH] _git: don't expand {alias} if _git-{alias} exists



From: "Benjamin R. Haskell" <zsh@xxxxxxxxxx>

This allows easy creation of completion functions for aliases that are
shell wrappers around other git functions.

E.g. I have an alias for `git reset --hard` called `git hard`, which
checks that I'm not resetting staged changes:

$ git config alias.hard
! : reset hard unless staged ; if git diff --cached | grep -q . ; then echo You have staged changes ; return 1 ; fi ; git reset --hard

Adding the following function lets me use the same completion: _git-hard () { _git-reset "$@" }

---
 Completion/Unix/Command/_git |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 88c765f..b8f3051 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -6073,7 +6073,7 @@ _git() {
     aliases=(${(f)${${${(f)"$(_call_program aliases git config --get-regexp '\^alias\.')"}#alias.}/ /$'\n'}/(#e)/$'\n'})
     (( $#aliases % 2 == 0 )) && git_aliases=($aliases)
 
-    if (( $+git_aliases[$words[2]] && !$+commands[git-$words[2]] )); then
+    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})
-- 
1.7.8.4



Messages sorted by: Reverse Date, Date, Thread, Author