This post presents a way to assemble tmux into tiling WMs painlessly. You don’t have to change any user habit but gain the fruitful functions of tmux. Tmux just works smarter in tiling WMs.
First all, I using Awesome WM, a tiliing windows manager. It tiles windows automatically according to several pre-set patterns. Individual rules for specific windows can apply as well. With some settings, windows management becomes an effortless and enjoyable process. At least, work efficiency get boosted.
In Awesome, Mod4 + Enter is a very convenient way to call a terminal window onto a workspaces (Desktop). It automatically is assigned a position on the screen, such as the the right corner. It gets very handy when you want to work simultaneously in multiple terminals.
Tmux is an alternative of GNU Screen. Actually, it is a terminal manager, saving the process in multiple terminals, and get to reach them in a convenient way. In Tmux, there are sessions, windows, and panel. Sessions is a collection of windows can be access by a client, i.e. a terminal emulator (xterm). In a window, there can be many panels. Each panel is, actually, a running terminal.
Things get complicated when you want to terminals split the desktop with tmux. Before tmux, I just Mod4+Enter twice. Each terminal is a window object for Awesome WM. And they got tiled automatically. But if you use “urxvt -e tmux” instead of ”urxvt”, things get really nasty. Tmux keeps creating new sessions each time you hit Mod4+Enter, even when you had closed some of them. The number of sessions just keeps adding up. Soon you got lost in huge number of sessions. It even gets really hard to find the which session were you previously working on. And kill these sessions one by one is exhausting. What’s more, tmux it self has a way to manage pannels. Trying to use two ways to manage windows at the same time is really painful.
I searched online, there are some solutions using bash script, but not quite suitable for me. Hence I decided to write one of my one. This is my first time to write a bash script with conditions. Here’s how the script works.
- Create a session when there’s no sessions exists.
- Load last session if there’s no sessions attached.
- Create a new terminal emulator with a session if there’s a session attached already.
Using this script, working in the terminal now become far more delightful. I can kill the terminal emulator anytime I like even it is still running, and press Mod4+Enter to resume it. If I want to work with to terminals I just Mod4+Enter again. Tmux works just like other windows. You can use all the tools assembled in the WM.
Here’s my script: I use urxvt as terminal emulator. You can just run this script instead of urxvt.
#!/bin/bash
#By Zhou Ze Yu 18-06-2011
tmux has-session 2>/dev/null
if [ $? -eq 0 ]; then
aflag=$(tmux ls |grep attached )
echo ${#aflag}
if [ ${#aflag} -ge 5 ]; then
#killall urxvt
urxvt -e tmux new-session
echo already on
else
urxvt -e tmux attach -d
fi
else
urxvt -e tmux new -s x
fi
Hope you like it.
-
dictionaryde2 liked this
-
reallinux liked this
-
adouzzy posted this