aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/plugin/bin/paste-buffer
blob: c5c16844533b9b0baeef52b499a4ba2b7d9bc89f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh
# tmux prefix+] (paste-buffer -p): paste the most recent copy into the current
# pane. Herdr copies to the system clipboard, so that is the buffer. -p means
# bracketed paste when the application asked for it, and that is what herdr's
# send-text already does (src/app/api_helpers.rs: encode_api_text).
. "$(dirname "$0")/../lib.sh"

if command -v pbpaste >/dev/null 2>&1; then
    buf="$(pbpaste; printf x)"
elif command -v wl-paste >/dev/null 2>&1; then
    buf="$(wl-paste --no-newline; printf x)"
elif command -v xclip >/dev/null 2>&1; then
    buf="$(xclip -o -selection clipboard; printf x)"
else
    fail "no buffers"
fi
# The x keeps trailing newlines that $(...) would strip; tmux pastes verbatim.
buf="${buf%x}"
[ -n "$buf" ] || fail "no buffers"
"$H" pane send-text "$(active_pane)" "$buf" >/dev/null