ivan
ivan

Reputation: 6322

tmux status line: use status-left for window-list, use middle-section for something else?

I'm transitioning from GNU Screen to tmux, and trying to configure my tmux status line to mimic the caption I built in Screen.

My Screen caption has the list of windows on the left, hostname and loadavg roughly centered, and the session name on the right:

GNU Screen 0

The window-list stays left, the session name stays right, and the middle-section stays roughly centered, but nudges over to accommodate the window-list if it's long... GNU Screen 2 GNU Screen 6

The closest I can get so far with tmux is:

set-window-option -g window-status-format ' #I #W'
set-window-option -g window-status-current-format ' #I #W'
set -g status-justify left
set -g status-left ''
set -g status-right '#h :: #(sysctl vm.loadavg | cut -d " " -f 3-5) #S '

yielding: enter image description here Is there a way to display the window-list in the status-left section and use the middle-section the way I want?

Upvotes: 4

Views: 11075

Answers (1)

lord.garbage
lord.garbage

Reputation: 5970

Setting this correctly is a bit tricky in tmux. But what you want is achieved by:

set -g status-right '#S'
# set-option -g status-left-length 30
set -g status-left '#I #W'
set-option -g status-justify centre


set-window-option -g window-status-current-format '#h :: #(sysctl vm.loadavg | cut -d " " -f 3-5)'
# Disable showing the default window list component.
set-window-option -g window-status-format '#h :: #(sysctl vm.loadavg | cut -d " " -f 3-5)'

This will give you the load average and hostname in the middle section for every window that you open. If you just want this to appear once and not for every new window again then you have to alter the last to lines:

`set-window-option -g window-status-current-format '#h :: #(sysctl vm.loadavg | cut -d " " -f 3-5)'`

and

 set `set-window-option -g window-status-format ''`

Let me elaborate on this a little. The lines window-status-current-format and window-status-format allow you to alter the window part of your status line. But you don't need to use window variables you can also use #h or any other stuff you want. The difference between window-status-current-format and window-status-format is that the former allows you to specify what is shown when the window in question is the current window and the latter when it is not. I prefer to set both and both to the same value. Once you have that part figured out you can easily format the left and right portion of your status line. Note that when you don't set window-current-status-format and window-status-format then tmux will show it's default window display option. Hence, even if you just want to get rid of the middle part because it interferes with your other settings you need to set both to ''. man tmux is also very useful!

Upvotes: 3

Related Questions