Tmux identify if pane is zoomed and active

I use tmux 1.8 so I have built in CTRL+b+z feature to zoom an active pane.
The problem is that zoomed pane looks the same as just one plain pane so sometimes I forget if the pane was zoomed. Is there a way to add an indication that I am currently in the zoom mode?

Also the same issue is with horizontally split panes. It’s hard to remember that if the border on the left corresponds to the active upper pane and vice versa. Can I make that more distinct? Maybe add horizontal borders if that’s possible?

Asked By: Glueon

||

Tmux adds a Z to the end of the window name in the status bar to indicate that the pane is zoomed. Or at least the 1.9 version I’m using does this by default.

Answered By: Steve Wills

At the same time as the zoom feature, the window_flag with the same name Z was added, so this flag should appear in the status line next to the window title (you mention in a comment that you use some plugin/customization of tmux).


In any case, you can query tmux using the list-panes command and the formats feature:

 tmux list-panes -F '#F'

prints out all the window flags of the currently active pane. If Z is among the flags, the current pane is zoomed. Thus, the command

 tmux list-panes -F '#F' | grep -q Z

will return 0 if the current pane is zoomed and return error 1 in case it isn’t. This should allow you to add this indicator to your customized status line.


From man tmux:

 FORMATS

 Certain commands accept the -F flag with a format argument.  This is a
 string which controls the output format of the command.  Replacement
 variables are enclosed in ‘#{’ and ‘}’, for example ‘#{session_name}’.
 The possible variables are listed in the table below, or the name of a
 tmux option may be used for an option's value.  Some variables have a
 shorter alias such as ‘#S’, and ‘##’ is replaced by a single ‘#’.

 [...]

 Variable name          Alias    Replaced with
 [...]
 window_flags           #F       Window flags

Looking at the source code (window.c, line 639f) shows that the complete list of flags is:

 #:  window activity flag
 !:  window bell flag
 ~:  window silence flag
 *:  current window flag
 -:  last window flag
 Z:  window zoomed flag
 ' ' (a space):  no flags at all.
Answered By: ariane

By default, zoom is indicated using #F but it is possible to create custom indicators using #{?...}

Using #F

Add this to the tmux configuration file

# Display the window flag next to window name
set -g window-status-format " #I #W#F "

The last tab has two flags * for current tab and Z for zoomed

enter image description here

Using #{?...}

Add this to the tmux configuration file

# Display whatever you want when the window is zoomed or not zoomed
#   - zoomed = '+' 
#   - not zoomed = ' '
set -g window-status-format " #I #W#{?window_zoomed_flag,+, } "

The last tab has the + for zoomed

enter image description here

Details

In the status bar, you can customize the window status to show that the window is zoomed. You configure this in your tmux config (man) and you can find (or create) your config in a couple different places (man)

  • set -g window-status-format decides how the tabs in the status bar are formatted
    • set -g window-status-current-format decides how the current tab is formatted
  • #I is the window index
  • #W is the window name
  • #F are the window’s flags
  • #{?A,B,C} is a conditional, if A != 0, use B, else use C
  • window_zoomed_flag is 0 when not-zoomed and 1 when zoomed

tmux’s format syntax has a lot of really interesting variables that can be combined with conditionals to do just about anything (man)

Answered By: NonlinearFruit
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.