Add worktree cd subcommand & --force flag to remove

This commit is contained in:
2026-05-08 10:37:21 +01:00
parent 8877017ae7
commit b3eff126c7
2 changed files with 45 additions and 7 deletions

View File

@@ -16,6 +16,13 @@ __worktree_active_branches() {
_describe 'branch' branches
}
__worktree_all_branches() {
local -a branches
branches=(${(fo)"$(git worktree list --porcelain 2>/dev/null | \
awk '/^branch refs\/heads\//{ sub(/^branch refs\/heads\//, ""); print }')"})
_describe 'branch' branches
}
_worktree() {
local context curcontext="$curcontext" state line
typeset -A opt_args
@@ -28,6 +35,7 @@ _worktree() {
(cmd)
local commands; commands=(
'add:Create a worktree for a branch'
'cd:Change directory to a worktree by branch'
'list:List managed worktrees'
'ls:List managed worktrees'
'remove:Remove a worktree by branch'
@@ -42,8 +50,13 @@ _worktree() {
(add)
_arguments '1:: :__worktree_branches'
;;
(cd)
_arguments '1:: :__worktree_all_branches'
;;
(rm|remove)
_arguments '*:: :__worktree_active_branches'
_arguments \
'(-f --force)'{-f,--force}'[Force removal even with modified or untracked files]' \
'*:: :__worktree_active_branches'
;;
(sync)
_arguments '*:: :__worktree_active_branches'