Dropping status bars for tmux
By Calum MacRae
December 6, 2012
As I'm sure some of my readers know, I run Linux on an 11" MacBook Air as my 'daily driver' machine. I love smaller laptops, especially one as tiny as the Air. But of course, when you're using a machine with a small display, screen real estate is a primary concern for some, it's always nice to squeeze as many pixels as you can out of your desktop, y'know, use the space for useful stuff, the stuff you actually want to see!
Now, don't get me wrong, I like bars on the desktop. Slim, simple, and in good taste, pretty easy on the eyes too (not you, i3bar…). I've used a bar on my desktop ever since I started ricing my setups, I've used many (tint2, conky, conky-cli piped to dzen2, bipolarbar, etc…).
However, I realised that my bar always had such little info being displayed. I don't minimize any windows, so a minimized/quicklist window selection section wasn't necessary. I use dmenu to launch any applications, so an application menu isn't needed.Then the rest of the stuff I do is in the shell, so I only really needed a bar for status information at a quick glance, I figured "There's gotta be somewhere more convenient I can put this."
I've often read of tmux and it's excellent features, and advantages over GNU screen. But, unbeknownst to myself until recently, you can get pretty fancy with it and have it display things in status bars. Since I always have a shell open, this seemed to be the perfect solution to getting rid of my bar (keep in mind, this is not the intended primary use of tmux, nor does it demonstrate it's other capabilities. It's so much more than this, I've really been enjoying using it - go read about it!)
Since I was using conky as my last bar (which had some 'built in' widgets, I needed some shell scripts that would get the same info, then I could just call them from tmux - modular, how it's supposed to be - nice!
Here's what I want to see at a glance:
- Wifi status (ESSID of connected network & signal strength)
- System volume
- Battery life
- MPD - Now playing (artist name - track title)
So, I've almost accomplished this, but we'll get to that in a minute…
All scripts and tmux config listed at the bottom
Launching tmux with the shell [a bit of a tangent]
How terribly inconvenient would it be if that every time we launch our
terminal emulator, we have to take a whole second to type
is precious people!
So, obviously, the best way to tackle this would be to just have tmux execute when you launch a shell. Now, there's various aspects that have to be taken into consideration here; what window manager/desktop environment you're using, which terminal emulator you're using, hell even which shell you use. Fortunately, it should be relatively easy to work out.
There does seem to be several suggested ways of achieving this, but to
me it just makes sense to tell which ever means you have of launching
your terminal to execute
tmux when it opens.
I use urxvt as my terminal emulator, appending -e and giving a command
will open the shell and execute said command. In this case we want
urxvt -e tmux . As I'm using i3
as my window manager, I just set the below line in my config to bind the
sensible terminal variable (defined earlier in the config as urxvtc),
with the execute argument, appended with
tmux to mod4+Return:
bindsym $mod+Return exec i3-sensible-terminal -e tmux
Now, whenever I launch a shell by hitting mod4+Return, I'm greeted with a tmux session!
Stop blabbing, what does it look like?!
And here's the end result
Pretty useful right? Click the image below to take a look at my current desktop without any bar.
Gimme, gimme, gimme
So you like it? Welp, here're the scripts!
#! /bin/sh iwgetid | cut -d '"' -f 2
#! /bin/sh exec amixer get Master | egrep -o "[0-9]+%" | egrep -o "[0-9]*"
#! /bin/sh echo "♥" $(acpi | cut -d ',' -f 2)
Edit: The above scripts were in fact a lot messier and bigger previously. Fortunately, WonderWoofy from the Arch Linux forums gave my post a read and generously contributed! Yay for Woofy!
Relevant lines from ~/.tmux.conf
# Info on right set -g status-right-length 60 set -g status-right '#[fg=brightblue] #[fg=brightyellow]vol: #(sh ~/.tmux/scripts/volume)
#[fg=black]| #[fg=brightred]#(sh ~/.tmux/scripts/battery) #[fg=colour7]| #[fg=brightgreen]%a %H:%M' # Info on left set -g status-left-length 60 set -g status-left '#[fg=brightgreen]wl: #(sh ~/.tmux/scripts/wifi)'
I hope this post helps anyone who's looking for a similar setup. As always, feeback is greatly appreciated!
- Posted on:
- December 6, 2012
- 4 minute read, 795 words