From c3ea9f7c359fadc4a83302e2f6a9c4d32c5e3aa4 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 30 Oct 2016 14:28:05 +0100 Subject: [PATCH] Add shell/tmux --- shell/tmux/.tmux.conf | 233 ++++++++++++++---- shell/tmux/install | 4 +- shell/tmux/scripts/conf-status.sh | 32 --- shell/tmux/scripts/conf.sh | 65 ----- .../{prefix_highlight.tmux => prefix-hl.tmux} | 0 5 files changed, 192 insertions(+), 142 deletions(-) delete mode 100755 shell/tmux/scripts/conf-status.sh delete mode 100755 shell/tmux/scripts/conf.sh rename shell/tmux/scripts/{prefix_highlight.tmux => prefix-hl.tmux} (100%) diff --git a/shell/tmux/.tmux.conf b/shell/tmux/.tmux.conf index 2f7874e5..b5f44b51 100644 --- a/shell/tmux/.tmux.conf +++ b/shell/tmux/.tmux.conf @@ -1,36 +1,78 @@ -## Behavior ############### +# -- GENERAL ----------------------------- -run-shell "~/.dotfiles/tmux/conf.sh" - -# Zero-based indexing is fine in programming languages, but not so much in -# a multiplexer when zero is on the other side of the keyboard. -set -g base-index 1 -set -g renumber-windows on -setw -g automatic-rename on - -# address vim mode switching delay (http://superuser.com/a/252717/65504) -set -g escape-time 0 - -# tmux messages are displayed for 4 seconds -set -g display-time 2000 - -# go zsh, go +set -g default-terminal screen-256color set -g default-shell $SHELL +set -s quiet on +set -s focus-events on +# increase scrollback buffer size +set -g history-limit 10000 -# set -g visual-activity off -setw -g monitor-activity on +# Rather than constraining window size to the maximum size of any client +# connected to the *session*, constrain window size to the maximum size of any +# client connected to *that window*. Much more reasonable. +setw -g aggressive-resize off + +# Tmux >= 2.1 +# enable mouse +setw -g mouse on +# fix mouse scrolling: enter copy mode on scroll-up, exits it when scrolled to bottom +bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'" + +# For tmux <2.2 +# UTF-8 +#set -q -g status-utf8 on +#setw -q -g utf8 on +# Enable mouse +#setw -g mode-mouse on +#set -g mouse-resize-pane on +#set -g mouse-select-pane on +#set -g mouse-select-window on + +# -- DISPLAY ----------------------------- + +set -g set-titles on +set -g set-titles-string "tmux [#H] #S:#W:#T" + +# Zero-based indexing is fine in programming languages, but not so much in a multiplexer +# when zero is on the other side of the keyboard. +set -g base-index 1 +setw -g pane-base-index 1 + +setw -g automatic-rename on # rename window to reflect current program +set -g renumber-windows on # renumber windows when a window is closed +# display tmux messages longer +set -g display-time 1500 +set -g display-panes-time 800 +# redraw status line less frequently +set -g status-interval 15 +# activity +set -g monitor-activity on +set -g visual-activity off # focus events enabled for terminals that support them set -g focus-events on -## Key bindings ########### +# -- KEYBINDS ---------------------------- + # set vi keys setw -g mode-keys vi -unbind [ -bind Escape copy-mode -## Pane management ##### +setw -g xterm-keys on +# address vim mode switching delay (http://superuser.com/a/252717/65504) +set -s escape-time 0 +set -sg repeat-time 600 + +# Custom prefix +set -g prefix C-c +bind C-c send-prefix +# GNU-Screen compatible prefix +# set -g prefix2 C-a +# bind C-a send-prefix -2 + +unbind C-b + +## Pane management # Saner splitting commands unbind % unbind '"' @@ -105,29 +147,134 @@ bind q kill-session bind Q kill-server -## Looks ######################## -set -g set-titles on -set -g set-titles-string "tmux [#H] #S:#W:#T" +# -- LIST CHOICE ------------------------- -set -s default-terminal "xterm-256color" +bind -t vi-choice h tree-collapse +bind -t vi-choice l tree-expand +run -b 'tmux bind -t vi-choice K start-of-list 2> /dev/null' +run -b 'tmux bind -t vi-choice J end-of-list 2> /dev/null' +bind -t vi-choice H tree-collapse-all +bind -t vi-choice L tree-expand-all +bind -t vi-choice Escape cancel -setw -g window-status-fg colour245 -setw -g window-status-bg colour237 -setw -g window-status-current-fg yellow -setw -g window-status-current-bg black -setw -g window-status-activity-attr bold,blink -setw -g window-status-activity-bg colour236 -setw -g window-status-activity-fg white -set -g status-interval 30 -set -g status-justify left -set -g status-right-length 100 -set -g status-left-length 80 -set -g status-left "#($DOTFILES/shell/tmux/scripts/conf-status.sh left) " -set -g status-right "#($DOTFILES/shell/tmux/scripts/conf-status.sh right) " +# -- EDIT MODE --------------------------- -set -g window-status-format " #I #W:#T " -set -g window-status-current-format " › #W:#T " +bind -ct vi-edit H start-of-line +bind -ct vi-edit L end-of-line +bind -ct vi-edit q cancel +bind -ct vi-edit Escape cancel -#### -run-shell "$DOTFILES/shell/tmux/scripts/prefix_highlight.tmux" + +# -- COPY MODE --------------------------- + +bind Enter copy-mode # enter copy mode +bind b list-buffers # list paster buffers +bind p paste-buffer # paste from the top pate buffer +bind P choose-buffer # choose which buffer to paste from + +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-copy Escape cancel +bind -t vi-copy H start-of-line +bind -t vi-copy L end-of-line + +# copy to Mac OSX pasteboard +if -b 'type -p reattach-to-user-namespace > /dev/null 2>&1' 'bind y run "tmux save-buffer - | reattach-to-user-namespace pbcopy"' + + +# -- THEME ------------------------------- + +# set -g status-justify left +# set -g status-right-length 100 +# set -g status-left-length 80 +# set -g status-left "#(~/.dotfiles/tmux/conf-status.sh left) " +# set -g status-right "#(~/.dotfiles/tmux/conf-status.sh right) " +# +# set -g window-status-format " #I #W:#T " +# set -g window-status-current-format " › #W:#T " + +## Status bar design +# status line +set -g status-bg colour4 +set -g status-fg colour12 +set -g status-interval 10 + +# messaging +set -g message-fg black +set -g message-bg yellow +set -g message-command-fg blue +set -g message-command-bg black + +# window mode +setw -g mode-bg colour6 +setw -g mode-fg colour0 + +# window status +setw -g window-status-current-bg colour0 +setw -g window-status-current-fg colour11 +setw -g window-status-current-attr dim +setw -g window-status-bg green +setw -g window-status-fg black +setw -g window-status-attr reverse + +# Info on left (I don't have a session display for now) +set -g status-left '' + +# loud or quiet? +set-option -g visual-activity off +set-option -g visual-bell off +set-option -g visual-silence off +set-window-option -g monitor-activity off +set-option -g bell-action none + +# The modes +setw -g clock-mode-colour colour135 +setw -g mode-attr bold +setw -g mode-fg colour196 +setw -g mode-bg colour238 + +# The panes +set -g pane-border-bg colour235 +set -g pane-border-fg colour238 +set -g pane-active-border-fg colour4 +set -g pane-active-border-bg colour235 + +# The statusbar +set -g status-position bottom +set -g status-fg colour137 +set -g status-bg colour8 +# set -g status-bg colour236 +set -g status-attr dim +set -g status-left '' +set -g status-right "#[fg=colour4]#(echo ${USER})#[fg=colour241]@#[fg=colour12]#(hostname) " +set -g status-right-length 40 +set -g status-left-length 30 + +# setw -g window-status-current-fg colour9 +setw -g window-status-current-fg colour81 +setw -g window-status-current-bg colour0 +setw -g window-status-current-attr bold +setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F ' + +setw -g window-status-fg colour242 +setw -g window-status-bg colour8 +setw -g window-status-attr none +setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour240]#W#[fg=colour240]#F ' + +setw -g window-status-bell-attr bold +setw -g window-status-bell-fg colour255 +setw -g window-status-bell-bg colour1 + +# The messages +set -g message-attr bold +set -g message-fg colour232 +set -g message-bg colour5 + + +## +run-shell "~/.dotfiles-new/shell/tmux/scripts/prefix-highlight.tmux" + +## User defined overrides +if '[ -f ~/.tmux.local.conf ]' 'source ~/.tmux.local.conf' diff --git a/shell/tmux/install b/shell/tmux/install index eee5ddc2..4447748e 100755 --- a/shell/tmux/install +++ b/shell/tmux/install @@ -6,8 +6,8 @@ case "$OSTYPE" in ;; linux*) if [ -f /etc/arch-release ]; then - sudo pacman -S tmux + sudo pacman --noconfirm -S tmux elif [ -f /etc/debian-version ]; then - sudo apt-get install tmux + sudo apt-get install -y tmux fi esac diff --git a/shell/tmux/scripts/conf-status.sh b/shell/tmux/scripts/conf-status.sh deleted file mode 100755 index 7459eb3e..00000000 --- a/shell/tmux/scripts/conf-status.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -color() { echo "#[$1=$2]"; } - -HOSTNAME=$(hostname) -RESET='#[default]' - -if [[ "$1" == "left" ]] -then - FG=white - [[ -n "$SSH_CONNECTION" ]] && FG=black - - STATUS=$(color fg $FG)' '$(tmux display-message -p '#S') -else - if [[ -z "$SSH_CONNECTION" ]]; then - DELIM=$(color fg yellow) - SYSINFO=$(color fg colour246) - IP=$(color fg white) - HOST=$(color bg yellow)$(color fg black) - else - DELIM=$(color fg black) - SYSINFO=$(color fg black) - IP=$(color fg black) - HOST=$(color bg black)$(color fg yellow) - fi - - STATUS="$DELIM<<$RESET " - STATUS+=$IP$(dig +short myip.opendns.com @208.67.222.222)" $RESET" - STATUS+=$HOST' '$HOSTNAME' ' -fi - -echo $STATUS diff --git a/shell/tmux/scripts/conf.sh b/shell/tmux/scripts/conf.sh deleted file mode 100755 index 1f01c7c1..00000000 --- a/shell/tmux/scripts/conf.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env sh - -TMUX_VERSION=$(tmux -V | awk '{ print $2 }') - -## Mouse ######### -if (( $(echo "$TMUX_VERSION >= 2.1" | bc) )); then - # setw -g mouse-utf8 on - tmux setw -g mouse on - # fix mouse scrolling: enter copy mode on scroll-up, exits it when scrolled to bottom - tmux bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'" -else - tmux setw -g mode-mouse on - tmux set -g mouse-resize-pane on - tmux set -g mouse-select-pane on - tmux set -g mouse-select-window on -fi - -# Fix clipboard access on osx -if [[ "$OSTYPE" == darwin* ]]; then - tmux unbind p - tmux bind p paste-buffer - tmux bind-key -t vi-copy 'v' begin-selection - tmux bind-key -t vi-copy 'y' copy-pipe "reattach-to-user-namespace pbcopy" - - tmux unbind -t vi-copy Enter - tmux bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy" - - # Rather than constraining window size to the maximum size of any client - # connected to the *session*, constrain window size to the maximum size of any - # client connected to *that window*. Much more reasonable. - tmux setw -g aggressive-resize off - - # increase scrollback buffer size - tmux set -g history-limit 10000 -else - tmux setw -g aggressive-resize on - - # increase scrollback buffer size - tmux set -g history-limit 5000 -fi - -# If in ssh, use default C-b prefix -if [[ -z "$SSH_CONNECTION" ]] -then - # Remap the key prefix - tmux set -g prefix ^c - # Restore sigterm C-c - tmux bind C-c send-prefix - - tmux set -g status-bg colour237 - tmux set -g status-fg white - - tmux set -g pane-active-border-fg yellow - tmux set -g pane-border-fg colour238 -else - # Remap the key prefix - tmux set -g prefix ^a - - tmux set -g status-bg yellow - tmux set -g status-fg black - - tmux set -g pane-active-border-fg blue - tmux set -g pane-border-fg colour237 -fi -tmux unbind C-b diff --git a/shell/tmux/scripts/prefix_highlight.tmux b/shell/tmux/scripts/prefix-hl.tmux similarity index 100% rename from shell/tmux/scripts/prefix_highlight.tmux rename to shell/tmux/scripts/prefix-hl.tmux