From: Oliver Kiddle <opk@zsh.org>
To: Ahmad Ismail <ismail783@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: git diff HEAD - only show modified files in completion
Date: Sat, 17 Oct 2020 10:33:20 +0200 [thread overview]
Message-ID: <51151-1602923600.276703@fJFe.e1_b.HfoP> (raw)
In-Reply-To: <CAHAhJwLAD04fAMBy-Kwm6WM1uiBg+xr+4-0e9+3c674Xs=GJvQ@mail.gmail.com>
Ahmad Ismail wrote:
> I think I have to use:
> _git-diff 2>/dev/null
> functions[_git-diff-orig]=$functions[_git-diff]
>
> _git-diff() {
> _git-diff-orig "$@"
> ...
> }
It looks like you've removed the stack overflow question already so
I'm somewhat guessing at what your issue is. Mostly, you need to move
your own code up before calling _git-diff-orig. The tag-ordering styles
can only work when there is a single tag loop in which completions are
added.
In this case, it's probably easier to tweak the original _git-diff
function than to modify it from a wrapper. And using git diff HEAD or
git diff @ to get both staged and unstaged changes is a common enough
case to warrant being special-cased. So any thoughts on the following
patch for _git. Ideally it ought to be possible to correctly handle any
arbitrary base branch name but we have existing functions for taking
care of files modified relative to the HEAD.
Admittedly, __git_changed_files itself could be improved but that's a
separate issue.
Oliver
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 05e2a2361..81a060e4d 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -806,11 +806,14 @@ _git-diff () {
# Example: git diff branch1..branch2 <tab>
__git_tree_files ${PREFIX:-.} $(__git_committish_range_last $line[1]) && ret=0
elif __git_is_committish $line[1] || __git_is_treeish $line[1]; then
+ local files_alt='files::__git_tree_files ${PREFIX:-.} HEAD'
+ [[ $line[1] = (HEAD|@) ]] &&
+ files_alt='files::__git_changed_files'
# Example: git diff branch1 <tab>
_alternative \
'commits::__git_commits' \
'blobs-and-trees-in-treeish::__git_blobs_and_trees_in_treeish' \
- 'files::__git_tree_files ${PREFIX:-.} HEAD' && ret=0
+ $files_alt && ret=0
elif __git_is_blob $line[1]; then
_alternative \
'files::__git_cached_files' \
@@ -831,6 +834,10 @@ _git-diff () {
__git_is_treeish $line[2]; then
# Example: git diff branch1 branch2 <tab>
__git_tree_files ${PREFIX:-.} $line[2] && ret=0
+ elif [[ $line[1] = (HEAD|@) ]]; then
+ # Example: git diff @ file1 <tab>
+ # Example: git diff HEAD -- <tab>
+ __git_ignore_line __git_changed_files && ret=0
elif __git_is_committish $line[1] || __git_is_treeish $line[1]; then
# Example: git diff branch file1 <tab>
# Example: git diff branch -- f<tab>
next prev parent reply other threads:[~2020-10-17 8:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-15 22:48 Ahmad Ismail
2020-10-16 22:16 ` Ahmad Ismail
2020-10-17 8:33 ` Oliver Kiddle [this message]
2020-10-17 15:24 ` Bart Schaefer
2020-10-17 16:25 ` Ahmad Ismail
2020-10-17 22:15 ` Bart Schaefer
2020-10-18 18:23 ` Ahmad Ismail
2020-10-17 12:28 ` Daniel Shahaf
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=51151-1602923600.276703@fJFe.e1_b.HfoP \
--to=opk@zsh.org \
--cc=ismail783@gmail.com \
--cc=zsh-users@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).