Here's the default setting of an option in ~/.tmux.conf:

set -gw window-status-format " #I:#W#{?window_flags,#{window_flags}, } "

The problem I have with this is that the space character at the beginning of the value isn't being applied to the first window's name (in the window's list in the status bar) when it's not active, unlike all other windows where it's applied irrespectively. So there's this movement in the windows list whenever I switch to the first window (due to the space character being added then) which I feel is distracting. This shouldn't happen.

So what I want is, I want to set window-status-format to:

  • "#I:#W#{?window_flags,#{window_flags}, } " if window_index is 0 (i.e. target first window name).
  • " #I:#W#{?window_flags,#{window_flags}, } " if window_index is anything else.

It'd appear something like this:

set -gw window-status-format "#{?window_index=0,"#I:#W#{?window_flags,#{window_flags}, } "," #I:#W#{?window_flags,#{window_flags}, } "}"

But that's definitely not the right tmux command (obviously it doesn't work) for various reasons:

  1. Surely, that's not the right syntax to check if window_index is equal to 0.
  2. Can we have multiple conditionals in the same tmux config. command?

So, how do I do this right?


Looks like instead of using multiple conditionals, this could be done using specificity. All I had to do was add this to my ~/.tmux.conf:

set -gw window-status-format " #I:#W#{?window_flags,#{window_flags}, } "
set -w -t :0 window-status-format "#I:#W#{?window_flags,#{window_flags}, } "

If it's not obvious already:

  • The first tmux command sets the global value, for all windows irrespective of session. (This is also the default setting, you don't need this line at all.)

  • The next command specifies the value for a target-window (again, irrespective of session). In our case, we are saying, if the index of the target window, i.e. window_index, is 0, i.e. if the target window is also the first window in the session, apply the value.

    It's interesting that -t (target-window) option also targets the respective window's name in the status bar. If not for this, this solution wouldn't be one.


  • If you are using different base index, e.g. set -g base-index 1, so that it starts from 1 instead of 0, then you'd have to use :1 in the above command.

  • You'll need a solution for this as you'll see an error when you create a new session, but of course, you can work around it like I described there.

|improve this answer|||||

I found another solution:

is_first="#([ $(tmux display-message -p '#I') = $(tmux show-options -gqv base-index) ] && echo true)"
set -gw window-status-format "#{?$is_first,First is active,}"
|improve this answer|||||
  • 1
    Can you explain how this answers the question? Please do not respond in comments; edit your answer to make it clearer and more complete. – Scott Jun 5 '19 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.