forked from coderabbitai/git-worktree-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_git-gtr
More file actions
202 lines (193 loc) · 7.31 KB
/
_git-gtr
File metadata and controls
202 lines (193 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#compdef _git-gtr git-gtr gtr
# AUTO-GENERATED by scripts/generate-completions.sh — DO NOT EDIT MANUALLY
# Re-generate with: ./scripts/generate-completions.sh
#
# Zsh completion for git gtr (Git Worktree Runner)
#
# SETUP: For completions to work with `git gtr`, add this to ~/.zshrc
# BEFORE any existing compinit call:
#
# eval "$(git gtr completion zsh)"
#
# This registers gtr as a git subcommand and sets up the completion path.
# Run `git gtr completion --help` for more details.
#
# WHY: Zsh needs to know `gtr` is a valid git subcommand BEFORE completion
# triggers. The zstyle registration below only runs when this file is loaded,
# but autoloading happens AFTER completion - a timing issue. The `completion`
# command outputs the zstyle before compinit, solving this.
_git-gtr() {
# Normalize invocation so we always see: [git, gtr, <command>, ...]
# Handles: `git gtr`, `gtr`, and `git-gtr` invocations
if [[ $words[1] != git ]]; then
# Handle both `gtr ...` and `git-gtr ...`
words=(git gtr "${words[@]:1}")
(( CURRENT += 1 ))
fi
local -a commands
commands=(
'new:Create a new worktree'
'go:Navigate to worktree'
'run:Execute command in worktree'
'copy:Copy files between worktrees'
'rm:Remove worktree(s)'
'mv:Rename worktree and branch'
'rename:Rename worktree and branch'
'editor:Open worktree in editor'
'ai:Start AI coding tool'
'ls:List all worktrees'
'list:List all worktrees'
'clean:Remove stale worktrees'
'doctor:Health check'
'adapter:List available adapters'
'config:Manage configuration'
'completion:Generate shell completions'
'init:Generate shell integration for cd support'
'version:Show version'
'help:Show help'
)
local -a branches all_options
# Get branch names
branches=(${(f)"$(git branch --format='%(refname:short)' 2>/dev/null)"})
# Add special ID '1' for main repo
all_options=("1" "${branches[@]}")
# Early handler for `new` command - handle all positions
if (( CURRENT >= 4 )) && [[ $words[3] == new ]]; then
_arguments \
'1:branch name:' \
'--from[Base ref]:ref:' \
'--from-current[Create from current branch]' \
'--track[Track mode]:mode:(auto remote local none)' \
'--no-copy[Skip file copying]' \
'--no-fetch[Skip git fetch]' \
'--no-hooks[Skip post-create hooks]' \
'--force[Allow same branch in multiple worktrees]' \
'--name[Custom folder name suffix]:name:' \
'--folder[Custom folder name (replaces default)]:folder:' \
'--yes[Non-interactive mode]' \
'--editor[Open in editor after creation]' \
'-e[Open in editor after creation]' \
'--ai[Start AI tool after creation]' \
'-a[Start AI tool after creation]'
return
fi
# Early handler for `clean` command
if (( CURRENT >= 4 )) && [[ $words[3] == clean ]]; then
_arguments \
'--merged[Remove worktrees with merged PRs/MRs]' \
'--yes[Skip confirmation prompts]' \
'-y[Skip confirmation prompts]' \
'--dry-run[Show what would be removed]' \
'-n[Show what would be removed]' \
'--force[Force removal even if worktree has uncommitted changes]'
return
fi
# Early handler for `list/ls` command - add --porcelain
if (( CURRENT >= 4 )) && [[ $words[3] == (list|ls) ]]; then
_arguments '--porcelain[Machine-readable output]'
return
fi
# Complete the gtr subcommand (new, go, editor, etc.)
if (( CURRENT == 3 )); then
_describe 'commands' commands
# Complete arguments to the subcommand
elif (( CURRENT == 4 )); then
case "$words[3]" in
go|run|rm|mv|rename|copy)
_describe 'branch names' all_options
;;
editor)
_describe 'branch names' all_options
;;
ai)
_describe 'branch names' all_options
;;
config)
# Complete action or scope flags
_values 'config action' list get set add unset --local --global --system
;;
completion)
# Complete shell names
_values 'shell' bash zsh fish
;;
init)
# Complete shell names
_values 'shell' bash zsh fish
;;
esac
# Complete subsequent arguments
elif (( CURRENT >= 5 )); then
case "$words[3]" in
editor)
_arguments '--editor[Editor to use]:editor:(antigravity atom cursor emacs idea nano none nvim pycharm sublime vim vscode webstorm zed)'
;;
ai)
_arguments '--ai[AI tool to use]:tool:(aider auggie claude codex continue copilot cursor gemini none opencode)'
;;
rm)
_arguments \
'--delete-branch[Delete branch]' \
'--force[Force removal even if worktree has uncommitted changes or untracked files]' \
'--yes[Non-interactive mode]'
;;
mv|rename)
_arguments \
'--force[Force move even if locked]' \
'--yes[Skip confirmation]'
;;
copy)
_arguments \
'-n[Dry-run preview]' \
'--dry-run[Preview without copying]' \
'-a[Copy to all worktrees]' \
'--all[Copy to all worktrees]' \
'--from[Source worktree]:source:->worktrees' \
'*:target:->worktrees'
case "$state" in
worktrees) _describe 'branch names' all_options ;;
esac
;;
init)
_arguments '--as[Custom function name]:name:'
;;
config)
# Find action by scanning all config args (handles flexible flag positioning)
# Use offset 3 to start from words[4] (first arg after 'config')
# Zsh uses 0-based offset: ${array[@]:3} = elements starting from 4th position
local config_action=""
local arg
for arg in "${words[@]:3}"; do
case "$arg" in
list|get|set|add|unset)
[[ -z "$config_action" ]] && config_action="$arg"
;;
esac
done
if [[ -z "$config_action" ]]; then
# Still need action or scope
_values 'config action' list get set add unset --local --global --system
else
case "$config_action" in
list|get)
# Read operations support all scopes including --system
_arguments \
'--local[Use local git config]' \
'--global[Use global git config]' \
'--system[Use system git config]' \
'*:config key:(gtr.copy.include gtr.copy.exclude gtr.copy.includeDirs gtr.copy.excludeDirs gtr.hook.postCreate gtr.hook.preRemove gtr.hook.postRemove gtr.hook.postCd gtr.editor.default gtr.editor.workspace gtr.ai.default gtr.worktrees.dir gtr.worktrees.prefix gtr.defaultBranch gtr.provider gtr.ui.color)'
;;
set|add|unset)
# Write operations only support --local and --global
# (--system may require root or appropriate file permissions)
_arguments \
'--local[Use local git config]' \
'--global[Use global git config]' \
'*:config key:(gtr.copy.include gtr.copy.exclude gtr.copy.includeDirs gtr.copy.excludeDirs gtr.hook.postCreate gtr.hook.preRemove gtr.hook.postRemove gtr.hook.postCd gtr.editor.default gtr.editor.workspace gtr.ai.default gtr.worktrees.dir gtr.worktrees.prefix gtr.defaultBranch gtr.provider gtr.ui.color)'
;;
esac
fi
;;
esac
fi
}
_git-gtr "$@"