Make tmux.conf work on different versions

This commit is contained in:
ViViDboarder 2017-08-30 16:56:43 -07:00
parent e6019c238b
commit c3d7fc6652

View File

@ -12,16 +12,11 @@ set -g default-terminal "screen-256color"
unbind C-b unbind C-b
set -g prefix C-q set -g prefix C-q
# Enable mouse mode 2.1+
set-option -g mouse on
# easy splitting # easy splitting
bind | split-window -h -c "#{pane_current_path}" bind | split-window -h -c "#{pane_current_path}"
bind - split-window -c "#{pane_current_path}" bind - split-window -c "#{pane_current_path}"
bind _ split-window -c "#{pane_current_path}" bind _ split-window -c "#{pane_current_path}"
# act like vim
setw -g mode-keys vi
# move between panes # move between panes
bind C-q select-pane -t :.+ bind C-q select-pane -t :.+
bind h select-pane -L bind h select-pane -L
@ -35,18 +30,51 @@ bind -r K swap-pane -U
bind C-j command-prompt -p "Join pane from:" "join-pane -s '%%'" bind C-j command-prompt -p "Join pane from:" "join-pane -s '%%'"
bind C-s command-prompt -p "Send pane to:" "join-pane -t '%%'" bind C-s command-prompt -p "Send pane to:" "join-pane -t '%%'"
bind C-b break-pane bind C-b break-pane
# use vim style copy mode
unbind [ # based on https://stackoverflow.com/a/40902312/1046584
bind ` copy-mode run-shell "tmux setenv -g TMUX_VERSION $(tmux -V | cut -c 6-)"
bind -t vi-copy v begin-selection
bind -t vi-copy V rectangle-toggle # In version 2.1 "mouse" replaced the previous 4 mouse options
bind -t vi-copy y copy-selection if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.1" | bc)" = 1 ]' \
"set -g mouse on"
# UTF8 is autodetected in 2.2 onwards, but errors if explicitly set
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.2" | bc)" = 1 ]' \
"set -g utf8 on; set -g status-utf8 on; set -g mouse-utf8 on"
# New keybindings for vi-mode
# https://github.com/tmux/tmux/issues/754
setw -g mode-keys vi
if-shell -b '[ "$(echo "$TMUX_VERSION >= 2.4" | bc)" = 1 ]' \
'bind -T copy-mode-vi v send-keys -X begin-selection ; \
bind -T copy-mode-vi C-v send-keys -X rectangle-toggle ; \
bind -T copy-mode-vi y send-keys -X copy-selection ; \
bind -T copy-mode-vi H send-keys -X start-of-line ; \
bind -T copy-mode-vi L send-keys -X end-of-line ; \
bind -T choice-mode-vi h send-keys -X tree-collapse ; \
bind -T choice-mode-vi l send-keys -X tree-expand ; \
bind -T choice-mode-vi H send-keys -X tree-collapse-all ; \
bind -T choice-mode-vi L send-keys -X tree-expand-all ; \
bind -T copy-mode-emacs MouseDragEnd1Pane send-keys -X copy-pipe "pbcopy"; \
bind -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe "pbcopy"; ' \
'bind -t vi-copy v begin-selection; \
bind -t vi-copy C-v rectangle-toggle; \
bind -t vi-copy y copy-selection; \
bind -t vi-choice h tree-collapse; \
bind -t vi-choice l tree-expand; \
bind -t vi-choice H tree-collapse-all; \
bind -t vi-choice L tree-expand-all; \
bind -t emacs-copy MouseDragEnd1Pane copy-pipe "pbcopy"; \
bind -t vi-copy MouseDragEnd1Pane copy-pipe "pbcopy"; '
# bind p for put
unbind p unbind p
bind p paste-buffer bind p paste-buffer
# rebind previous-window # rebind previous-window
bind b previous-window bind b previous-window
# after copying to a tmux buffer, hit y again to copy to clipboard # after copying to a tmux buffer, hit y again to copy to clipboard
unbind y
if-shell 'test "$(uname -s)" = "Darwin"' 'bind y run "tmux show-buffer | pbcopy"' if-shell 'test "$(uname -s)" = "Darwin"' 'bind y run "tmux show-buffer | pbcopy"'
if-shell 'test "$(uname -s)" = "Linux"' 'bind y run "tmux show-buffer | xclip -sel clip -i"' if-shell 'test "$(uname -s)" = "Linux"' 'bind y run "tmux show-buffer | xclip -sel clip -i"'