summaryrefslogtreecommitdiff
path: root/core/tmux.conf
blob: 8a21bef92f7c8c0f586595a9b58dab3a2b5f5677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Ctrl-b f: prompt for text, list windows whose name, pane title or pane contents match; Enter jumps
# Ctrl-b w: tree of every window in every session; press f inside it to filter by name, Enter jumps
# Ctrl-b s: tree of sessions (same tree, session view)
# Ctrl-b p: go to the previous window (lower index, wraps); Ctrl-b n goes to the next one
#
# Vi mode for copy
setw -g mode-keys vi

# Mouse selection
set -g mouse on

# Persistent pane index labels (top-left of each pane's border)
set -g pane-border-status top
set -g pane-border-format "#P"

# Explicitly swap current pane with a pane index you type in
bind-key S command-prompt -p "swap with pane #:" "swap-pane -d -t '%%'"
bind-key P command-prompt -p "go to pane #:" "select-pane -t '%%'"
# Manual: :swap-pane -s <src> -t <dst>

# Vim-style pane resizing (prefix + H/J/K/L), magnitude 1
bind -r H resize-pane -L 1
bind -r J resize-pane -D 1
bind -r K resize-pane -U 1
bind -r L resize-pane -R 1

# Copy-mode cursor line (counted up from the bottom, matches the : goto-line prompt) in the status line;
# the status bar redraws every second, the top-right copy-mode indicator does not follow the cursor
# : goto-line only scrolls the view; also put the cursor on the bottom row so the status line shows the typed number
bind-key -T copy-mode-vi : command-prompt -p "(goto line)" { send-keys -X goto-line "%%" ; send-keys -X bottom-line }
set -g status-interval 1
set -g status-right-length 70
set -g status-right "#{?pane_in_mode,line #{e|+:#{scroll_position},#{e|-:#{e|-:#{pane_height},1},#{copy_cursor_y}}}/#{history_size}  ,}\"#{=21:pane_title}\" %H:%M %d-%b-%y"

# ===== Shared clipboard: RAM file /dev/shm/clip/buf on CLIP_HOST =====
%hidden CLIP_HOST="root@p.noml.ch"
# One persistent ssh link (opens on first use, one key touch).
# Close it: ssh -O exit -o ControlPath=~/.ssh/cm-%C <CLIP_HOST>
%hidden CLIP="ssh -o ControlMaster=auto -o ControlPersist=yes -o ControlPath=~/.ssh/cm-%C -o ServerAliveInterval=30 -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR $CLIP_HOST"
# push (yank): copy mode v to select, then y / Enter / mouse drag
%hidden YANK="$CLIP 'umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'"
bind-key -T copy-mode-vi v send-keys -X begin-selection
# y = yank selection; with no selection, y y = yank the whole line
bind-key -T copy-mode-vi y if-shell -F '#{selection_present}' { send-keys -X copy-pipe-no-clear "$YANK" } { switch-client -T copy-yy }
bind-key -T copy-yy y send-keys -X select-line \; send-keys -X copy-pipe-no-clear "$YANK"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "$YANK"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "$YANK"
# pull (paste): prefix + ] fetches the buffer into tmux, then pastes it (-p: bracketed paste, so vim inserts it as-is even from normal mode);
# no buffer on CLIP_HOST yet (exit 3, e.g. after its reboot) = paste tmux's own buffer
bind-key ] run-shell "f=\$(mktemp); $CLIP '[ -f /dev/shm/clip/buf ] || exit 3; cat /dev/shm/clip/buf' >\$f; r=\$?; [ \$r -eq 0 ] && tmux load-buffer \$f; rm -f \$f; [ \$r -eq 0 ] || [ \$r -eq 3 ] && tmux paste-buffer -p"
# ===== end shared clipboard =====
# TODO: try `set -g set-clipboard off` later (tmux default "external" sends copies to the local terminal clipboard via OSC 52); unrelated to the shared clipboard above

# Linux only: true-color regardless of what TERM the outer terminal/distro sets
if-shell 'uname | grep -q Darwin' {} {
  set -g default-terminal "tmux-256color"
  set -ga terminal-overrides ",*256col*:Tc"
}