Last Updated: March 06, 2017
·
14.19K
· rican7

Checking the version of Tmux in a tmux.conf

Tmux 1.9 was just released today!

Which is awesome... but it changed a feature I really liked. Tmux, when creating a new window, used to start in the same directory as the one that you're current window was in. It made for a predictable flow.

Luckily its easily fixed with a redefinition of the "new-window" key binding in your tmux.conf file. So, I made the change and pushed it, then checked to see if it would still behave on my older box with tmux 1.6 (out of my hands)... and it failed.

So, how can we create statements, set options, or define key bindings based on a version in a tmux.conf file? Here's how:

# Use "if-shell" to run a bash command
# and check the version string of tmux
if-shell "[[ `tmux -V` == *1.9 ]]" 'command-to-be-run-here'

So, how did I actually change the binding for 1.9 only? Like this:

# For 1.9 - Make new windows start in the
# same directory as the current window
if-shell "[[ `tmux -V` == *1.9 ]]" \
    'unbind c; bind c new-window -c "#{pane_current_path}"'

1 Response
Add your response

Thanks for the tip! By the way, you can make this more future-proof as the version number increases. I am implementing something like this to account for incompatible changes in 2.1.

if-shell "[[ `tmux -V | cut -d' ' -f2` -ge 1.9 ]]"
over 1 year ago ·