From 2ccf41e5772cbfb22802365a26872b796833a7c6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Sun, 18 May 2025 03:06:16 +0000 Subject: 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. --- Completion/Unix/Command/_git | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Completion/Unix/Command/_git') diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 702360ef3..95bd3096d 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -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] )) || -- cgit v1.2.3-70-g09d2