💻 A neat tmux setup


2021-01-14

This is just a quick little post. As i mentioned before i am currently using newsboat to manage my subscriptions to various YouTube channels. I really like the CLI approach of newsboat and decided to give a few other CLI tools a try.

In order to have a more compact setup and not spread all those tools over several workspaces in my i3wm i opted into putting them all into one tmux session. But starting them all manually is a pain in the backside, so i started to look for a way to start them all with a single command. I created a new function in my .zshrc which consists of the following few lines:

function pim {
    tmux new-session -d -s pim -n newsboat 'newsboat'
    tmux new-window -t '=pim:' -d -n ikhal 'ikhal'
    tmux new-window -t '=pim:' -d -n aerc 'aerc'
    tmux new-window -t '=pim:' -d -n local 'zsh'
    tmux new-window -t '=pim:' -d -n loriot 'mosh loriot'
    tmux attach -t pim
}

In this function i create a new session called pim and directly start newsboat in it. Since creating a tmux session or a new tmux window is blocking (because you are attaching your terminal to that session/window), every operation has to contain the -d flag in order to directly detach from that session/window again. After the session i create four windows and start several programs within them. Using the -t flag, i attach all these windows to the pim session. The way tmux windows works is that they attach to the first session they can find. By using this =pim notation the windows attach to the exact session name. The colon at the end is there for me to indicate that the newly created window will be added at the end of the windowlist within that session. After all that windows have been created and the tools have been started within them, the last thing is to attach to the newly created session by issuing the last command tmux attach -t pim. As you can see i have not created a window for khal. That's because i added khal to the addresslookup of aerc. With that i have all my tools in a single terminal window. To stop everything I created another small function which is kalled kill-pim and within that i execute a simple tmux kill-session -t pim. This approach is not without flaws as i have to check that this shuts down everything since tmux only sends a SIGHUP to each window. But so far i never noticed any problems with that.

Here you have it. A small, neat setup to start a customized tmux session with the tools you need.

Tags: #cli #tmux

If you want to send me a message feel free to contact me via my mastodon account. You can find me over at Fosstodon.