Skip to content

Instantly share code, notes, and snippets.

@logicalgroove
Last active January 3, 2024 02:08
Show Gist options
  • Save logicalgroove/efe4fa1e6a46c9952a13c637d60028fe to your computer and use it in GitHub Desktop.
Save logicalgroove/efe4fa1e6a46c9952a13c637d60028fe to your computer and use it in GitHub Desktop.
Tmux sessions helper
# setup_tmux_session.sh
# chmod +x setup_tmux_session.sh
# Usage: ./setup_tmux_session.sh SESSION_NAME FOLDER_PATH
SESSION_NAME=$1
FOLDER_PATH=$2
# Check if the session exists
tmux has-session -t "$SESSION_NAME" 2>/dev/null
# If the session exists, attach to it
if [ $? -eq 0 ]; then
tmux attach -t "$SESSION_NAME"
else
# Create the session if it doesn't exist
tmux new-session -d -s "$SESSION_NAME" -n 'vim' -c "$FOLDER_PATH"
tmux send-keys -t "$SESSION_NAME" 'vim Gemfile' Enter
# Create additional windows
tmux new-window -t "$SESSION_NAME:" -n 'git' -c "$FOLDER_PATH"
tmux new-window -t "$SESSION_NAME:" -n 'server' -c "$FOLDER_PATH"
tmux new-window -t "$SESSION_NAME:" -n 'console' -c "$FOLDER_PATH"
tmux new-window -t "$SESSION_NAME:" -n 'tests' -c "$FOLDER_PATH"
# Select the initial window
tmux select-window -t "$SESSION_NAME:vim"
fi
#!/bin/zsh
/Users/youruser/.config/tmux/tmux-sessions/setup_tmux_session.sh "someproject" "/path/to/someproject"
alias tmuxsomeproject='. /Users/youruser/.config/tmux/tmux-sessions/tmuxsomeproject.json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment