298 lines
10 KiB
Bash
298 lines
10 KiB
Bash
set -g default-terminal "tmux-256color"
|
|
set -g mouse on
|
|
set -g mode-keys vi
|
|
set -g extended-keys always
|
|
|
|
set -g prompt-history-limit 999999
|
|
set -g history-file "$XDG_DATA_HOME/tmux/tmux_history"
|
|
run-shell 'mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/tmux"'
|
|
|
|
# Better clipboard on mousedrag (https://unix.stackexchange.com/a/349020)
|
|
# Disable xterm escape sequences for setting clipboard
|
|
set -s set-clipboard off
|
|
|
|
set -g copy-command 'xclip -selection clipboard'
|
|
|
|
# Copy selection into primary selection (without aborting)
|
|
bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-no-clear "xclip -se p"
|
|
|
|
# https://github.com/neovim/neovim/wiki/FAQ#cursor-shape-doesnt-change-in-tmux
|
|
set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
|
|
|
|
# Scroll up 5 lines when entering copy-mode through the mouse wheel, send 5x`up`
|
|
# when the current pane is in alternate mode and discard the `-e` flag passed to
|
|
# copy-mode from the default binding (See below)
|
|
# TODO: Do not modify selection when scolling with the wheel
|
|
bind -n WheelUpPane \
|
|
if -F "#{||:#{pane_in_mode},#{mouse_any_flag}}" {
|
|
send -M
|
|
} {
|
|
if -F "#{alternate_on}" {
|
|
send -N5 up
|
|
} {
|
|
copy-mode; send -XN5 scroll-up
|
|
}
|
|
}
|
|
# Scroll without selecting the pane
|
|
bind -T copy-mode-vi WheelUpPane send -XN5 scroll-up
|
|
# Exit copy-mode when at the bottom. This practically mimics `copy-mode -e` but
|
|
# only scrolling with the wheel (`-e` annoys me when scrolling down with `C-d`).
|
|
bind -T copy-mode-vi WheelDownPane \
|
|
if -F "#{==:0,#{scroll_position}}" {send -X cancel} {send -XN5 scroll-down}
|
|
|
|
# Set C-a as new prefix
|
|
unbind C-b
|
|
set -g prefix C-a
|
|
bind C-a send-prefix
|
|
|
|
# Split panes with > and <
|
|
unbind %
|
|
bind < splitw -v -c "#{pane_current_path}"
|
|
unbind '"'
|
|
bind > splitw -h -c "#{pane_current_path}"
|
|
|
|
# Create new window with CWD as PWD and place it after the current one
|
|
bind c neww -a -c "#{pane_current_path}" -t #{active_window_index}
|
|
|
|
# Resource config
|
|
bind R source-file "$XDG_CONFIG_HOME/tmux/tmux.conf" \; \
|
|
display "Sourced $XDG_CONFIG_HOME/tmux/tmux.conf"
|
|
|
|
# Fullscreen pane (toggle)
|
|
bind F resizep -Z
|
|
|
|
# Automatically renumber windows when closing one
|
|
set -g renumber-windows on
|
|
# Number windows with 1-based indices
|
|
set -g base-index 1
|
|
|
|
# Enter copy-mode and scroll one page up directly with PageUp without the need
|
|
# of the prefix. (Exists already per default with prefix)
|
|
bind -n PPage copy-mode -u
|
|
|
|
# Repeatable window-navigation bindings
|
|
bind -r n next
|
|
bind -r C-n next
|
|
bind -r p prev
|
|
bind -r C-p prev
|
|
|
|
# Swap window with previous/next one
|
|
bind -r N swap-window -d -t :+1
|
|
bind -r P swap-window -d -t :-1
|
|
|
|
# Reorder windows by dragging on status line. This uses a loop and swap-window
|
|
# as move-window needs the target index to be free.
|
|
# NOTE: This breaks the stack and last-used window.
|
|
bind -n MouseDragEnd1Status {
|
|
# TODO: Can we somehow get the idx of {mouse} without selecting it?
|
|
set -F @source_idx "#{window_index}"
|
|
select-window -t=
|
|
set -F @target_idx "#{window_index}"
|
|
if -F "#{!=:#{@source_idx},#{window_index}}" { select-window -t! }
|
|
|
|
# Get the right direction to not mess up the order when wrapping around
|
|
tmux_move_direction="#{?#{e|<:#{@target_idx},#{@source_idx}},:-1,:+1}"
|
|
tmux_move_target_idx="#{@target_idx}"
|
|
|
|
run-shell "\
|
|
while [ $tmux_move_target_idx -ne $(tmux display -a | grep -Po '(?<=^window_index=)[0-9]*') ]; do \
|
|
tmux swap-window -d -t $tmux_move_direction; \
|
|
done"
|
|
|
|
setenv -u tmux_move_direction
|
|
setenv -u tmux_move_target_idx
|
|
}
|
|
|
|
# TODO: Move to beginning or end like in MouseDragEnd1Status
|
|
# bind -n MouseDragEnd1StatusDefault display-message "#{e|>|f|0:#{mouse_x},#{e|/|f:213,2}}"
|
|
|
|
# Repeatable window-movement bindings
|
|
bind -r \{ swap-pane -U
|
|
bind -r \} swap-pane -D
|
|
|
|
# Select windows with Alt-[0-9], select last window if target is current
|
|
bind -n M-1 select-window -T -t 1
|
|
bind -n M-2 select-window -T -t 2
|
|
bind -n M-3 select-window -T -t 3
|
|
bind -n M-4 select-window -T -t 4
|
|
bind -n M-5 select-window -T -t 5
|
|
bind -n M-6 select-window -T -t 6
|
|
bind -n M-7 select-window -T -t 7
|
|
bind -n M-8 select-window -T -t 8
|
|
bind -n M-9 select-window -T -t 9
|
|
bind -n M-0 select-window -T -t 10
|
|
|
|
# Vim-bindings
|
|
|
|
# Enter copy-mode with Escape
|
|
bind Escape copy-mode
|
|
|
|
# Start selection (i.e. visual mode) with `v`, and rectangle selection (i.e.
|
|
# visual block mode) with `C-v`
|
|
# TODO: mimic vims behaviour for visual mode cycling and toggling
|
|
unbind -T copy-mode-vi v
|
|
bind -T copy-mode-vi v send -X begin-selection
|
|
unbind -T copy-mode-vi C-v
|
|
bind -T copy-mode-vi C-v {
|
|
if -F "#{selection_active}" {} { send -X begin-selection }
|
|
send -X rectangle-toggle
|
|
}
|
|
|
|
# Yank into system clipboard
|
|
# TODO: This breaks on repeatable movements (e.g. `y2e`)
|
|
bind -T copy-mode-vi y \
|
|
if -F "#{selection_present}" {
|
|
send -X copy-pipe
|
|
} {
|
|
command-prompt -k -p (operator-pending) {
|
|
send -X begin-selection
|
|
send "%%"
|
|
send -X copy-pipe
|
|
}
|
|
}
|
|
bind -T copy-mode-vi Y \
|
|
if -F "#{selection_present}" { send -X copy-pipe-line } { send -X copy-pipe-end-of-line }
|
|
|
|
# Clear selection or cancel copy-mode when nothing is selected
|
|
bind -T copy-mode-vi Escape \
|
|
if -F "#{selection_present}" { send -X clear-selection } { send -X cancel }
|
|
|
|
# Use insert-mode-like bindings to cancel copy-mode
|
|
bind -T copy-mode-vi A send -X cancel
|
|
bind -T copy-mode-vi I send -X cancel
|
|
bind -T copy-mode-vi a send -X cancel
|
|
bind -T copy-mode-vi i send -X cancel
|
|
|
|
# Simulate vim's C-e & C-y (Keep cursor position while scrolling). As tmux
|
|
# cannot scroll past the first and last history line, both bindings stop
|
|
# scrolling when the respective line is visible. This mimics the behaviour of
|
|
# vim's C-y at the top of the file.
|
|
bind -T copy-mode-vi C-e \
|
|
if -F "#{e|>:#{scroll_position},0}" {
|
|
send-keys -X scroll-down
|
|
if -F "#{e|>:#{copy_cursor_y},#{scroll_region_upper}}" {
|
|
send-keys -X cursor-up
|
|
}
|
|
}
|
|
|
|
bind -T copy-mode-vi C-y \
|
|
if -F "#{e|<:#{scroll_position},#{history_size}}" {
|
|
send-keys -X scroll-up
|
|
if -F "#{e|<:#{copy_cursor_y},#{scroll_region_lower}}" {
|
|
send-keys -X cursor-down
|
|
}
|
|
}
|
|
|
|
# Navigate panes with <prefix>-[hjkl]
|
|
# NOTE: C-[hjkl] (w/o prefix) moves through vim splits and tmux panes
|
|
# See vim-tmux-navigator
|
|
unbind l
|
|
bind -r h selectp -L
|
|
bind -r j selectp -D
|
|
bind -r k selectp -U
|
|
bind -r l selectp -R
|
|
|
|
# Resize mode similar to my i3 config
|
|
bind -T resize h resizep -L \; switchc -T resize
|
|
bind -T resize j resizep -D \; switchc -T resize
|
|
bind -T resize k resizep -U \; switchc -T resize
|
|
bind -T resize l resizep -R \; switchc -T resize
|
|
bind -T resize 1 selectl even-horizontal \; switchc -T resize
|
|
bind -T resize 2 selectl even-vertical \; switchc -T resize
|
|
bind -T resize 3 selectl main-horizontal \; switchc -T resize
|
|
bind -T resize 4 selectl main-vertical \; switchc -T resize
|
|
bind -T resize 5 selectl tiled \; switchc -T resize
|
|
bind r switchc -T resize
|
|
|
|
# Make it possible to send keys that are bound in the root key table. (C-h for
|
|
# example is sometimes needed as backspace sequence)
|
|
# TODO: Make repeatable without C-v
|
|
bind -r C-v command-prompt -k -p (selfinsert) { send "%%" }
|
|
|
|
# Synchronize the panes in the current window with `<prefix>S`
|
|
bind S set -w synchronize-panes
|
|
|
|
# Change installation location of plugins
|
|
setenv -g TMUX_PLUGIN_MANAGER_PATH "$XDG_CONFIG_HOME/tmux/plugins/"
|
|
|
|
## Plugins
|
|
set -g @plugin 'tmux-plugins/tmux-continuum'
|
|
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
|
|
set -g @plugin 'tmux-plugins/tmux-resurrect'
|
|
set -g @plugin 'tmux-plugins/tmux-sensible'
|
|
set -g @plugin 'tmux-plugins/tpm'
|
|
set -g @plugin 'vim-tmux-navigator'
|
|
|
|
# Capture pane content
|
|
set -g @resurrect-capture-pane-contents 'on'
|
|
# Change keybindings
|
|
set -g @resurrect-save 'C-s'
|
|
set -g @resurrect-restore 'C-r'
|
|
# Save session every 5 min
|
|
set -g @continuum-save-interval '5'
|
|
# Last saved environment is automatically restored when tmux is started.
|
|
set -g @continuum-restore 'on'
|
|
# Restore {,neo}vim sessions with the help of vim-obsession
|
|
# https://github.com/tpope/vim-obsession
|
|
set -g @resurrect-strategy-vim 'session'
|
|
set -g @resurrect-strategy-nvim 'session'
|
|
# Save sessions before detaching
|
|
unbind d
|
|
bind d {
|
|
run -b "$XDG_CONFIG_HOME/tmux/plugins/tmux-resurrect/scripts/save.sh";
|
|
detach
|
|
}
|
|
|
|
## Theming
|
|
set -g @accent_color '#fce94f' # brightyellow
|
|
set -g @ui_color '#757773' # brightblack
|
|
set -g @sync_color '#ef2929' # brightred
|
|
set -g @text_fg '#5e6466' # black
|
|
|
|
set -g status-style bg=default,fg='#d3d7cf' # white
|
|
set -g message-command-style 'bg=default,fg=#{@accent_color}'
|
|
set -g message-style 'bg=#{@accent_color},fg=#{@text_fg}'
|
|
set -g mode-style 'bg=#{@accent_color},fg=#{@text_fg}'
|
|
|
|
# Visually display when a pane is in copy-mode or 'synchronize-panes' is on.
|
|
# Use the pane-borders for tmux >= 3.2 and the "prefix_highlight" plugin
|
|
# otherwise.
|
|
#
|
|
# NOTE: `<` does string comparison with `strcmp()`. This means that the
|
|
# condition will break from a double digit major version (e.g. `10.0`) on.
|
|
# TODO: Use #{e|<|f:, but cut off trailing non-numbers and convert the result
|
|
# (i.e. 1.00 or 0.00) back into an int.
|
|
if -F "#{<:#{version},3.2}" {
|
|
set -g pane-border-style 'bg=default,fg=#{@ui_color}'
|
|
set -g pane-active-border-style 'bg=default,fg=#{@accent_color}'
|
|
|
|
set -g @prefix_highlight_show_copy_mode 'on'
|
|
set -g @prefix_highlight_show_sync_mode 'on'
|
|
set -g @prefix_highlight_copy_mode_attr 'fg=#{@text_fg},bg=#{@accent_color}'
|
|
set -g @prefix_highlight_sync_mode_attr 'fg=#{@text_fg},bg=#{@sync_color}'
|
|
} {
|
|
# From 3.2 on, we can use formats in styles, so that all indicators can be
|
|
# done by the borders.
|
|
set -g pane-border-style "#{?synchronize-panes,fg=#{@sync_color},fg=#{@ui_color}}"
|
|
set -g pane-active-border-style "#{?pane_in_mode,bg=#{@accent_color}#,fg=#{@ui_color},#{?synchronize-panes,fg=#{@sync_color},fg=#{@accent_color}}}"
|
|
}
|
|
|
|
set -g @prefix_highlight_fg '#{@accent_color}'
|
|
set -g @prefix_highlight_bg 'default'
|
|
set -g status-right "#{prefix_highlight}"
|
|
set -g status-left "#{prefix_highlight}"
|
|
|
|
set -g status-justify centre
|
|
|
|
# Display window_index and window_name as status and underline it when the
|
|
# active pane is zoomed.
|
|
%hidden window_status='#{?window_zoomed_flag,#[underscore],}#I #W'
|
|
set -g window-status-current-format \
|
|
"#[fg=#{@accent_color} bold]"$window_status
|
|
set -g window-status-format \
|
|
"#[fg=#{@ui_color}]"$window_status
|
|
setenv -ghu window_status
|
|
|
|
# Initialize TMUX plugin manager. Keep this line at the very bottom.
|
|
run -b "$XDG_CONFIG_HOME/tmux/plugins/tpm/tpm"
|