-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy
More file actions
executable file
·30 lines (28 loc) · 749 Bytes
/
copy
File metadata and controls
executable file
·30 lines (28 loc) · 749 Bytes
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
#!/bin/bash
# copy - universal clipboard script for Linux, macOS, Windows
copy_to_clipboard() {
if command -v xclip >/dev/null 2>&1; then
xclip -selection clipboard
elif command -v wl-copy >/dev/null 2>&1; then
wl-copy
elif command -v pbcopy >/dev/null 2>&1; then
pbcopy
elif command -v clip.exe >/dev/null 2>&1; then
clip.exe
else
echo "Error: No clipboard command found (install xclip, wl-clipboard, pbcopy, or use Windows with clip.exe)." >&2
exit 1
fi
}
if [ -t 0 ]; then
# No stdin (no pipe)
if [ $# -eq 0 ]; then
echo "Usage: echo 'text' | copy OR copy 'text to copy'" >&2
exit 1
else
printf "%s" "$*" | copy_to_clipboard
fi
else
# Input comes from a pipe
copy_to_clipboard
fi