diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index c5cb891..2dd3036 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -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 diff --git a/.config/tmux/yank.sh b/.config/tmux/yank.sh new file mode 100644 index 0000000..c8a3e8a --- /dev/null +++ b/.config/tmux/yank.sh @@ -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