syntaxconfigtmux

tmux.conf: if in key-bindings


(sorry, bad english) My goal: execute a different command depending on a "variable", but with one key-binding.

I want to de/activate the pane-synchronization with S (capital s), because the little s is in use to show the different sessions, but I really dont know how to write that. (Of course I could rebind s, but that little s for Sessions is branded in my mind)

I thought maybe something like this: bind S "if (snychronize-panes=on)"; then "setw synchronize-panes off": else "setw synchronize-panes on"

I tried replacing the "synchronize-panes" with a variable, but I dont know how to write a corret if-clause in the tmux.conf.


Solution

  • This should work, using the built-in variable pane_synchronized and the format version of if-then-else: #{?expression,value-if-true,value-if-false}:

    bind-key S set-window-option -F synchronize-panes #{?pane_synchronized,off,on}
    

    and as Nicholas Marriott says in the comments, if no value is provided to a on/off option, it will simply toggle, so you can simply have:

    bind-key S set-window-option synchronize-panes