Skip to content

Commit

Permalink
feat: reduce duplication in tmux conf files
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nhunt committed Jul 21, 2020
1 parent 406d3ab commit 654f141
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 236 deletions.
114 changes: 0 additions & 114 deletions dotfiles/.macos.tmux.conf
Original file line number Diff line number Diff line change
@@ -1,48 +1,6 @@
# Use <ctrl-a> for prefix rather than <ctrl-b>. The '-g' option sets it globally
# Unbinding commands isn't neccesary
unbind C-b
set -g prefix C-a
bind C-a send-prefix

set -g allow-rename off
# Use 256 colors
set -g default-terminal "tmux-256color"

# Use zsh as default shell
set -g default-shell $SHELL

# Prevent Vim mode switching delay (https://superuser.com/a/252717/65504)
set -sg escape-time 0

# Increase scrollback history above the default of 2000
set -g history-limit 50000

# Limit size of window in session by smallest client only when both viewing the same window. By defaul all windows are limited
setw -g aggressive-resize on

# Style status line
set -g status-style fg=green,bold,bg=black
set -g status-left-length 20
# set -g status-right 'Continuum status: #{continuum_status}'
setw -g window-status-style fg=blue,bold,bg=default
setw -g window-status-current-style fg=white,bold,bg=red

# Style message line
set -g message-style fg=white,bold,bg=black

# Style active pane
setw -g pane-active-border-style fg=green,bg=default

# Enable activity alerts and set style
set -g visual-activity on
setw -g monitor-activity on
setw -g window-status-activity-style bg=white

# Copy-paste integration
set-option -g default-command "reattach-to-user-namespace -l zsh"

# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"

# Update default binding of `Enter` to also use copy-pipe
Expand All @@ -52,80 +10,8 @@ bind-key -T copy-mode-vi Enter send-keys -X copy-pipe "reattach-to-user-namespac
# Bind ']' to use pbpaste
bind ] run "reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer"

# Make window and pane index start with 1, by default it would be 0 which is a bigger stretch on the keyboard
set -g base-index 1
setw -g pane-base-index 1 # setw is used for setting options on the window, the long form is 'set-window-option'

# Reload config file. '\;' separates commands
bind r source-file ~/.tmux.conf \; display "Config Reloaded!"

# Quickly open a new window. The default is 'prefix c'
bind N new-window

# Split window and fix path for tmux 1.9
# Split window vertically, default is 'prefix %'
bind | split-window -h -c "#{pane_current_path}"
# Split window horizontally, default is 'prefix "'
bind - split-window -v -c "#{pane_current_path}"

# Synchronize all panes in a window, toggles
bind C-a setw synchronize-panes

# Cycle through windows via ctrl-h and ctrl-l
bind -r C-h select-window -T -t :-
bind -r C-l select-window -T -t :+

# Resize panes using H,J,K,L. Using -r option to make the command repeatable
bind -r H resize-pane -L 10
bind -r J resize-pane -D 10
bind -r K resize-pane -U 10
bind -r L resize-pane -R 10

# Enable mouse support. Use sparingly. Most useful to select text and copy into the clipboard.
set -g mouse on

# Use Vim keybindings in Copy mode
setw -g mode-keys vi

