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

View File

@@ -36,6 +36,20 @@ unbind %
# Reload the tmux configuration file with 'r'
bind r source-file $XDG_CONFIG_HOME/tmux/tmux.conf
### Clipboard Integration
# Enable clipboard
set -s set-clipboard on
set -ag terminal-overrides ",*:Ms=\\E]52;c;%p2%s\\7"
# Vi-style copy mode
setw -g mode-keys vi
# Copy mode key bindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "$XDG_CONFIG_HOME/tmux/yank.sh"
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "$XDG_CONFIG_HOME/tmux/yank.sh"
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "$XDG_CONFIG_HOME/tmux/yank.sh"
### Status and Window Configuration
# Set the status bar update interval to 1 second
set -g status-interval 1

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