#+TITLE: Tmux Configuration #+AUTHOR: Mitch Tishmack #+STARTUP: hidestars #+STARTUP: odd #+PROPERTY: header-args :cache yes #+PROPERTY: header-args :padline no #+PROPERTY: header-args :mkdirp yes #+PROPERTY: header-args :comments no #+PROPERTY: header-args :replace yes Tmux configuration Use vi mode for tmux keybindings. Means if we start emacs up, no conflicts for keybinds. Also set aggressive resize so our panes resize somewhat sanely with multiple clients. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-window-option -g mode-keys vi set-window-option -g aggressive-resize on #+END_SRC Use the only shell that matters for our login shell. Set our TERM to xterm-256color as well. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-option -g default-command 'zsh -l' set-option -g default-terminal 'xterm-256color' #+END_SRC Status line options. For the status line we want the selected window tabish thing to be white background and black foreground. Use the default coloring which is white on black. Helps make the current tab rather obvious from color alone ignoring the * character. Additionally, setup the status lines so we have a mostly minimal setup on what is displayed. Try to keep things as minimal as possible. Also note the status-interval is 7 seconds long, this is intentional as it ensures that any skew on waking up/updating isn't visible. Yes I'm weird in that if I specify 5 and don't get things updated every 0-4 seconds it annoys me. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-window-option -g window-status-current-style bg=white,fg=black set-window-option -g window-status-style default set-option -g window-status-format '#I #W#F' set-option -g window-status-current-format '#I:#W#{?window_zoomed_flag, 🔍,}' set-option -g status-style bg=black,fg=colour7 set-option -g status-interval 7 set-option -g status-left-length 24 set-option -g status-left '' #+END_SRC Right status just with Day HH:MM:SS to the right. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-option -g status-right-length 13 set-option -g status-right "%a %H:%M:%S" #+END_SRC Right status with battery shenanigans. Only present on macos for now. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-option -g status-right-length 20 set-option -g @batt_remain_minimal true set-option -g @batt_icon_status_charged ' ' set-option -g @batt_icon_status_charging '↑' set-option -g @batt_icon_status_discharging '↓' set-option -g @batt_icon_status_unknown '?' set-option -g @batt_color_status_primary_discharging colour9 set-option -g status-right "#{battery_color_fg}#{battery_icon_status}#[default] #{battery_color_charge_bg}#{battery_remain}#[default] %a %H:%M:%S" run-shell ~/src/github.com/tmux-plugins/tmux-battery/battery.tmux #+END_SRC The highlight style is how tmux renders selected text. Black on red is what I use to make it obvious what is being selected. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-window-option -g mode-style bg=red,fg=black #+END_SRC Pane border options, mostly an attempt to mimic/ape the status line setup. Intent is we want to know what pane we're selected into, however we only set the foreground so that if we are on a white on black, or black on white or some other scheme we don't have a gaudy background for the panes. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-option -g pane-border-style fg=colour7 set-option -g pane-active-border-style fg=colour2 #+END_SRC TTY alert character stuff. Much like a phone, don't make a sound. Leave that kinda gaudy sound beeps to boomers. Basically flash the message/status bar with a black on white message. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-option -g visual-activity on set-option -g visual-bell on set-option -g message-style bg=colour7,fg=black #+END_SRC Use the window title if available and update it if it changes. Aka, in iterm2/Terminal.app on macos generally this is set to the active command or shell. Can rename it to something else if we want as well. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) set-option -g set-titles on set-option -g set-titles-string '#T' set-window-option -g automatic-rename on #+END_SRC Custom key rebindings. PREFIX + R = Reload tmux configuration. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) bind-key R \ source-file ~/.tmux.conf \;\ display 'reloaded ~/.tmux.conf' #+END_SRC Note, this uses tmux 2.9 syntax now. Which is annoying af, used to be able to just modify the fg/bg independently but now if you set the current style fg, it presumes default for everything *GRRRR*. So if you have to care about the background have to check that as well. Current strategy here is to dump out the window options and look for window-status-current-style and yoink the existing bg if present. Essentially the foreground is changed to green when logging this pane. Background is set to red when synchronizing. That's about it. PREFIX + o = L*o*g pane output to a file. Saved with the iso8601 command for the name. Also change the foreground text to green so we know we're logging. * TODO Tmux logging key is broken :someday:broken: #+BEGIN_SRC conf :tangle no bind-key o \ pipe-pane -o "cat >> $HOME/tmux-`iso8601`.log" \;\ if-shell \ "tmux show-window-options | grep 'window-status-current-style' | grep fg=green'" \ "set-window-option "display 'stopping logging pane output' set-window-option window-status-current-style fg=green #+END_SRC PREFIX + O = St*O*p logging pane output. Also reset the fg color back to default. #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) bind-key O \ pipe-pane \;\ set-window-option window-status-current-style default \; #+END_SRC #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (bound-and-true-p tmux-p)) bind-key N new-session -t default # Using s for synchronizing panes, means that s for choosing sessions # is now e unbind-key s # interactive select sessions bind-key e choose-tree # (un)synchronize panes with prefix-s bind-key s \ if-shell \ "tmux show-window-options | grep 'synchronize-panes on'" \ "set-window-option window-status-current-style bg=white,fg=black; \ set-window-option pane-active-border-style bg=colour15,fg=colour2; \ set-window-option synchronize-panes off; \ display 'synchronization off'" \ "set-window-option window-status-current-style bg=red,fg=black; \ set-window-option pane-active-border-style bg=colour15,fg=red; \ set-window-option synchronize-panes on; \ display 'synchronizing'" # same thing as ^ so it sets up things if we were started with # something else that set synchronization. if-shell \ "tmux show-window-options | grep 'synchronize-panes on' || /bin/true" \ "set-window-option window-status-current-style bg=red; \ set-window-option pane-active-border-style bg=red,fg=black" # Setup splits to be less annoying bind-key \\ split-window -h bind-key - split-window -v # vi keybindings for pane navigation bind-key k select-pane -U bind-key j select-pane -D bind-key h select-pane -L bind-key l select-pane -R # Make it so that I can detach/etc while holding control down, # PURE LAZY bind-key C-d detach bind-key C-n next-window bind-key C-p previous-window bind-key C-k select-pane -U bind-key C-j select-pane -D bind-key C-h select-pane -L bind-key C-l select-pane -R # Non confirming kill pane plskthxbai bind-key x kill-pane # Lets change the prefix key so we don't clobber emacs back one char key unbind-key C-b # hacky, but C-\ isn't used by anything overly important in emacs set-option -g prefix 'C-\' # two C-\'s == C-\, if i need it, likely not bind 'C-\' send-prefix # Delay in sending things is dumb set-option -s escape-time 1 # so we can scroll the mouse, select panes, etc... set -g mouse on bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'" bind-key m \ if-shell \ "tmux show-options -g | grep 'mouse on'" \ "set -g mouse off; \ display 'Mouse modes off'" \ "set -g mouse on; \ display 'Mouse modes on'" #+END_SRC Only set xclip for when x is in use #+BEGIN_SRC conf :tangle (tangle/file ".tmux.conf" (and (bound-and-true-p tmux-p) (bound-and-true-p x-p))) bind C-p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer" bind C-y run "tmux save-buffer - | xclip -i" #+END_SRC