Skip to content

Instantly share code, notes, and snippets.

@mightbxg
Created July 13, 2022 11:52
Show Gist options
  • Save mightbxg/2c8f8e3a3531d2a5af900ac22bc15441 to your computer and use it in GitHub Desktop.
Save mightbxg/2c8f8e3a3531d2a5af900ac22bc15441 to your computer and use it in GitHub Desktop.
auto tmux session example
#!/usr/bin/env bash
session='xx'
# check session exists
tmux has-session -t $session 2>/dev/null
if [ $? -eq 0 ]; then
read -p "tmux session [$session] already exists, kill it and reopen one? [Y/n]" -n 1 -r
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
echo "abort."
exit
else
tmux kill-session -t $session
fi
fi
tmux new -s $session \; \
split-window -v \; \
send-keys "cd ~/xx" ENTER \; \
send-keys "clear" ENTER \; \
send-keys "source setup.zsh" ENTER \; \
send-keys "something dummy" \; \
\
select-pane -t 0 \; \
split-window -h \; \
select-pane -t 0 \; \
send-keys "cd ~/xxx/xx" ENTER \; \
send-keys "clear" ENTER \; \
send-keys "xx" ENTER \; \
\
split-window -v \; \
send-keys "xxxx" ENTER \; \
send-keys "some_dummy_command" ENTER \; \
\
select-pane -t 3 \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment