Improve git worktree session workflow

This commit is contained in:
2026-08-10 12:42:53 +01:00
parent c97c9cb027
commit 56b5bdb5ac
6 changed files with 67 additions and 4 deletions

View File

@@ -57,7 +57,21 @@ if [[ "${1:-}" == --pick ]]; then
) || exit 0
[ -n "$project" ] || exit 0
tmux new-window -n "$project" -c "$projects_dir/$project"
# Inside a session for this same project, e.g. one created by `session -p`,
# the slug only repeats the session name, so name the window after the branch
# checked out there instead — a worktree's whole identity. Everything up to
# the `@` is the clone the worktrees hang off, and tmux rewrote `.` and `:` in
# the session name, so match both before comparing.
window_name=$project
session=$(tmux display -p '#S')
root=${project%%@*}
if [ "${root//[.:]/_}" = "$session" ]; then
branch=$(git -C "$projects_dir/$project" symbolic-ref --short HEAD 2>/dev/null ||
git -C "$projects_dir/$project" rev-parse --short HEAD 2>/dev/null || true)
window_name=${branch:-$project}
fi
tmux new-window -n "$window_name" -c "$projects_dir/$project"
~/.local/share/tmux/layouts/window-auto
exit
fi