# vim:ts=4:sts=4:sw=4:et # # Author: Hari Sekhon # Date: 2015-10-08 12:10:02 +0100 (Thu, 08 Oct 2015) # # https://github.com/harisekhon/bash-tools # # License: see accompanying Hari Sekhon LICENSE file # # If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish # # https://www.linkedin.com/in/harisekhon # # Run 'make tmux' to install TPM before using this config or see git clone at bottom # ============================================================================ # # T M U X C o n f i g u r a t i o n # ============================================================================ # # Ctrl-b r - reloads .tmux.conf # remember tmux reuses backend server process which doesn't go down unless you do 'tmux kill-server' (killing tmux server process is an easy reset if you don't want to undo options you've been messing with interactively) bind r source-file ~/.tmux.conf \; display ".tmux.conf reloaded" # Ctrl-b b - reloads .bashrc - .bash.d/aliases.sh 'r' enter keystroke is easier to type #bind b send-keys "source ~/.bashrc" "Enter" \; display ".bashrc reloaded" # 'tmux attach' starts new session if none exists # when combined with reloading above, however, causing a new session to be created every time #new-session #attach # ============================================================================ # # change default meta key from Ctrl-b to Ctrl-a to be more like screen # # seemed like a good idea initially until working on various companies servers and your muscle memory is wrong or # you need to embed screen and tmux sessions (eg. screen on laptop, tmux on remote server) without having to double escape meta keys # #unbind C-b #set -g prefix C-a # # sends meta through to other apps eg. screen #bind C-a send-prefix #bind a send-prefix # ============================================================================ # # S t a t u s B a r # ============================================================================ # # based on my screen colour style - might be better to leave tmux looking distinct with it's original block green # more complex multi-colours now set in window-status-format / window-current-status-format below instead # need this to stay set to make sure status-separator doesn't revert to bg=green set -g status-style "bg=black fg=brightgreen" # ======================================== # window list - setting to red if panes are synchronized # #I - window index # #W - window name setw -g window-status-current-format "#[bg=black fg=red][#{?pane_synchronized,#[bg=brightred fg=white],#[bg=black fg=brightblue]}#I* #W#[bg=black fg=red]]" setw -g window-status-format "#{?pane_synchronized,#[bg=brightred fg=white],#[bg=black fg=brightgreen]} #I #W" setw -g window-status-separator " " # toggle sending keystrokes to all panes in split - quick way of multi-commanding servers (like cssh back in the day) bind y set synchronize-panes\; display 'synchronize-panes #{?synchronize-panes,on,off}' # ======================================== setw -g monitor-activity on #setw -g window-status-activity-style "bg=black fg=magenta" # ======================================== # Status Left set -g status-left "#[bg=black fg=green][ #[fg=magenta]#h #[bg=black fg=green] | #S | " set -g status-left-length 50 # ======================================== # Status Right # # #{battery_percentage} - Mac shows battery percentage at top right so don't need this # #{online_status} - tmux-plugins/tmux-online-status - causes climbing duplicate status bars at bottom # #(bash ~/.tmux/plugins/kube.tmux 250 magenta green) - may not have kubernetes, also expensive to re-execute this every 5 secs # Continuum: #{continuum_status} set -g status-right "#[bg=black fg=green]| %H:%M %d/%b/%Y ]" #set -g status-right-length 100 #%if #{TMUX} #set -g status-bg red #%endif # ============================================================================ # # S e t t i n g s # ============================================================================ # # set is short for set-option # -g = global # -s = server / session # -u = unsets session to inherit global, or resets global to default with -g # -o = prevents resetting an already set value # -a = appends to current value # show all settings: # # tmux show -g # don't auto-rename windows # set-option -g allow-rename off set -g status-justify left # or centre setw -g alternate-screen on # default, restore previous contents when exiting interactive app set -g bell-action none set -g visual-bell off # renumber windows when one closes set -g renumber-windows on set -g focus-events on # if this line gives you an 'ambiguous' error, upgrade tmux set -g mouse on # disable copy-mode dragging #unbind -n MouseDrag1Pane #unbind -Tcopy-mode MouseDrag1Pane #set -g base-index 1 # start window count from 1 instead of 0 #setw -g pane-base-index 1 # start pane count from 1 instead of 0 # =============================== # these are set in tmux-sensible # #setw -g utf8 on #set -g status-interval 15 # default: 15 - how often to redraw status and execute tmux plugins #set -g default-terminal "screen-256color" # force assuming colors without 'tmux -2' or TERM environment variable set -g history-limit 100000 # give us even bigger history than tmux-sensible # ============================================================================ # # K e y b i n d i n g s # ============================================================================ # # be more like screen to toggle between last window - no longer used as interferes with portal muscle memory when working on various companies servers #bind b last-window #bind-key C-c run-shell "tmux show-buffer | xclip -i" #bind-key C-v run-shell "tmux set-buffer \\"$(xclip -o)\\"; tmux paste-buffer" # millis to wait a key after meta - default is 500ms # set higher for remote servers with latency # set lower for local sessions for speed / responsiveness set -s escape-time 1 # use expanded view - default is choose-tree view which lists sessions collapsed #bind s choose-tree -u # don't recommend changing these from the defaults if you work on other people's servers as a consultant #bind | split-window -h #bind - split-window -v # retain $PWD when splitting #bind _ split-window -v -c "#{pane_current_path}" #bind \ split-window -h -c "#{pane_current_path}" # ==================================== # shortcuts to higher numbered windows bind F1 selectw -t:10 bind F2 selectw -t:11 bind F3 selectw -t:12 bind F4 selectw -t:13 bind F5 selectw -t:14 bind F6 selectw -t:15 bind F7 selectw -t:16 bind F8 selectw -t:17 bind F9 selectw -t:18 bind F10 selectw -t:19 bind F11 selectw -t:20 bind F12 selectw -t:21 #toggle between smallest and largest sizes if a window is visible in multiple places #bind F set -w window-size # switch panes with Alt-arrow bind -n M-Left select-pane -L bind -n M-Right select-pane -R bind -n M-Up select-pane -U bind -n M-Down select-pane -D # ============================================================================ # # T M U X p l u g i n s # ============================================================================ # # Ctrl-b I to fetch plugins set -g @plugin 'tmux-plugins/tmux-sensible' # options everyone should be ok with set -g @plugin 'tmux-plugins/tmux-resurrect' # Ctrl-b Ctrl-s to save sessions, Ctrl-b Ctrl-r to restore set -g @plugin 'tmux-plugins/tmux-continuum' # needs tmux-resurrect set -g @plugin 'tmux-plugins/tmux-urlview' #set -g @plugin 'tmux-plugins/tmux-online-status' # overkill, just call .bash.d/ functions & aliases when needed #set -g @plugin 'tmux-plugins/tmux-pain-control' #set -g @plugin 'tmux-plugins/tmux-battery' # Mac shows this at top right so don't need these bash scripts set -g @continuum-save-interval '15' # default: 15, set to 0 to stop automatic saving set -g @continuum-restore 'on' # automatic restore set -g @continuum-boot 'on' # auto-start terminal at boot set -g @continuum-boot-options 'fullscreen' # if icons don't display properly set this #set -g @online_icon "ok" #set -g @offline_icon "offline!" # ============ # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) # # download TPM like so before launching/reloading tmux: # # git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm # run -b '~/.tmux/plugins/tpm/tpm'