zsh-workers
 help / color / mirror / code / Atom feed
From: "Benjamin R. Haskell" <zsh@benizi.com>
To: Zsh Workers <zsh-workers@zsh.org>
Cc: <zsh@benizi.com>
Subject: [PATCH] _git: don't expand {alias} if _git-{alias} exists
Date: Thu, 18 Oct 2012 03:28:55 -0400	[thread overview]
Message-ID: <1350545335-10537-1-git-send-email-zsh@benizi.com> (raw)

From: "Benjamin R. Haskell" <zsh@benizi.com>

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


                 reply	other threads:[~2012-10-18  7:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1350545335-10537-1-git-send-email-zsh@benizi.com \
    --to=zsh@benizi.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).