literate-dotfiles/dotfiles/tmux.org
2019-01-31 09:41:03 +01:00

320 lines
9.5 KiB
Org Mode

#+TITLE: Tmux Configuration
#+PROPERTY: header-args :tangle ~/.tmux.conf
#+PROPERTY: header-args+ :comments both :mkdirp yes
* Line
** Define colors
#+BEGIN_SRC conf
t_red="#ef5253" # red
t_red_light="#eb9798" # light red
t_red_dark="#c22627" # dark red
t_blue="#579cde" # blue
t_orange="#de9a57"
t_green="#57de9a"
t_grey_dark="#393939" # dark grey
t_grey_light="#d9d9d9" # light grey
t_grey="#ababab" # grey
t_1l_bg="#ef5253" # red
t_1l_fg="#393939" # dark grey
t_2l_bg="#4e4e4e" # dark grey
t_2l_fg="#e8e8e8" # grey
t_3l_bg="#ababab" # grey
t_3l_fg="#393939" # dark grey
t_4l_bg="#579cde" # blue
t_4l_fg="#393939" # dark grey
t_1r_bg="#909090"
t_1r_fg="#393939"
t_2r_bg="#4e4e4e"
t_2r_fg="#a0a0a0"
t_3r_bg="#ababab" # grey
t_3r_fg="#393939" # dark grey
t_line_bg="#18262f" # dark blue
t_line_fg="#393939" # dark grey
t_win_bg="#18262f" # dark blue
t_win_fg="#d9d9d9" # light grey
t_win_bg_active="#ef5253" # red
t_win_fg_active="#393939" # dark grey
t_text_fg="#d9d9d9" # light grey
t_text_bg="#393939" # dark grey
#+END_SRC
** General config
#+BEGIN_SRC conf
set -g status "on" # Activate the status bar
set -g status-attr "none"
set -g status-interval "2" # update status every x seconds
set -g status-justify "centre" # center the list of windows
set -g status-bg "$t_line_bg"
set -g status-fg "$t_line_fg"
#+END_SRC
** Contents of right and light status
#+BEGIN_SRC conf
t_1_l="#S"
t_2_l="%H:%M"
# t_3_l="#($HOME/.config/.tmux/bin/tmux_left_status)"
t_4_l="C"
t_1_r="%d/%m"
# t_2_r="#($HOME/.config/.tmux/bin/tmux_right_status)"
# t_3_r=""
#+END_SRC
** Status left and right
#+BEGIN_SRC conf
set -g status-left "#[fg=$t_1l_fg,bg=$t_1l_bg] $t_1_l #[fg=$t_1l_bg,bg=$t_2l_bg]#[fg=$t_2l_fg,bg=$t_2l_bg] $t_2_l #{?client_prefix,#[fg=$t_2l_bg]#[bg=$t_4l_bg]#[fg=$t_4l_fg]#[bg=$t_4l_bg] $t_4_l #[fg=$t_4l_bg]#[bg=$t_line_bg],#[fg=$t_2l_bg]#[bg=$t_line_bg]}"
# set -g status-left "#[fg=$t_1l_fg,bg=$t_1l_bg] $t_1_l #[fg=$t_1l_bg,bg=$t_2l_bg]#[fg=$t_2l_fg,bg=$t_2l_bg] $t_2_l #[fg=$t_2l_bg,bg=$t_3l_bg]#[fg=$t_2l_bg, bg=$t_3l_bg]$t_3_l#{?client_prefix,#[fg=$t_3l_bg]#[bg=$t_4l_bg]#[fg=$t_4l_fg]#[bg=$t_4l_bg] $t_4_l #[fg=$t_4l_bg]#[bg=$t_line_bg],#[fg=$t_3l_bg]#[bg=$t_line_bg]}"
set -g status-left-length "90"
set -g status-left-attr "none"
set -g status-right "#[fg=$t_1r_bg]#[fg=$t_1r_fg,bg=$t_1r_bg] $t_1_r "
# set -g status-right "#[fg=$t_3r_bg,bg=$t_line_bg]#[fg=$t_3r_fg, bg=$t_3r_bg] $t_3_r #[fg=$t_2r_bg,bg=$t_3r_bg]#[fg=$t_2r_fg,bg=$t_2r_bg] $t_2_r #[fg=$t_1r_bg,bg=$t_2r_bg]#[fg=$t_1r_fg,bg=$t_1r_bg] $t_1_r "
set -g status-right-length "90"
set -g status-right-attr "none"
#+END_SRC
** Message and commands
#+BEGIN_SRC conf
set -g message-fg "$t_text_fg"
set -g message-bg "$t_text_bg"
set -g message-command-fg "$t_text_fg"
set -g message-command-bg "$t_text_bg"
#+END_SRC
** Panes
#+BEGIN_SRC conf
set -g pane-border-fg "$t_grey_dark" # Color of the separation between panes
set -g pane-active-border-fg "$t_red_light" # Color of the active separation
#+END_SRC
** Windows
#+BEGIN_SRC conf
setw -g window-status-fg "$t_red"
setw -g window-status-bg "$t_grey_light"
setw -g window-status-attr "none"
setw -g window-status-activity-fg "$t_grey_dark"
setw -g window-status-activity-bg "$t_red"
setw -g window-status-activity-attr "bold"
setw -g window-status-separator " "
setw -g window-status-format "#[fg=$t_win_fg,bg=$t_win_bg] #I | #W "
setw -g window-status-current-format "#[fg=$t_win_bg_active,bg=$t_line_bg]#[fg=$t_win_fg_active,bg=$t_win_bg_active] #I | #W #[fg=$t_win_bg_active,bg=$t_line_bg]"
#+END_SRC
* Bindings
#+BEGIN_SRC conf
# Set prefix to 'C-Space'
unbind C-b
set -g prefix C-Space
# Reload the config using 'C-Space + r'
bind r source-file ~/.tmux.conf \; display-message "Config reloaded..."
# Simulate 'C-l' to clear the terminal
bind C-l send-keys C-l \; clear-history
# Open new panes with the path of the current pane.
unbind c
bind c new-window -c '#{pane_current_path}'
# Vim-like key bindings for pane navigation (default uses cursor keys).
unbind h
bind h select-pane -L
unbind j
bind j select-pane -D
unbind k
bind k select-pane -U
unbind l # normally used for last-window
bind l select-pane -R
# Move Panes
unbind L
bind L swap-pane -D
unbind H
bind H swap-pane -U
# Resizing (mouse also works).
unbind Left
bind -r Left resize-pane -L 5
unbind Right
bind -r Right resize-pane -R 5
unbind Down
bind -r Down resize-pane -D 5
unbind Up
bind -r Up resize-pane -U 5
# Fast toggle (normally prefix-l).
bind ^space last-window
# Intuitive window-splitting keys.
bind / split-window -h -c '#{pane_current_path}' # normally prefix-%
bind - split-window -v -c '#{pane_current_path}' # normally prefix-"
# Swap windows
bind-key -r "<" swap-window -t -1
bind-key -r ">" swap-window -t +1
# Smart pane switching with awareness of Vim splits
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# Set 'C-Space + v' to enter copy-mode
unbind [
bind-key v copy-mode
# Set 'C-Space + C-v' to paste
unbind ]
bind-key C-v paste-buffer
# Setup 'v' to begin selection as in Vim and 'y' to yank
bind-key -T copy-mode-vi 'v' send -X begin-selection
bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key -T copy-mode-vi 'Escape' send -X cancel
bind-key -T copy-mode-vi 'C-v' send-keys -X rectangle-toggle
#+END_SRC
* Settings
#+BEGIN_SRC conf
# Activity monitoring
set -g visual-activity off
# Automatically renumber window numbers on closing a pane (tmux >= 1.7).
set -g renumber-windows on
# Mouse can be used to select panes, select windows (by clicking on the status bar), resize panes
set -g mouse on
set -g default-terminal "screen-256color"
set -ga terminal-overrides ',xterm-256color:Tc'
set -g history-limit 262144
# Start window and pane numbering at 1, (0 is too hard to reach)
set -g base-index 1
set -g pane-base-index 1
# Don't wait for an escape sequence after seeing C-a
set -s escape-time 0
# Dynamically update iTerm tab and window titles
set -g set-titles on
# Needed as on tmux 1.9 and up (defaults to off)
set -g focus-events on
# But don't change tmux's own window titles
set-option -g allow-rename off
# Don't wrap searches; it's super confusing given tmux's reverse-ordering of position info in copy mode
set -w -g wrap-search off
# Restore pre-2.1 behavior of scrolling with the scrollwheel in Vim, less, copy mode etc, otherwise entering copy mode if not already in it.
bind-key -T root WheelUpPane \
if-shell -Ft= '#{?pane_in_mode,1,#{mouse_any_flag}}' \
'send -Mt=' \
'if-shell -Ft= "#{alternate_on}" "send -t= Up" "copy-mode -et="'
bind-key -T root WheelDownPane \
if-shell -Ft = '#{?pane_in_mode,1,#{mouse_any_flag}}' \
'send -Mt=' \
'if-shell -Ft= "#{alternate_on}" "send -t= Down" "send -Mt="'
# Stay in copy mode on drag end, but otherwise exit for mouse up.
# Requires patch from https://github.com/tmux/tmux/issues/326
# unbind-key -t vi-copy MouseDragEnd1Pane
# bind-key -t vi-copy MouseUp1Pane cancel
bind-key -n MouseDrag1Status swap-window -t=
# bind-key -n MouseDown3Status new-window -a -t=
bind-key -n MouseDrag1Status swap-window -t=
# bind-key -n MouseDown3Status new-window -a -t=
# #T = standard window title (last command, see ~/.bash_profile)
# #h = short hostname
# #S = session name
# #W = tmux window name
set -g set-titles-string "#T : #h > #S > #W"
# Show bells in window titles
set -g window-status-bell-style fg=yellow,bold,underscore
#+END_SRC
* Plugins
** Install plugins
#+BEGIN_SRC conf
set -g @plugin 'tmux-plugins/tpm'
# set -g @plugin 'tmux-plugins/tmux-sessionist'
# set -g @plugin 'tmux-plugins/tmux-resurrect'
# set -g @plugin 'tmux-plugins/tmux-continuum'
# set -g @plugin 'tmux-plugins/tmux-battery'
set -g @plugin 'nhdaly/tmux-better-mouse-mode'
set -g @plugin 'seebi/tmux-colors-solarized'
#+END_SRC
** Configuration
#+BEGIN_SRC conf
# =============================================================
# tmux-resurrect
# =============================================================
# for vim
set -g @resurrect-strategy-vim 'session'
# for neovim
set -g @resurrect-strategy-nvim 'session'
# Restoring pane contents
set -g @resurrect-capture-pane-contents 'on'
run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux
# =============================================================
# =============================================================
# tmux-continuum
# =============================================================
set -g @continuum-boot 'on'
set -g @continuum-boot-options 'iterm,fullscreen'
set -g @continuum-save-interval '15'
run-shell ~/.tmux/plugins/tmux-continuum/continuum.tmux
# =============================================================
# =============================================================
# tmux-battery
# =============================================================
set -g @batt_charged_icon "="
set -g @batt_charging_icon "+"
set -g @batt_discharging_icon "-"
set -g @batt_attached_icon "o"
# =============================================================
#+END_SRC
* Colors
#+BEGIN_SRC conf
set -g @colors-solarized 'light'
#+END_SRC
* Initialize TMUX plugin manager
#+BEGIN_SRC conf
run '~/.tmux/plugins/tpm/tpm'
#+END_SRC