Where developers come to connect, share, build and be inspired.


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}"'

Add a comment