mirror of
https://github.com/theniceboy/.config.git
synced 2026-05-11 17:36:05 +08:00
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.
This commit is contained in:
parent
449fbc261e
commit
1a8e4cf560
3 changed files with 72 additions and 1 deletions
22
tmux/scripts/copy_to_clipboard.sh
Executable file
22
tmux/scripts/copy_to_clipboard.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
content=$(cat | tr -d '\r')
|
||||
# Update tmux buffer and system clipboard (uses tmux set-clipboard setting)
|
||||
tmux set-buffer -w -- "$content"
|
||||
|
||||
# Best-effort: also call platform clip utilities when available
|
||||
if command -v pbcopy >/dev/null 2>&1; then
|
||||
printf '%s' "$content" | pbcopy || true
|
||||
elif command -v wl-copy >/dev/null 2>&1; then
|
||||
printf '%s' "$content" | wl-copy --type text || wl-copy || true
|
||||
elif command -v xclip >/dev/null 2>&1; then
|
||||
printf '%s' "$content" | xclip -selection clipboard || true
|
||||
elif command -v xsel >/dev/null 2>&1; then
|
||||
printf '%s' "$content" | xsel --clipboard --input || true
|
||||
elif command -v powershell.exe >/dev/null 2>&1; then
|
||||
powershell.exe -NoProfile -Command Set-Clipboard -Value @"
|
||||
${content}
|
||||
"@ || true
|
||||
fi
|
||||
|
||||
38
tmux/scripts/paste_from_clipboard.sh
Executable file
38
tmux/scripts/paste_from_clipboard.sh
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue