-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcb
More file actions
executable file
·31 lines (27 loc) · 799 Bytes
/
cb
File metadata and controls
executable file
·31 lines (27 loc) · 799 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
31
#!/usr/bin/env bash
set -e # Exit if one of commands exit with non-zero exit code
set -u # Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error
set -o pipefail # Any command failed in the pipe fails the whole pipe
# set -x # Print shell commands as they are executed (or you can try -v which is less verbose)
# cb is a shorthand for "ClipBoard"
paste() {
if isMacOs; then
pbpaste
else
xsel -ob;
fi
}
copy() {
if isMacOs; then
pbcopy
else
xclip -selection clipboard
fi
}
if [ $# -eq 1 ]; then
readlink -f "$1" | xargs echo -n | copy
elif [ ! -t 0 ]; then # If stdin descriptor isn't opened on tty (it can be interpreted as "something is piped into the stdin")
copy
else
paste
fi