-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclipcopy
executable file
·51 lines (43 loc) · 1 KB
/
clipcopy
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
usage() {
echo "Usage: command | clipcopy [-h]
copy text from STDIN onto your clipboard
e.g. 'ls | clipcopy'
on X, puts text on 'clipboard', doesn't affect selection clipboard
on mac, uses pbcopy (cmd+c/v clipboard)
on termux, this requires the termux API
on windows, uses clip.exe"
exit "${1:-0}"
}
if [[ "$1" == '-h' ]]; then
usage
fi
STDIN="$(cat)"
[[ -z "${STDIN}" ]] && {
echo -e 'clipcopy: No data received from STDIN\n' >&2
usage 1
}
case "${ON_OS:-$(on_machine)}" in
linux*)
if havecmd wl-copy; then
printf '%s' "${STDIN}" | wl-copy
else
printf '%s' "${STDIN}" | xclip -in -selection clipboard
fi
;;
mac*)
printf '%s' "${STDIN}" | pbcopy
;;
windows*)
printf '%s' "${STDIN}" | clip.exe
;;
android_termux*)
havecmd -V 'install the termux API package: https://github.com/termux/termux-api' termux-clipboard-set || exit $?
printf '%s' "${STDIN}" | termux-clipboard-set
;;
*)
echo "clipcopy: not sure how to access clipboard..." >&2
printf '%s\n' "${STDIN}"
exit 1
;;
esac