Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

8.7 KiB

Tmux Configuration

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.

  set-window-option -g mode-keys vi
  set-window-option -g aggressive-resize on

Use the only shell that matters for our login shell. Set our TERM to xterm-256color as well.

  set-option -g default-command 'zsh -l'
  set-option -g default-terminal 'xterm-256color'

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.

  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 ''

Right status just with Day HH:MM:SS to the right.

  set-option -g status-right-length 13
  set-option -g status-right "%a %H:%M:%S"

Right status with battery shenanigans. Only present on macos for now.

  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

The highlight style is how tmux renders selected text. Black on red is what I use to make it obvious what is being selected.

  set-window-option -g mode-style bg=red,fg=black

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.

  set-option -g pane-border-style fg=colour7
  set-option -g pane-active-border-style fg=colour2

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.

  set-option -g visual-activity on
  set-option -g visual-bell on
  set-option -g message-style bg=colour7,fg=black

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.

  set-option -g set-titles on
  set-option -g set-titles-string '#T'
  set-window-option -g automatic-rename on

Custom key rebindings.

PREFIX + R = Reload tmux configuration.

  bind-key R \
    source-file ~/.tmux.conf \;\
    display 'reloaded ~/.tmux.conf'

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.

  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

PREFIX + O = St*O*p logging pane output. Also reset the fg color back to default.

  bind-key O \
    pipe-pane \;\
    set-window-option window-status-current-style default \;

  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'"

Only set xclip for when x is in use

  bind C-p run "tmux set-buffer \"$(xclip -o)\"; tmux paste-buffer"
  bind C-y run "tmux save-buffer - | xclip -i"