wtcode 0.1.3__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wtcode/__init__.py +1 -1
- wtcode/wtcode.sh +91 -7
- {wtcode-0.1.3.dist-info → wtcode-0.2.0.dist-info}/METADATA +2 -2
- wtcode-0.2.0.dist-info/RECORD +9 -0
- {wtcode-0.1.3.dist-info → wtcode-0.2.0.dist-info}/WHEEL +1 -1
- wtcode-0.1.3.dist-info/RECORD +0 -9
- {wtcode-0.1.3.dist-info → wtcode-0.2.0.dist-info}/entry_points.txt +0 -0
- {wtcode-0.1.3.dist-info → wtcode-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {wtcode-0.1.3.dist-info → wtcode-0.2.0.dist-info}/top_level.txt +0 -0
wtcode/__init__.py
CHANGED
wtcode/wtcode.sh
CHANGED
|
@@ -16,7 +16,7 @@ ${WTCODE_DEBUG:+set -x}
|
|
|
16
16
|
sed 's/^-//; s/-$//' # trim leading/trailing hyphens
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
WTCODE_VERSION=0.
|
|
19
|
+
WTCODE_VERSION=0.2.0
|
|
20
20
|
--version() { echo "wtcode $WTCODE_VERSION"; }
|
|
21
21
|
--help() {
|
|
22
22
|
cat <<USAGE
|
|
@@ -27,8 +27,9 @@ Usage: wtcode [BRANCH] [CMD [CMD-ARGS...]]
|
|
|
27
27
|
|
|
28
28
|
BRANCH Git branch or worktree name to switch to.
|
|
29
29
|
If omitted and fzf is available, interactively select one.
|
|
30
|
-
|
|
31
|
-
(use multiple colons to avoid fzf matching, e.g., :::my-branch
|
|
30
|
+
Surround with ':' to force creating a new branch
|
|
31
|
+
(use multiple colons to avoid fzf matching, e.g., :::my-branch
|
|
32
|
+
or my-branch:::).
|
|
32
33
|
|
|
33
34
|
CMD Command to launch in the worktree (default: \$WTCODE_CMD,
|
|
34
35
|
or first available of: ${WTCODE_CMDS_TO_TRY[*]}, \$SHELL).
|
|
@@ -37,6 +38,11 @@ Usage: wtcode [BRANCH] [CMD [CMD-ARGS...]]
|
|
|
37
38
|
|
|
38
39
|
Environment variables:
|
|
39
40
|
WTCODE_CMD Default tool to launch (e.g., claude, lazygit, vim)
|
|
41
|
+
WTCODE_TMUX_MODE When in tmux, control how the tool is launched:
|
|
42
|
+
send-keys - send command to current pane (default in tmux)
|
|
43
|
+
split-window - create split pane with send-keys
|
|
44
|
+
new-window - create new window with send-keys
|
|
45
|
+
exec - exec the tool directly (opt out of send-keys)
|
|
40
46
|
WTCODE_DEBUG Enable debug tracing when set
|
|
41
47
|
GIT_WORKTREE_ROOT Override the directory where worktrees are created
|
|
42
48
|
|
|
@@ -127,13 +133,14 @@ WTCODE_CMDS_TO_TRY=(
|
|
|
127
133
|
exit 1
|
|
128
134
|
fi
|
|
129
135
|
|
|
130
|
-
#
|
|
131
|
-
#
|
|
136
|
+
# leading or trailing ':' forces new branch creation
|
|
137
|
+
# multiple colons (e.g., :::my-branch or my-branch:::) help avoid fzf matching
|
|
132
138
|
local force_new_branch=false
|
|
133
|
-
if [[ $branch_name == :* ]]; then
|
|
139
|
+
if [[ $branch_name == :* || $branch_name == *: ]]; then
|
|
134
140
|
force_new_branch=true
|
|
135
141
|
branch_name=${branch_name##+(:)}
|
|
136
|
-
|
|
142
|
+
branch_name=${branch_name%%+(:)}
|
|
143
|
+
: ${branch_name:?non-empty branch name required around ':'}
|
|
137
144
|
fi
|
|
138
145
|
|
|
139
146
|
# sanitize free-form text into a valid git branch name
|
|
@@ -155,6 +162,19 @@ WTCODE_CMDS_TO_TRY=(
|
|
|
155
162
|
done
|
|
156
163
|
fi
|
|
157
164
|
|
|
165
|
+
# if the branch is already checked out on a worktree, use that worktree
|
|
166
|
+
# regardless of its directory name — avoids "already checked out" failures
|
|
167
|
+
# when branches and worktree directories have drifted apart (e.g., after
|
|
168
|
+
# something like claude ran `git checkout` inside a worktree)
|
|
169
|
+
if ! $force_new_branch && [[ -z ${remote_branch-} ]]; then
|
|
170
|
+
local existing_worktree
|
|
171
|
+
existing_worktree=$(git for-each-ref --format='%(worktreepath)' "refs/heads/$branch_name" 2>/dev/null)
|
|
172
|
+
if [[ -n $existing_worktree ]]; then
|
|
173
|
+
--msg "branch '$branch_name' is checked out at: $existing_worktree"
|
|
174
|
+
cd "$existing_worktree"
|
|
175
|
+
return 0
|
|
176
|
+
fi
|
|
177
|
+
fi
|
|
158
178
|
|
|
159
179
|
# 2. create or switch to the worktree
|
|
160
180
|
cd "$(git rev-parse --show-toplevel)"
|
|
@@ -167,6 +187,24 @@ WTCODE_CMDS_TO_TRY=(
|
|
|
167
187
|
)}
|
|
168
188
|
|
|
169
189
|
local worktree_path="$GIT_WORKTREE_ROOT"/"$branch_name"
|
|
190
|
+
|
|
191
|
+
# if the default worktree directory exists but holds a different branch
|
|
192
|
+
# (e.g., something like claude swapped branches with `git checkout`), pick
|
|
193
|
+
# a fresh numbered suffix instead of stealing it. branch-is-checked-out
|
|
194
|
+
# case is already handled above, so we only need to check the default path.
|
|
195
|
+
if [[ -e "$worktree_path"/.git ]]; then
|
|
196
|
+
local existing_branch
|
|
197
|
+
existing_branch=$(git -C "$worktree_path" branch --show-current 2>/dev/null)
|
|
198
|
+
if [[ -n $existing_branch && $existing_branch != "$branch_name" ]]; then
|
|
199
|
+
--msg "$worktree_path holds branch '$existing_branch'; picking a new path for '$branch_name'"
|
|
200
|
+
local n=2
|
|
201
|
+
while [[ -e "$GIT_WORKTREE_ROOT/$branch_name-$n" ]]; do
|
|
202
|
+
n=$((n+1))
|
|
203
|
+
done
|
|
204
|
+
worktree_path="$GIT_WORKTREE_ROOT/$branch_name-$n"
|
|
205
|
+
fi
|
|
206
|
+
fi
|
|
207
|
+
|
|
170
208
|
if [[ -e "$worktree_path"/.git ]]; then
|
|
171
209
|
--msg "using existing worktree: $worktree_path"
|
|
172
210
|
elif [[ -n ${remote_branch-} ]] && ! git rev-parse --verify "refs/heads/$branch_name" &>/dev/null; then
|
|
@@ -204,6 +242,52 @@ WTCODE_CMDS_TO_TRY=(
|
|
|
204
242
|
fi
|
|
205
243
|
|
|
206
244
|
--msg "launching: $*"
|
|
245
|
+
|
|
246
|
+
# when inside tmux, default to send-keys for command history access
|
|
247
|
+
# set WTCODE_TMUX_MODE=exec to opt out and exec directly
|
|
248
|
+
if [[ -n ${TMUX:-} ]] && type tmux &>/dev/null; then
|
|
249
|
+
local mode=${WTCODE_TMUX_MODE:-send-keys}
|
|
250
|
+
|
|
251
|
+
case $mode in
|
|
252
|
+
send-keys|split-window|new-window)
|
|
253
|
+
local worktree_path="$PWD"
|
|
254
|
+
# quote each argument for shell safety
|
|
255
|
+
local quoted_args=()
|
|
256
|
+
for arg in "$@"; do
|
|
257
|
+
quoted_args+=("$(printf '%q' "$arg")")
|
|
258
|
+
done
|
|
259
|
+
local cmd="cd $(printf '%q' "$worktree_path") && ${quoted_args[*]}"
|
|
260
|
+
|
|
261
|
+
case $mode in
|
|
262
|
+
send-keys)
|
|
263
|
+
# send to current pane
|
|
264
|
+
tmux send-keys "$cmd" Enter
|
|
265
|
+
return 0
|
|
266
|
+
;;
|
|
267
|
+
split-window)
|
|
268
|
+
# create split, send there
|
|
269
|
+
tmux split-window -v -c "$worktree_path"
|
|
270
|
+
tmux send-keys "$cmd" Enter
|
|
271
|
+
return 0
|
|
272
|
+
;;
|
|
273
|
+
new-window)
|
|
274
|
+
# create window, send there
|
|
275
|
+
tmux new-window -c "$worktree_path"
|
|
276
|
+
tmux send-keys "$cmd" Enter
|
|
277
|
+
return 0
|
|
278
|
+
;;
|
|
279
|
+
esac
|
|
280
|
+
;;
|
|
281
|
+
exec)
|
|
282
|
+
# explicitly opt out of send-keys, fall through to exec
|
|
283
|
+
;;
|
|
284
|
+
*)
|
|
285
|
+
--msg "unknown WTCODE_TMUX_MODE: $mode (expected: send-keys, split-window, new-window, exec)"
|
|
286
|
+
;;
|
|
287
|
+
esac
|
|
288
|
+
fi
|
|
289
|
+
|
|
290
|
+
# outside tmux, WTCODE_TMUX_MODE=exec, or unknown mode: exec directly
|
|
207
291
|
if [[ $(type -t "$1") == function ]]; then
|
|
208
292
|
"$@"
|
|
209
293
|
else
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: wtcode
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Launch your favorite code tool in a git worktree
|
|
5
5
|
Author-email: Jaeho Shin <netj@sparcs.org>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -59,7 +59,7 @@ wtcode [BRANCH] [CMD [CMD-ARGS...]]
|
|
|
59
59
|
wtcode --exec CMD [CMD-ARGS...]
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
- **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one.
|
|
62
|
+
- **`BRANCH`** -- Git branch or worktree name. If omitted and [fzf](https://github.com/junegunn/fzf) is available, interactively select one. Surround with `:` to create a new branch (use `:::name` or `name:::` to avoid fzf matching the colons).
|
|
63
63
|
- **`CMD`** -- Command to launch in the worktree. Defaults to `$WTCODE_CMD`, or the first available of: `claude`, `aider`, `codex`, `$SHELL`.
|
|
64
64
|
- **`--exec`** -- Skip the branch argument; select interactively via fzf, then launch `CMD`.
|
|
65
65
|
- **`--help`** / **`--version`** -- Show help or version info.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
wtcode/__init__.py,sha256=8wIDZvCqXSwHi1obGTZsqnp-Zkf1KeYS-S3nx1vmTOY,89
|
|
2
|
+
wtcode/__main__.py,sha256=hOvSYANO-q_rf2yy-AQoEOr18KFRSOF8Ezosf8eeFmM,335
|
|
3
|
+
wtcode/wtcode.sh,sha256=tEljKNqwz899AuGUUn6IJUZd1a1whRH_UV0Xf5GanK8,13425
|
|
4
|
+
wtcode-0.2.0.dist-info/licenses/LICENSE,sha256=MV9gr1nAVj5R60EM2BQuBhBxCG5V9ulX6-Ep_-LcLqA,1067
|
|
5
|
+
wtcode-0.2.0.dist-info/METADATA,sha256=kEnP6efh4xTOr5vKH4Te-Wj8y2zqGEx5Ca6A7GVwSps,3477
|
|
6
|
+
wtcode-0.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
7
|
+
wtcode-0.2.0.dist-info/entry_points.txt,sha256=QkSPHU86FQa-ujQk07fF4sX4DBQgWzDtgusop4AA5bc,48
|
|
8
|
+
wtcode-0.2.0.dist-info/top_level.txt,sha256=oftTSYYjDMqt33wa0c9MC15KuQ3eyRyoTLXy3PdkVfE,7
|
|
9
|
+
wtcode-0.2.0.dist-info/RECORD,,
|
wtcode-0.1.3.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
wtcode/__init__.py,sha256=aagDFL0zLWWaQTknxcP1XubMjiDKeOS3qlUI_tAMapc,89
|
|
2
|
-
wtcode/__main__.py,sha256=hOvSYANO-q_rf2yy-AQoEOr18KFRSOF8Ezosf8eeFmM,335
|
|
3
|
-
wtcode/wtcode.sh,sha256=Q6Gywz2BI-O3zWI8nNHfQ8IMra9gdfp2J-9xRrFsQIY,10051
|
|
4
|
-
wtcode-0.1.3.dist-info/licenses/LICENSE,sha256=MV9gr1nAVj5R60EM2BQuBhBxCG5V9ulX6-Ep_-LcLqA,1067
|
|
5
|
-
wtcode-0.1.3.dist-info/METADATA,sha256=LE_h7cswIGiqrPFwnn8gJFhLu5hEugFjcFosKRtv_2g,3462
|
|
6
|
-
wtcode-0.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
-
wtcode-0.1.3.dist-info/entry_points.txt,sha256=QkSPHU86FQa-ujQk07fF4sX4DBQgWzDtgusop4AA5bc,48
|
|
8
|
-
wtcode-0.1.3.dist-info/top_level.txt,sha256=oftTSYYjDMqt33wa0c9MC15KuQ3eyRyoTLXy3PdkVfE,7
|
|
9
|
-
wtcode-0.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|