tmux: Fixed copying over ssh/mosh

This commit is contained in:
2026-02-12 09:20:50 +01:00
parent 03f69af191
commit fb1870d332
2 changed files with 39 additions and 0 deletions

25
.config/tmux/yank.sh Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/sh
# tmux clipboard helper - works locally and over SSH/mosh
set -eu
# Read from stdin
buf=$(cat)
# Try methods in order of preference
copy_backend_remote_tunnel_port=$(tmux show-option -gvq "@copy_backend_remote_tunnel_port" 2>/dev/null || echo "")
# Method 1: Use pbcopy if available (local macOS)
if command -v pbcopy >/dev/null 2>&1; then
printf "%s" "$buf" | pbcopy
# Method 2: OSC 52 (for mosh/ssh)
elif [ -n "${TMUX:-}" ]; then
# Get the tmux tty
tmux_tty=$(tmux display-message -p '#{client_tty}')
# Encode in base64
encoded=$(printf "%s" "$buf" | base64 | tr -d '\n')
# Send OSC 52 sequence
printf "\033]52;c;%s\a" "$encoded" > "$tmux_tty"
fi