summary refs log tree commit diff
path: root/Completion/Unix
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2018-09-11 13:24:21 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2018-09-12 15:12:09 +0000
commitb44be21525d0758c93d8c5fab05fdbd8a9cb0d91 (patch)
tree98d01b13e042df4276386645d91f97f93540098a /Completion/Unix
parent7ae2be3a2fd7e3be2b6f3990cb4c0ca164cf72d1 (diff)
downloadzsh-b44be21525d0758c93d8c5fab05fdbd8a9cb0d91.tar.gz
zsh-b44be21525d0758c93d8c5fab05fdbd8a9cb0d91.tar.xz
zsh-b44be21525d0758c93d8c5fab05fdbd8a9cb0d91.zip
43443: _git: When completing worktrees, show the ref and hash of each worktree.
Diffstat (limited to 'Completion/Unix')
-rw-r--r--Completion/Unix/Command/_git21
1 files changed, 19 insertions, 2 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index b2f93ff0f..195a7f6dc 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] )) ||