github #134 (+ implement commit review suggestion): __git_worktrees: Use a library function

Using _describe makes the completions and descriptions line up in
columns, and makes the function honour the list-separator style.
This commit is contained in:
Daniel Shahaf
2025-05-18 03:06:16 +00:00
parent fceece6a8a
commit 2ccf41e577
2 changed files with 10 additions and 2 deletions

View File

@@ -1,3 +1,9 @@
2025-05-18 Daniel Shahaf <d.s@daniel.shahaf.name>
* github #134 (+ implement commit review suggestion):
Completion/Unix/Command/_git: __git_worktrees: Use a library
function
2025-05-17 Daniel Shahaf <d.s@daniel.shahaf.name>
* unposted: Fix a ChangeLog typo reported offlist.

View File

@@ -8514,6 +8514,7 @@ __git_worktrees () {
local -a records=( ${(ps.\n\n.)"$(_call_program directories git worktree list --porcelain)"} )
local -a directories descriptions
local i hash branch
local match mbegin mend
for i in $records; do
directories+=( ${${i%%$'\n'*}#worktree } )
hash=${${${"${(f)i}"[2]}#HEAD }[1,9]}
@@ -8527,9 +8528,10 @@ __git_worktrees () {
branch="[$branch]"
fi
descriptions+=( "${directories[-1]}"$'\t'"$hash $branch" )
descriptions+=( "${directories[-1]//(#b)([\\:])/\\${match[1]}}":"$hash $branch" )
done
_wanted directories expl 'working tree' compadd -ld descriptions -S ' ' -f -M 'r:|/=* r:|=*' -a directories
_describe -t directories 'working tree' descriptions -S ' ' -f -M 'r:|/=* r:|=*'
}
(( $+functions[__git_difftools] )) ||