summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorxs <xs@xs.local>2026-11-05 10:45:29 +0800
committerxs <xs@xs.local>2026-11-05 10:45:32 +0800
commitbbe55a3f647f07a6b7c9852a499c45d03ac068af (patch)
treec35e6da0cb789718ad026e8ef2be28a4fb77102d /core
parentdc1ff54f7290a42ae440389141401b78ed76d473 (diff)
core: shared clipboard over ssh to root@p.noml.ch
tmux.conf and vimrc push yanks to /dev/shm/clip/buf on CLIP_HOST (root@p.noml.ch) and pull before every paste (tmux prefix+], every vim p variant, 3 s limit, local paste when no buffer exists yet). One persistent ssh link per machine (ControlPersist=yes, ControlPath ~/.ssh/cm-%C), host key not checked. Replaces the openssl+netcat sender. vimrc: set nocompatible so /etc/vimrc parses \ continuations and <leader>.
Diffstat (limited to 'core')
-rw-r--r--core/tmux.conf29
-rw-r--r--core/vimrc37
2 files changed, 52 insertions, 14 deletions
diff --git a/core/tmux.conf b/core/tmux.conf
index 97084f1..2a0e161 100644
--- a/core/tmux.conf
+++ b/core/tmux.conf
@@ -23,19 +23,24 @@ bind -r J resize-pane -D 1
23bind -r K resize-pane -U 1 23bind -r K resize-pane -U 1
24bind -r L resize-pane -R 1 24bind -r L resize-pane -R 1
25 25
26# v to start selection, y to yank (like vim) 26# ===== Shared clipboard: RAM file /dev/shm/clip/buf on CLIP_HOST =====
27%hidden CLIP_HOST="root@p.noml.ch"
28# One persistent ssh link (opens on first use, one key touch).
29# Close it: ssh -O exit -o ControlPath=~/.ssh/cm-%C <CLIP_HOST>
30%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"
31# push (yank): copy mode v to select, then y / Enter / mouse drag
32%hidden YANK="$CLIP 'umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'"
27bind-key -T copy-mode-vi v send-keys -X begin-selection 33bind-key -T copy-mode-vi v send-keys -X begin-selection
28# macOS: pbcopy. Linux: wl-copy/xclip when usable, else just drain (tmux's own 34bind-key -T copy-mode-vi y send-keys -X copy-pipe-no-clear "$YANK"
29# buffer + set-clipboard/OSC 52 still apply). Netcat send is the same on both. 35bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "$YANK"
30if-shell 'uname | grep -q Darwin' { 36bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "$YANK"
31 bind-key -T copy-mode-vi y send-keys -X copy-pipe-no-clear "bash -c 'tee >(pbcopy) | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1'" 37# pull (paste): prefix + ] fetches the buffer into tmux, then pastes it;
32 bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "bash -c 'tee >(pbcopy) | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1'" 38# no buffer on CLIP_HOST yet (exit 3, e.g. after its reboot) = paste tmux's own buffer
33 bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "bash -c 'tee >(pbcopy) | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1'" 39bind-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"
34} { 40# ===== end shared clipboard =====
35 # Linux only: true-color regardless of what TERM the outer terminal/distro sets 41
42# Linux only: true-color regardless of what TERM the outer terminal/distro sets
43if-shell 'uname | grep -q Darwin' {} {
36 set -g default-terminal "tmux-256color" 44 set -g default-terminal "tmux-256color"
37 set -ga terminal-overrides ",*256col*:Tc" 45 set -ga terminal-overrides ",*256col*:Tc"
38 bind-key -T copy-mode-vi y send-keys -X copy-pipe-no-clear "bash -c 'tee >(wl-copy 2>/dev/null || xclip -selection clipboard 2>/dev/null || cat >/dev/null) | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1'"
39 bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-no-clear "bash -c 'tee >(wl-copy 2>/dev/null || xclip -selection clipboard 2>/dev/null || cat >/dev/null) | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1'"
40 bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-no-clear "bash -c 'tee >(wl-copy 2>/dev/null || xclip -selection clipboard 2>/dev/null || cat >/dev/null) | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1'"
41} 46}
diff --git a/core/vimrc b/core/vimrc
index 06d1782..017e754 100644
--- a/core/vimrc
+++ b/core/vimrc
@@ -1,5 +1,6 @@
1" One vimrc for Mac and Linux. Source of truth: /Users/xs/dev_env/core/vimrc 1" One vimrc for Mac and Linux. Source of truth: /Users/xs/dev_env/core/vimrc
2" Mac: cp core/vimrc ~/.vimrc Linux: sudo bash core/vim.sh (copies it to /etc/vimrc or /etc/vim/vimrc) 2" Mac: cp core/vimrc ~/.vimrc Linux: sudo bash core/vim.sh (copies it to /etc/vimrc or /etc/vim/vimrc)
3set nocompatible " /etc/vimrc is read before vim leaves vi mode; without this \ continuations and <leader> break
3" gt: go to next tab (right, wraps) 4" gt: go to next tab (right, wraps)
4" gT: go to previous tab (left, wraps) 5" gT: go to previous tab (left, wraps)
5" 2gt: go to tab number 2 (counted from 1 at the left) 6" 2gt: go to tab number 2 (counted from 1 at the left)
@@ -53,10 +54,42 @@ nnoremap <silent> <leader>f :<C-U>LspDocumentFormat<CR>| " \f: format file
53nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor 54nnoremap <silent> <leader>em :<C-U>call ExpandMacro()<CR>| " \em: expand macro under cursor
54 55
55 56
56augroup netcat_clipboard 57" ===== Shared clipboard: RAM file /dev/shm/clip/buf on g:clip_host (same as tmux.conf) =====
58let g:clip_host = 'root@p.noml.ch'
59" One persistent ssh link (opens on first use, one key touch).
60let g: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', g:clip_host]
61" push (yank): every yank or delete sends @" in a background job
62augroup ssh_clipboard
57au! 63au!
58au TextYankPost * call system("echo " . shellescape(@") . " | openssl enc -aes-256-cbc -pbkdf2 -pass pass:YourPassword | nc -w 1 p.noml.ch 5023 >/dev/null 2>&1 &") 64au TextYankPost * let g:clip_job = job_start(g:clip + ['umask 077; mkdir -p /dev/shm/clip && cat >/dev/shm/clip/new && mv /dev/shm/clip/new /dev/shm/clip/buf'], {'in_io': 'pipe', 'out_io': 'null', 'err_io': 'null'}) | call ch_sendraw(g:clip_job, @") | call ch_close_in(g:clip_job)
59augroup END 65augroup END
66" pull (paste): every p P gp gP ]p [p (normal) and p P (visual) first fetches the buffer into @".
67" Waits up to 3 s for a pending push, then up to 3 s for the fetch (perl alarm kills ssh);
68" no buffer on g:clip_host yet (exit 3, e.g. after its reboot) = normal local paste;
69" any other failure prints a message and skips the paste. Counts and "x register prefixes still work.
70function! ClipPull() abort
71 let l:i = 0
72 while exists('g:clip_job') && job_status(g:clip_job) ==# 'run' && l:i < 30
73 sleep 100m
74 let l:i += 1
75 endwhile
76 let l:out = system("perl -e 'alarm 3; exec @ARGV' " . join(g:clip) . " '[ -f /dev/shm/clip/buf ] || exit 3; cat /dev/shm/clip/buf'")
77 if v:shell_error == 3
78 return 1
79 elseif v:shell_error
80 echohl ErrorMsg | echo 'clip: pull from ' . g:clip_host . ' failed or took >3s, paste skipped' | echohl None
81 return 0
82 endif
83 call setreg('"', l:out)
84 return 1
85endfunction
86for s:k in ['p', 'P', 'gp', 'gP', ']p', '[p']
87 execute 'nnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''"
88endfor
89for s:k in ['p', 'P']
90 execute 'xnoremap <expr> ' . s:k . " ClipPull() ? '" . s:k . "' : ''"
91endfor
92" ===== end shared clipboard =====
60 93
61filetype plugin indent on 94filetype plugin indent on
62 95