theniceboy/tmux/scripts/paste_from_clipboard.sh
David Chen 1a8e4cf560 tmux: clipboard integration
- copy-mode-vi: map  to copy-pipe-and-cancel -> ~/.config/tmux/scripts/copy_to_clipboard.sh
- add C-S-v and M-V to paste from system clipboard (works over SSH)
- add scripts: paste_from_clipboard.sh, copy_to_clipboard.sh

Only staged clipboard-related changes; other edits remain unstaged.
2025-09-23 16:41:23 -07:00

38 lines
834 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
read_clipboard() {
if command -v pbpaste >/dev/null 2>&1; then
pbpaste
return 0
fi
if command -v wl-paste >/dev/null 2>&1; then
wl-paste --no-newline 2>/dev/null || wl-paste
return 0
fi
if command -v xclip >/dev/null 2>&1; then
xclip -selection clipboard -o 2>/dev/null || true
return 0
fi
if command -v xsel >/dev/null 2>&1; then
xsel -o --clipboard 2>/dev/null || true
return 0
fi
if command -v powershell.exe >/dev/null 2>&1; then
powershell.exe -NoProfile -Command Get-Clipboard 2>/dev/null || true
return 0
fi
return 1
}
content=$(read_clipboard || true)
if [[ -z "${content:-}" ]]; then
exit 0
fi
# normalize CRLF -> LF
content=$(printf '%s' "$content" | tr -d '\r')
tmux set-buffer -- "$content"
tmux paste-buffer -p -d