Skip to content

Instantly share code, notes, and snippets.

@vincenthsu
Last active November 29, 2023 08:30
Show Gist options
  • Save vincenthsu/6847a8f2a94e61735034e65d17ca0d66 to your computer and use it in GitHub Desktop.
Save vincenthsu/6847a8f2a94e61735034e65d17ca0d66 to your computer and use it in GitHub Desktop.
Tmux version verification (works with v1.8 to v2.1 )
# Overwrite configs depending on version
run-shell "bash ~/.tmux/verify_tmux_version.sh"
# User key bindings
# ^C - create new window
# c - create new window (default key)
# \ | % - vsplit
# - _ " - split
unbind ^C
bind ^C new-window;
bind \ split-window -h
bind | split-window -h
bind - split-window -v
bind _ split-window -v
# Mouse mode is off by default
# <prefix> M : to turn it off
# <prefix> m : to turn it on
unbind m
bind m set -g mode-mouse on \; set -g mouse-resize-pane on \; set -g mouse-select-pane on \; set -g mouse-select-window on \; display "Mouse ON"
bind M set -g mode-mouse off \; set -g mouse-resize-pane off \; set -g mouse-select-pane off \; set -g mouse-select-window off \; display "Mouse OFF"
# User key bindings
# ^C - create new window
# c - create new window (default key)
# \ | % - vsplit
# - _ " - split
unbind ^C
bind ^C new-window;
bind \ split-window -h
bind | split-window -h
bind - split-window -v
bind _ split-window -v
# Mouse mode is off by default
# <prefix> M : to turn it off
# <prefix> m : to turn it on
unbind m
bind m set -g mode-mouse on \; set -g mouse-resize-pane on \; set -g mouse-select-pane on \; set -g mouse-select-window on \; display "Mouse ON"
bind M set -g mode-mouse off \; set -g mouse-resize-pane off \; set -g mouse-select-pane off \; set -g mouse-select-window off \; display "Mouse OFF"
# pass on focus events to vim inside of tmux
set -g focus-events on
# User key bindings
# ^C - create new window
# c - create new window (default key)
# \ | % - vsplit
# - _ " - split
unbind c
bind c new-window -c "#{pane_current_path}"
bind ^C new-window -c "#{pane_current_path}"
bind \ split-window -h -c "#{pane_current_path}"
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind _ split-window -v -c "#{pane_current_path}"
# Mouse mode is off by default
# <prefix> M : to turn it off
# <prefix> m : to turn it on
set -g mouse-utf8 on
unbind m
bind m set -g mouse on \; display "Mouse ON"
bind M set -g mouse off \; display "Mouse OFF"
# pass on focus events to vim inside of tmux
set -g focus-events on
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
# Restore tmux environment
set -g @plugin 'tmux-plugins/tmux-resurrect'
# Automatic restore
set -g @plugin 'tmux-plugins/tmux-continuum'
# Plugin settings
set -g @continuum-restore 'on'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
#!/bin/bash
verify_tmux_version () {
tmux_home=~/.tmux
tmux_version="$(tmux -V | cut -c 6-)"
if [[ $(echo "$tmux_version >= 2.1" | bc) -eq 1 ]] ; then
tmux source-file "$tmux_home/tmux_2.1_up.conf"
exit
elif [[ $(echo "$tmux_version >= 1.9" | bc) -eq 1 ]] ; then
tmux source-file "$tmux_home/tmux_1.9_to_2.1.conf"
exit
else
tmux source-file "$tmux_home/tmux_1.9_down.conf"
exit
fi
}
verify_tmux_version
@HaleTom
Copy link

HaleTom commented Nov 30, 2016

I prefer to manage updates in one place rather than two... any reason you don't put the common lines in file of their own?

@marcuslannister
Copy link

marcuslannister commented Nov 29, 2023

tmux_version="$(tmux -V | cut -c 6-)"

Using cut may result in issues in versions that have alphabets such as ‘3.3a’.
Running the script directly in the terminal will display an error message: ‘Parse error: bad expression’.

Therefore I replaced cut with sed (copy from https://stackoverflow.com/a/40902312).

tmux_version="$(tmux -V | sed -En "s/^tmux[^0-9]*([.0-9]+).*/\1/p")"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment