Basic Tmux configuration

I started using tmux the past few days. While I have briefly used tmux in the past, and screen before that while in Uni, I didn’t have any config files from back (would be pointless anyways as things have changed) so I set things up from scratch.

I don’t really need something like tmux now. I am not interested in a terminal multiplexor as all I need is session management, so what I should really be using is abduco… but, I was lazy.

Note: This isn’t a very well thought out post as I don’t have much to say, and there are way better posts on the Internet that explain all this better. I just wanted to make a post nevertheless to make a note of these, but to be honest you are better off checking any other blog for the same. For example, this one or the Arch Linux wiki.

Here are a few important settings for your .tmux.conf.

It’s important that the $TERM variable in a tmux session is set to “screen-256color” for things like scrolling within apps to work properly. So I set that as the default in .tmux.conf. This is not enough though, if you are overriding the $TERM in your startup scripts (e.g. .bash_profile) you must make an exception for tmux too. Here’s what I have in my .bash_profile:

If the $TMUX variable is empty it means I am not in a tmux session; so I use that to set my non-tmux terminal preference.

Another important setting is to turn on mouse support. Without this turned on when you scroll up or down your terminal scrolls out of the tmux session. With this turned on scrolling happens within the tmux session.

A lot of people do more fancy stuff here like bind the scroll wheel up and down to other things but I couldn’t get it working. With the basic mouse settings turned on scrolling is limited to the tmux window and that’s all I wanted. At some point I’d also like to get scrolling work with the app I am.

Here’s my status bar settings:

This sets the background and foreground colors. I don’t want the left side indicator so I set it to blank; and all I want on the right is the short hostname and the time.

The tmux status bar is made up of three components: the left & right sides (defined above) and a window status bit in the center (which is aligned to the left if the left side is empty). Here are my window status settings:

I want the status to be the “<window index>:<window name><flags>” where <window name> defaults to the currently running process.

Lastly, since I mostly connect using some terminal window application I also wanted the terminal title to be set correctly. I already set a title via my login profile so I want tmux to simply take its title from there. Hence I have the following:

For this to work the $PROMPT_COMMAND variable must be set so the window is dynamically updated. I have something like this in my login scripts (the prompt is made up for various functions, that’s why it looks odd).

Here’s how my tmux session looks at the end of all this. The window title still has the tmux window & process info, in addition to my shell generated title. I couldn’t figure out a way to get rid of the tmux window & process info and I left it after a while.

I also have the following in my .bash_profile to ensure I always start a tmux session (or connect to a detached one) when I login to something. If I am not SSHing into something then it doesn’t launch tmux as I don’t want to be in a tmux session if I am opening the terminal in my Mac or laptop.

On the tmux side I made two binding key changes:

That’s all for now!