# More settings to make copy-mode more Vim-like
unbind [ # Prefix [ is the default for Copy mode
bind Escape copy-mode
unbind p # Prefix p is previous window by default
bind p paste-buffer
bind -T copy-mode-vi 'v' send-keys -X begin-selection
bind -T copy-mode-vi 'y' send-keys -X copy-selection


bind-key -T root PPage if-shell -F "#{alternate_on}" "send-keys PPage" "copy-mode -e; send-keys PPage"
bind-key -T copy-mode-vi PPage send-keys -X page-up
bind-key -T copy-mode-vi NPage send-keys -X page-down

bind -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "select-pane -t =; send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "select-pane -t =; send-keys -M" "select-pane -t =; send-keys -M"
bind-key -T copy-mode-vi WheelUpPane send-keys -X halfpage-up
bind-key -T copy-mode-vi WheelDownPane send-keys -X halfpage-down

#Buffers to/from Mac clipboard, yay tmux book from pragprog
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer"

# Smart pane switching with awareness of Vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
# bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"

# Tmux PLugin Manager config
set -g @plugin 'tmux-plugins/tpm' # https://github.com/tmux-plugins/tpm
set -g @plugin 'tmux-plugins/tmux-continuum' # https://github.com/tmux-plugins/tmux-continuum
set -g @plugin 'tmux-plugins/tmux-resurrect' # https://github.com/tmux-plugins/tmux-resurrect
# set -g @plugin 'tmux-plugins/tmux-yank' # https://github.com/tmux-plugins/tmux-yank

# Continually save tmux environment (using tmux-continuum)
set -g @continuum-restore 'on'
# Restore vim sessions
set -g @resurrect-strategy-vim 'session'

# Initialize TPM (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
115 changes: 115 additions & 0 deletions dotfiles/.tmux.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Use <ctrl-a> for prefix rather than <ctrl-b>. The '-g' option sets it globally
# Unbinding commands isn't neccesary
unbind C-b
set -g prefix C-a
bind C-a send-prefix

set -g allow-rename off
# Use 256 colors
set -g default-terminal "tmux-256color"

# Use zsh as default shell
set -g default-shell $SHELL

# Prevent Vim mode switching delay (https://superuser.com/a/252717/65504)
set -sg escape-time 0

# Increase scrollback history above the default of 2000
set -g history-limit 50000

# Limit size of window in session by smallest client only when both viewing the same window. By defaul all windows are limited
setw -g aggressive-resize on

# Style status line
set -g status-style fg=green,bold,bg=black
set -g status-left-length 20
# set -g status-right 'Continuum status: #{continuum_status}'
setw -g window-status-style fg=blue,bold,bg=default
setw -g window-status-current-style fg=white,bold,bg=red

# Style message line
set -g message-style fg=white,bold,bg=black

# Style active pane
setw -g pane-active-border-style fg=green,bg=default

# Enable activity alerts and set style
set -g visual-activity on
setw -g monitor-activity on
setw -g window-status-activity-style bg=white

# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send-keys -X begin-selection

# Make window and pane index start with 1, by default it would be 0 which is a bigger stretch on the keyboard
set -g base-index 1
setw -g pane-base-index 1 # setw is used for setting options on the window, the long form is 'set-window-option'

# Reload config file. '\;' separates commands
bind r source-file ~/.tmux.conf \; display "Config Reloaded!"

# Quickly open a new window. The default is 'prefix c'
bind N new-window

# Split window and fix path for tmux 1.9
# Split window vertically, default is 'prefix %'
bind | split-window -h -c "#{pane_current_path}"
# Split window horizontally, default is 'prefix "'
bind - split-window -v -c "#{pane_current_path}"

# Synchronize all panes in a window, toggles
bind C-a setw synchronize-panes

# Cycle through windows via ctrl-h and ctrl-l
bind -r C-h select-window -T -t :-
bind -r C-l select-window -T -t :+

# Resize panes using H,J,K,L. Using -r option to make the command repeatable
bind -r H resize-pane -L 10
bind -r J resize-pane -D 10
bind -r K resize-pane -U 10
bind -r L resize-pane -R 10

# Enable mouse support. Use sparingly. Most useful to select text and copy into the clipboard.
set -g mouse on

# Use Vim keybindings in Copy mode
setw -g mode-keys vi

# More settings to make copy-mode more Vim-like
unbind [ # Prefix [ is the default for Copy mode
bind Escape copy-mode
unbind p # Prefix p is previous window by default
bind p paste-buffer

bind-key -T root PPage if-shell -F "#{alternate_on}" "send-keys PPage" "copy-mode -e; send-keys PPage"
bind-key -T copy-mode-vi PPage send-keys -X page-up
bind-key -T copy-mode-vi NPage send-keys -X page-down

bind -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "select-pane -t =; send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "select-pane -t =; send-keys -M" "select-pane -t =; send-keys -M"
bind-key -T copy-mode-vi WheelUpPane send-keys -X halfpage-up
bind-key -T copy-mode-vi WheelDownPane send-keys -X halfpage-down

# Smart pane switching with awareness of Vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"

# Tmux PLugin Manager config
set -g @plugin 'tmux-plugins/tpm' # https://github.com/tmux-plugins/tpm
set -g @plugin 'tmux-plugins/tmux-continuum' # https://github.com/tmux-plugins/tmux-continuum
set -g @plugin 'tmux-plugins/tmux-resurrect' # https://github.com/tmux-plugins/tmux-resurrect
# set -g @plugin 'tmux-plugins/tmux-yank' # https://github.com/tmux-plugins/tmux-yank

# Continually save tmux environment (using tmux-continuum)
set -g @continuum-restore 'on'
# Restore vim sessions
set -g @resurrect-strategy-vim 'session'

# Include WSL specific stuff
if-shell "test $OSTYPE = linux-gnu && test -n $WSL_DISTRO_NAME" 'source-file ~/.wsl.tmux.conf' 'source-file ~/.macos.tmux.conf'

# Initialize TPM (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
117 changes: 0 additions & 117 deletions dotfiles/.wsl.tmux.conf
Original file line number Diff line number Diff line change
@@ -1,120 +1,3 @@
# Use <ctrl-a> for prefix rather than <ctrl-b>. The '-g' option sets it globally
# Unbinding commands isn't neccesary
unbind C-b
set -g prefix C-a
bind C-a send-prefix

set -g allow-rename off
# Use 256 colors
set -g default-terminal "tmux-256color"

# Use zsh as default shell
set -g default-shell $SHELL

# Prevent Vim mode switching delay (https://superuser.com/a/252717/65504)
set -sg escape-time 0

# Increase scrollback history above the default of 2000
set -g history-limit 50000

# Limit size of window in session by smallest client only when both viewing the same window. By defaul all windows are limited
setw -g aggressive-resize on

# Style status line
set -g status-style fg=green,bold,bg=black
set -g status-left-length 20
# set -g status-right 'Continuum status: #{continuum_status}'
setw -g window-status-style fg=blue,bold,bg=default
setw -g window-status-current-style fg=white,bold,bg=red

# Style message line
set -g message-style fg=white,bold,bg=black

# Style active pane
setw -g pane-active-border-style fg=green,bg=default

# Enable activity alerts and set style
set -g visual-activity on
setw -g monitor-activity on
setw -g window-status-activity-style bg=white

# Copy-paste integration for WSLENV
if-shell -b 'test -n "$WSLENV"' 'bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel clip.exe'
if-shell -b 'test -n "$WSLENV"' 'bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel clip.exe'
# Setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi v send-keys -X begin-selection

# Make window and pane index start with 1, by default it would be 0 which is a bigger stretch on the keyboard
set -g base-index 1
setw -g pane-base-index 1 # setw is used for setting options on the window, the long form is 'set-window-option'

# Reload config file. '\;' separates commands
bind r source-file ~/.tmux.conf \; display "Config Reloaded!"

# Quickly open a new window. The default is 'prefix c'
bind N new-window

# Split window and fix path for tmux 1.9
# Split window vertically, default is 'prefix %'
bind | split-window -h -c "#{pane_current_path}"
# Split window horizontally, default is 'prefix "'
bind - split-window -v -c "#{pane_current_path}"

# Synchronize all panes in a window, toggles
bind C-a setw synchronize-panes

# Cycle through windows via ctrl-h and ctrl-l
bind -r C-h select-window -T -t :-
bind -r C-l select-window -T -t :+

# Resize panes using H,J,K,L. Using -r option to make the command repeatable
bind -r H resize-pane -L 10
bind -r J resize-pane -D 10
bind -r K resize-pane -U 10
bind -r L resize-pane -R 10

# Enable mouse support. Use sparingly. Most useful to select text and copy into the clipboard.
set -g mouse on

# Use Vim keybindings in Copy mode
setw -g mode-keys vi

# More settings to make copy-mode more Vim-like
unbind [ # Prefix [ is the default for Copy mode
bind Escape copy-mode
unbind p # Prefix p is previous window by default
bind p paste-buffer

bind-key -T root PPage if-shell -F "#{alternate_on}" "send-keys PPage" "copy-mode -e; send-keys PPage"
bind-key -T copy-mode-vi PPage send-keys -X page-up
bind-key -T copy-mode-vi NPage send-keys -X page-down

bind -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "select-pane -t =; send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M"
bind -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "select-pane -t =; send-keys -M" "select-pane -t =; send-keys -M"
bind-key -T copy-mode-vi WheelUpPane send-keys -X halfpage-up
bind-key -T copy-mode-vi WheelDownPane send-keys -X halfpage-down

#Buffers to/from Mac clipboard, yay tmux book from pragprog
# bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
# bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer"

# Smart pane switching with awareness of Vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
# bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"

# Tmux PLugin Manager config
set -g @plugin 'tmux-plugins/tpm' # https://github.com/tmux-plugins/tpm
set -g @plugin 'tmux-plugins/tmux-continuum' # https://github.com/tmux-plugins/tmux-continuum
set -g @plugin 'tmux-plugins/tmux-resurrect' # https://github.com/tmux-plugins/tmux-resurrect
# set -g @plugin 'tmux-plugins/tmux-yank' # https://github.com/tmux-plugins/tmux-yank

# Continually save tmux environment (using tmux-continuum)
set -g @continuum-restore 'on'
# Restore vim sessions
set -g @resurrect-strategy-vim 'session'

# Initialize TPM (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
8 changes: 3 additions & 5 deletions scripts/install-dotfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ ln -nfsv "$DOTFILES_DIR/.functions" ~
ln -nfsv "$DOTFILES_DIR/.prompt" ~
ln -nfsv "$DOTFILES_DIR/.p10k.zsh" ~
ln -nfsv "$DOTFILES_DIR/.shared-shell-setup" ~
ln -nfsv "$DOTFILES_DIR/.tmux.conf" ~
ln -nfsv "$DOTFILES_DIR/.macos.tmux.conf" ~
ln -nfsv "$DOTFILES_DIR/.wsl.tmux.conf" ~
ln -nfsv "$DOTFILES_DIR/.vimrc" ~
ln -nfsv "$DOTFILES_DIR/.zshrc" ~
ln -nfsv "$GIT_DIR/.git-prompt.sh" ~
ln -nfsv "$GIT_DIR/.git-completion.bash" ~
ln -nfsv "$GIT_DIR/.gitconfig" ~
ln -nfsv "$GIT_DIR/.gitignore" ~

if [[ "$OSTYPE" == "darwin"* ]]; then
ln -nfsv "$DOTFILES_DIR/.macos.tmux.conf" ~/.tmux.conf
fi

if [[ -n "$WSL_DISTRO_NAME" && "$OSTYPE" == "linux-gnu" ]]; then
ln -nfsv "$DOTFILES_DIR/.wsl.tmux.conf" ~/.tmux.conf
ln -nfsv "$DOTFILES_DIR/.zprofile" ~
fi

Expand Down

0 comments on commit 654f141

Please sign in to comment.