* [PATCH 1/2] _git: Break out a helper function.
@ 2018-09-11 13:24 Daniel Shahaf
2018-09-11 13:24 ` [PATCH 2/2] _git: When completing worktrees, show the ref and hash of each worktree Daniel Shahaf
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2018-09-11 13:24 UTC (permalink / raw)
To: zsh-workers
---
Completion/Unix/Command/_git | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 2cae4c82f..b2f93ff0f 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -2108,8 +2108,7 @@ _git-worktree() {
;;
esac
if [[ $state = worktrees ]]; then
- _wanted directories expl 'working tree' compadd -S ' ' -f -M 'r:|/=* r:|=*' \
- ${${(M)${(f)"$(_call_program directories git worktree list --porcelain)"}:#worktree*}#* } && ret=0
+ __git_worktrees && ret=0
fi
;;
esac
@@ -7561,6 +7560,11 @@ __git_browsers () {
'builtin-browsers:builtin browser:compadd -a - builtinbrowsers'
}
+__git_worktrees () {
+ _wanted directories expl 'working tree' compadd -S ' ' -f -M 'r:|/=* r:|=*' \
+ ${${(M)${(f)"$(_call_program directories git worktree list --porcelain)"}:#worktree*}#* }
+}
+
(( $+functions[__git_difftools] )) ||
__git_difftools () {
__git_diff-or-merge-tools diff $*
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] _git: When completing worktrees, show the ref and hash of each worktree.
2018-09-11 13:24 [PATCH 1/2] _git: Break out a helper function Daniel Shahaf
@ 2018-09-11 13:24 ` Daniel Shahaf
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2018-09-11 13:24 UTC (permalink / raw)
To: zsh-workers
---
This part is independently useful.
The hash is truncated to 9 nibbles; should that be changed?
Mikael, interesting idea. I think I'll try this:
_git-cd() {
(( ${+functions[_git]} )) || { autoload +X -U _git && _git }
__git_worktrees "$@" || ${_comps[cd]} "$@"
}
git() {
if [[ $1 == cd ]]; then
shift ; builtin cd "$@" ; return $?
fi
⋮
}
Cheers,
Daniel
Completion/Unix/Command/_git | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index b2f93ff0f..32e5566e9 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -7561,8 +7561,25 @@ __git_browsers () {
}
__git_worktrees () {
- _wanted directories expl 'working tree' compadd -S ' ' -f -M 'r:|/=* r:|=*' \
- ${${(M)${(f)"$(_call_program directories git worktree list --porcelain)"}:#worktree*}#* }
+ local -a records=( ${(ps.\n\n.)"$(_call_program directories git worktree list --porcelain)"} )
+ local -a directories descriptions
+ local i hash branch
+ for i in $records; do
+ directories+=( ${${i%%$'\n'*}#worktree } )
+ hash=${${${"${(f)i}"[2]}#HEAD }[1,9]}
+ branch=${${"${(f)i}"[3]}#branch refs/heads/}
+
+ # Simulate the non-porcelain output
+ if [[ $branch == detached ]]; then
+ # TODO: show a ref that points at $hash here, like vcs_info does?
+ branch="(detached HEAD)"
+ else
+ branch="[$branch]"
+ fi
+
+ descriptions+=( "${directories[-1]}"$'\t'"$hash $branch" )
+ done
+ _wanted directories expl 'working tree' compadd -ld descriptions -S ' ' -f -M 'r:|/=* r:|=*' -a directories
}
(( $+functions[__git_difftools] )) ||
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-09-11 13:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-11 13:24 [PATCH 1/2] _git: Break out a helper function Daniel Shahaf
2018-09-11 13:24 ` [PATCH 2/2] _git: When completing worktrees, show the ref and hash of each worktree 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).