Skip to content

Instantly share code, notes, and snippets.

@vpatel95
Created April 8, 2020 19:56
Show Gist options
  • Save vpatel95/c96434a562ba9c3b50dbeb22886e1759 to your computer and use it in GitHub Desktop.
Save vpatel95/c96434a562ba9c3b50dbeb22886e1759 to your computer and use it in GitHub Desktop.
Create tmux sesison with custom setup
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage : $0 <session_name> <machine_type>"
exit 1
fi
session="$1"
machine="$2"
tmux start-server
tmux new-session -d -s $session -n $machine
# Select first pane and change directory to <dir-path>
tmux selectp -t 1
tmux send-keys "cd <dir-path>" C-m
# Split window horizontally and change to <dir-path>
# in run <command> in new pane
tmux splitw -h
tmux send-keys "cd <dir-path>; <command>" C-m
# Select pane 2, tail a log file and split it vertically
tmux selectp -t 2
tmux send-keys "tail -f <log-file-path>" C-m
tmux splitw -v
# Select pane 3 and run ifstat in the pane
tmux selectp -t 3
tmux send-keys "ifstat" C-m
# Create a new-window and name it win2
# Change to a dir and open vim
tmux new-window -t $session:2 -n win2
tmux send-keys "cd <dir-path>; vim" C-m
# Return to first window using name
tmux select-window -t $session:$machine
tmux attach-session -t $session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment