tmux, create sessions with bash script
introduction
This post is based in my need to start several xterm windows, every time I try to add a new content to this hugo based site.
I made this process more efficient with help of tmux, orchestrated with bash script that help me to achive ’the workspace'.
This workspace contains:
- window with the newest hugo version check in case I decide to update it
- window with list of tags names I use in posts
- window with list categories names I use in posts
- window with running local hugo server
- and finaly window with neovim editor to create new content
template
Bellow script template you can use to extend to you your own needs.
#!/bin/bash
PAGECONTENT="~/myrepo/hugo_page_repository/"
SESH="hugo-development"
tmux has-session -t ${SESH} 2>/dev/null
if [ $? != 0 ]; then
tmux new-session -d -s ${SESH} -n "editor"
tmux send-keys -t ${SESH}:bash "cd ${PAGECONTENT}" C-m
tmux send-keys -t ${SESH}:bash "git status" C-m
tmux new-window -n local_hugo_server
tmux send-keys -t ${SESH}:local_hugo_server "cd ${PAGECONTENT}" C-m
tmux send-keys -t ${SESH}:local_hugo_server "hugo server -D --disableFastRender" C-m
# select editor window as active
tmux select-window -t ${SESH}:editor
fi
tmux attach-session -t ${SESH}
As you see it checks if tmux session named ‘hugo-development’ already exists and if not creates it.
tmux man page contains more information and examples that will be useful to extend above script to address your needs. Also please see ‘source’ section YouTube links, those short clips also contains some interesting ideas that you would like to use in your script.
source
This post was inspired with Tmux in 100 Seconds from Fireship YouTube channel and a few others :