'Tmux - how to execute a command automatically when changing window panes?

Is there a way to execute a command automatically every time I change panes in tmux?

Of course I could execute it manually, but I'm trying to fix a glitch in colors automatically [1]. I'm using tmux 2.6, on Ubuntu 18.04.

thanks!

--

[1] for context: I'm changing pane colors automatically based on the current user (so root would have a different pane color), and change the fg/bg based on active/inactive window. Everything works fine, but there's some edge cases where I need to issue a tmux refresh-client. So I'm trying to have the refresh-client running automatically every time I change panes.



Solution 1:[1]

I think these should do the trick:

tmux set-hook window-pane-changed refresh-client
tmux set-hook session-window-changed refresh-client
tmux set-hook session-changed refresh-client

But I only tested it with 'display-message hi' as the command, so it’s possible that the refresh-client won’t work as expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lucas Werkmeister