tmux hooks - update status bar colour depending on window and pane

44 views
Skip to first unread message

Billy Bromell

unread,
Jan 5, 2021, 2:35:44 PM1/5/21
to tmux-users

Hi

I'm trying to set up tmux so that the when the active pane is the pane that the session started with, the status bar is a different colour to that of when it is in a pane that has been created later. Here is what I have so far:

set-hook -g session-created 'select-pane -m; rename-window netkit-vm; set -t 0 remain-on-exit on'
set-hook -g pane-focus-in 'if -F "#{==:#{pane_marked},1}" "set status-style bg=#c78add" "set status-style bg=blue"'

The second hook works - whenever i move to a marked pane the status bar turns purple, and whenever i move to an unmarked pane it turns blue.

However when I'm using multiple sessions, it seems that only one of them has a marked pane. I wasn't sure if "set -g" was the right option but the rename-window part of the hook seems to work as all sessions have the first window named correctly.

Is a pane mark global to a tmux server (running all sessions under `tmux -L netkit` ) ? I thought they were session specific rather than server specific?

As the pane that i want the purple active status bar for, should always have window_name 'netkit-vm', pane_index 0 - this might be useful for the pane-focus hook but i couldnt work out an if statement that worked.

Any help would be appreciated!!

Billy

Nicholas Marriott

unread,
Jan 5, 2021, 3:08:12 PM1/5/21
to Billy Bromell, tmux-users
The marked pane is server wide.

If your tmux is new enough (built from master or 3.2-rc) you could set a user option on the pane you started with and then check it in status-style, for example:

set -p @firstpane 1
set -g status-style 'bg=#{?@firstpane,red,blue}'

Or just check its name, something like (not tested):

set -g status-style 'bg=#{?#{&&:#{==:#{window_name},netkit-vm},#{==:#{pane_index},0}},red,blue}'


--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/8379d701-2df8-4163-ab8d-12d89eb25d40n%40googlegroups.com.

Billy Bromell

unread,
Jan 6, 2021, 12:01:37 AM1/6/21
to tmux-users
Thank you !

I'm working on a tool that will be used by other people who likely won't have the latest tmux version - so the second one is a better option for now.

I tried to do this before but was missing the && bit. It still isn't quite working - ive currently got:

set-hook -g pane-focus-in 'set -g status-style "bg=#{?#{&&:#{==:#{window_name},netkit-vm},#{==:#{pane_index},0}},red,blue}"'

When i switch panes it fails with Bad style: bg=#{?#{&&:#{==:#{window_name},netkit-vm},#{==:#{pane_index},0}},red,blue}

but when i replace "set -g status-style" with "display-message" i see bg=blue or bg=red, so I'm assuming theres some kind of syntax that allows it to evaluate the statement but I'm not sure where?

Cheers,
Billy

Nicholas Marriott

unread,
Jan 6, 2021, 12:06:46 AM1/6/21
to Billy Bromell, tmux-users
Styles do not support formats unless you use a very new tmux, so you will not be able to do it like this.

You may be able to check the variable with if-shell -F instead, for example 

set-hook -g pane-focus-in "if -F '#{==:#{window_name},netkit-vm}' 'set status-style bg=blue' 'set status-style bg=red'"

You change the format to whatever you like.


Billy Bromell

unread,
Jan 6, 2021, 9:20:52 AM1/6/21
to tmux-users
Perfect thank you! It's working just how I want now!
Reply all
Reply to author
Forward
0 new messages