Created
August 1, 2017 09:17
-
-
Save sergio1990/b5a656299ec5416e94f5d71224de0171 to your computer and use it in GitHub Desktop.
Example, how to script tmux to recreate a session with predefined windows and panes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROJECT_NAME="article" | |
# Check if a session with a such name already exists | |
tmux has-session -t $PROJECT_NAME | |
# If session does not exists | |
if [ $? != 0 ] | |
then | |
# Create a new session with a specified name and with a windows with name `window1` | |
tmux new-session -s $PROJECT_NAME -n window1 -d | |
# Run rvm command in the window1 | |
tmux send-keys -t $PROJECT_NAME "rvm use 2.3.4" C-m | |
# Split window1 horizontally | |
tmux split-window -h -t $PROJECT_NAME | |
# Run cd command in the just created new pane of the window1 | |
tmux send-keys -t $PROJECT_NAME "cd ~/Downloads" C-m | |
# Split window vertically | |
tmux split-window -v -t $PROJECT_NAME | |
# Create new window with a name window2 | |
tmux new-window -n window2 -t $PROJECT_NAME | |
# Select a first window as an active one | |
tmux select-window -t $PROJECT_NAME:1 | |
fi | |
# Attach to the session with a specified name | |
tmux attach -t $PROJECT_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment