48 lines
1.4 KiB
Bash
48 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Adapted tmux sessionizer for ~/src/github/username/reponame layout
|
|
|
|
SEARCH_PATHS=(
|
|
"$HOME/src/github"
|
|
)
|
|
|
|
if [[ $# -eq 1 ]]; then
|
|
selected=$1
|
|
else
|
|
# Find all directories two levels deep under ~/src/github (username/repo)
|
|
selected=$(find "${SEARCH_PATHS[@]}" -mindepth 2 -maxdepth 2 -type d | fzf)
|
|
fi
|
|
|
|
# Exit if nothing selected
|
|
[[ -z $selected ]] && exit 0
|
|
|
|
selected_name=$(basename "$selected" | tr . _)
|
|
tmux_running=$(pgrep tmux)
|
|
|
|
# Start tmux if not running
|
|
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
|
tmux new-session -s "$selected_name" -c "$selected"
|
|
exit 0
|
|
fi
|
|
|
|
if ! tmux has-session -t="$selected_name" 2> /dev/null; then
|
|
# Create a new session and rename the first window to Shell.
|
|
tmux new-session -ds "$selected_name" -c "$selected"
|
|
tmux rename-window -t "$selected_name:" "shell"
|
|
# Create a second window for Neovim.
|
|
tmux new-window -t "$selected_name:" -c "$selected" -n "neovim"
|
|
tmux send-keys -t "$selected_name:neovim" "nvim" Enter
|
|
# Create a window for git only if this is a git repository.
|
|
if [[ -d "$selected/.git" ]]; then
|
|
tmux new-window -t "$selected_name:" -c "$selected" -n "git"
|
|
tmux send-keys -t "$selected_name:git" "lazygit" Enter
|
|
fi
|
|
# Start with the Shell window selected.
|
|
tmux select-window -t "$selected_name:shell"
|
|
fi
|
|
|
|
if [[ -z $TMUX ]]; then
|
|
tmux attach -t "$selected_name"
|
|
else
|
|
tmux switch-client -t "$selected_name"
|
|
fi
|