* Add matchspec for foo/bar branch names in git completion
@ 2015-05-14 14:37 Daniel Shahaf
2015-05-14 17:35 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2015-05-14 14:37 UTC (permalink / raw)
To: zsh-users
I'd like to add a matchspec to git heads completion, such that
'git checkout o/m<TAB>' would complete to 'origin/master'.
However, I can't seem to get the matchspec right. I tried this:
[[[
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 9304fbb..fe03439 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5585,7 +5585,7 @@ __git_remote_branch_names () {
branch_names=(${${(f)"$(_call_program remote-branch-refs git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/})
__git_command_successful $pipestatus || return 1
- _wanted remote-branch-names expl 'remote branch name' compadd "$@" -a - branch_names
+ _wanted remote-branch-names expl 'remote branch name' compadd -M 'r:|/=*' "$@" -a - branch_names
}
(( $+functions[__git_remote_branch_names_noprefix] )) ||
@@ -5596,7 +5596,7 @@ __git_remote_branch_names_noprefix () {
branch_names=(${${${(f)"$(_call_program remote-branch-refs-noprefix git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}##*/}:#HEAD})
__git_command_successful $pipestatus || return 1
- _wanted remote-branch-names-noprefix expl 'remote branch name' compadd "$@" -a - branch_names
+ _wanted remote-branch-names-noprefix expl 'remote branch name' compadd -M 'r:|/=*' "$@" -a - branch_names
}
(( $+functions[__git_commit_objects_prefer_recent] )) ||
@@ -5637,7 +5637,7 @@ __git_heads_local () {
[[ -f $gitdir/refs/stash ]] && heads+=stash
fi
- _wanted heads-local expl "local head" compadd "$@" -a - heads
+ _wanted heads-local expl "local head" compadd -M 'r:|/=*' "$@" -a - heads
}
(( $+functions[__git_heads_remote] )) ||
@@ -5647,7 +5647,7 @@ __git_heads_remote () {
heads=(${(f)"$(_call_program headrefs git for-each-ref --format='"%(refname:short)" refs/remotes' 2>/dev/null)"})
- _wanted heads-remote expl "remote head" compadd "$@" -a - heads
+ _wanted heads-remote expl "remote head" compadd -M 'r:|/=*' "$@" -a - heads
}
(( $+functions[__git_commit_objects] )) ||
]]]
Now, it does complete 'o/m' to 'origin/master', but when I type just
'or<TAB>', it completes to 'origin', without the trailing slash:
[[[
% git branch -l
foo/a
foo/b
foo/c
* master
% git co fo<TAB>
% git co foo
]]]
How could I get 'fo<TAB>' to become 'foo/', with the slash?
This is both in my usual config and in 'zsh -f'+compinit.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Add matchspec for foo/bar branch names in git completion
2015-05-14 14:37 Add matchspec for foo/bar branch names in git completion Daniel Shahaf
@ 2015-05-14 17:35 ` Bart Schaefer
2015-05-16 22:53 ` Daniel Shahaf
0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2015-05-14 17:35 UTC (permalink / raw)
To: zsh-users
On May 14, 2:37pm, Daniel Shahaf wrote:
}
} I'd like to add a matchspec to git heads completion, such that
} 'git checkout o/m<TAB>' would complete to 'origin/master'.
}
} However, I can't seem to get the matchspec right.
I'm not sure you can do that with a matchspec; you might need to use the
_multi_parts helper function.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Add matchspec for foo/bar branch names in git completion
2015-05-14 17:35 ` Bart Schaefer
@ 2015-05-16 22:53 ` Daniel Shahaf
2015-05-17 4:16 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2015-05-16 22:53 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Bart Schaefer wrote on Thu, May 14, 2015 at 10:35:03 -0700:
> On May 14, 2:37pm, Daniel Shahaf wrote:
> }
> } I'd like to add a matchspec to git heads completion, such that
> } 'git checkout o/m<TAB>' would complete to 'origin/master'.
> }
> } However, I can't seem to get the matchspec right.
>
> I'm not sure you can do that with a matchspec; you might need to use the
> _multi_parts helper function.
Thanks for the suggestion.
_multi_parts offers completions component-wise: e.g., with branches
origin/master
origin/interrupt_abort
foo/master
foo/bar
the existing code offers each of those as a completion, but _multi_parts
offers just 'origin' and 'foo'. I could see that being useful for some
people, but for us mortals with few branches it'd be a functionality
regression.
Other ideas?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Add matchspec for foo/bar branch names in git completion
2015-05-16 22:53 ` Daniel Shahaf
@ 2015-05-17 4:16 ` Bart Schaefer
2015-05-17 23:42 ` Daniel Shahaf
0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2015-05-17 4:16 UTC (permalink / raw)
To: zsh-users
On May 16, 10:53pm, Daniel Shahaf wrote:
}
} Other ideas?
I just looked again at your original patch, and I *think* you'll get what
you want if you simply change all 'r:|=*' to be 'r:|=**'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Add matchspec for foo/bar branch names in git completion
2015-05-17 4:16 ` Bart Schaefer
@ 2015-05-17 23:42 ` Daniel Shahaf
2015-05-19 1:52 ` Daniel Shahaf
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2015-05-17 23:42 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-users
Bart Schaefer wrote on Sat, May 16, 2015 at 21:16:42 -0700:
> On May 16, 10:53pm, Daniel Shahaf wrote:
> }
> } Other ideas?
>
> I just looked again at your original patch, and I *think* you'll get what
> you want if you simply change all 'r:|=*' to be 'r:|=**'.
Works, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Add matchspec for foo/bar branch names in git completion
2015-05-17 23:42 ` Daniel Shahaf
@ 2015-05-19 1:52 ` Daniel Shahaf
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Shahaf @ 2015-05-19 1:52 UTC (permalink / raw)
To: zsh-users
Daniel Shahaf wrote on Sun, May 17, 2015 at 23:42:57 +0000:
> Bart Schaefer wrote on Sat, May 16, 2015 at 21:16:42 -0700:
> > On May 16, 10:53pm, Daniel Shahaf wrote:
> > }
> > } Other ideas?
> >
> > I just looked again at your original patch, and I *think* you'll get what
> > you want if you simply change all 'r:|=*' to be 'r:|=**'.
>
> Works, thanks!
This seems useful so I'm going to go ahead and push it. Hopefully that
doesn't make the completion too overzealous by default.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-05-19 1:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-14 14:37 Add matchspec for foo/bar branch names in git completion Daniel Shahaf
2015-05-14 17:35 ` Bart Schaefer
2015-05-16 22:53 ` Daniel Shahaf
2015-05-17 4:16 ` Bart Schaefer
2015-05-17 23:42 ` Daniel Shahaf
2015-05-19 1:52 ` Daniel Shahaf
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).