36 lines
1.2 KiB
Bash
Executable File
36 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env zsh
|
|
|
|
# usage: session-project <project>
|
|
#
|
|
# Layout for a session created by `session -p <project>`, where <project> is a
|
|
# path in ~/Projects with the prefix removed. The session-created hook passes
|
|
# the project along, taking it from the session environment.
|
|
|
|
project=$1
|
|
repo=$HOME/Projects/$project
|
|
|
|
tmux rename-window home
|
|
$(dirname $0)/window-auto
|
|
|
|
# Without a project there is nothing but the home window, which is all a
|
|
# session created directly from this layout's name can get.
|
|
if [[ -z "$project" ]] || ! git -C "$repo" rev-parse --git-dir &>/dev/null; then
|
|
exit
|
|
fi
|
|
|
|
# The remote's default branch, falling back to whatever HEAD points at for
|
|
# repositories without an origin/HEAD, e.g. those with no remote at all.
|
|
branch=$(git -C "$repo" symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null)
|
|
branch=${branch#origin/}
|
|
if [[ -z "$branch" ]]; then
|
|
branch=$(git -C "$repo" symbolic-ref --short HEAD 2>/dev/null)
|
|
fi
|
|
if [[ -z "$branch" ]]; then
|
|
# Detached HEAD, name the window after the commit it sits on.
|
|
branch=$(git -C "$repo" rev-parse --short HEAD 2>/dev/null)
|
|
fi
|
|
|
|
tmux new-window -c "$repo"
|
|
tmux rename-window "$branch"
|
|
$(dirname $0)/window-auto
|