Improve git worktree session workflow
This commit is contained in:
16
project.sh
16
project.sh
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user