-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcb
executable file
·32 lines (26 loc) · 810 Bytes
/
cb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
set -eEu -o pipefail
shopt -s inherit_errexit
IFS=$'\n\t'
PS4='+\t '
error_handler() { echo "Error: Line ${1} exited with status ${2}"; }
trap 'error_handler ${LINENO} $?' ERR
[[ "${TRACE:-0}" == "1" ]] && set -x
if [[ $OSTYPE == darwin* ]]; then
copy() { perl -pe "chomp if eof" | pbcopy; }
paste() { pbpaste | perl -pe "chomp if eof"; }
elif [[ "${XDG_SESSION_TYPE:-}" == wayland ]]; then
copy() { wl-copy --trim-newline; }
paste() { wl-paste --no-newline; }
elif [[ -n "${DISPLAY:-}" ]] && command -v xclip > /dev/null; then
copy() { xclip -i -selection clipboard -rmlastnl; }
paste() { xclip -o -selection clipboard -rmlastnl; }
else
echo "No supported clipboard tool found" >&2
exit 1
fi
if [[ -p /dev/stdin ]]; then
copy
else
paste
fi