tmux: how to toggle "on" and "off" options with the same key
Solution 1:
If you don't explicitly specify "on" or "off", the option will get toggled. The following would suffice:
bind-key a set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
Solution 2:
don't attach on or off. it's toggle
bind-key a set-window-option synchronize-panes
Solution 3:
This should be possible with a combination of run-shell
and tmux show-option
, something like (tested in tmux 2.3):
bind a run-shell "if [[ `tmux show-options -w | grep 'synchronize-panes.*on'` ]]; then toggle=off; else export toggle=on; fi; tmux display-message \"sync panes tmux: \$toggle\"; tmux set-option -w synchronize-panes \$toggle &> /dev/null"
(this is a variation of a mouse-mode toggle found on the TMux user mailing list)