jasonwryan.com

Miscellaneous ephemera…

Setting tmux statusbar if in X

Arch Linux: dwm, tmux & scratchpad

I have been posting quite a bit about tmux of late1. It is a marvellous application and lends itself to all sorts of interesting uses. When you first install it, you will find a number of user config files in /usr/share/tmux/. I started with tmux by copying Thayer’s config across and then working up from there. There is a section at the bottom of this file that has always puzzled me, and so I decided to get to the bottom of it.

1
2
# show some useful stats but only when tmux is started
# outside of Xorg, otherwise dwm statusbar shows these already 

It is a great idea. If you are running tmux in X, then you have dwm’s status bar telling you what the time is, how much battery you have left etc,. You don’t need to replicate that functionality in tmux. If, however, you are in the console, you don’t have that information, unless you print it in tmux’s statusbar.

I had tried to get this to work once or twice over the last couple of years, but never persevered with it. However, as I have been doing a bit of work making the console as functional as possible2, I thought I would revisit it.

image

The insight that I had that got it working for me was to use the source-file option in .tmux.conf to call the relevant statusbar, depending if X was running or not. I just adapted Thayer’s code, like so:

1
2
3
# Statusbar starting in X or not
if '[ -n "$DISPLAY" ]' 'source-file ~/.tmux/inx'
if '[ -z "$DISPLAY" ]' 'source-file ~/.tmux/xless'

And then created those files with the desired statusbar options. So, for example, if I am running tmux in the console, $HOME/.tmux/xless is loaded:

1
2
3
4
5
# Statusbar if tmux run in console
# information normally in dwm bar
set -g status-right-length 50
set -g status-left-length 50
set -g status-left "#[fg=green] #H #[default] …blah, blah, blah…

Which prints a statusbar with the time and battery left on my laptop3:

image

All the relevant files are in my mercurial repo.

Notes
  1. Copy & paste in tmux, Sessions in tmux & Introduction to tmux

  2. Vim colours in the console

  3. Image squashed to fit the requirements of this blog…

Comments