-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxcopy.sh
More file actions
executable file
·36 lines (31 loc) · 836 Bytes
/
xcopy.sh
File metadata and controls
executable file
·36 lines (31 loc) · 836 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
32
33
34
35
36
#!/bin/sh
#title : xcopy.sh
#description : Copies stdin to the clipboard.
#author : dduits (https://github.com/dduits)
#license : MIT, see the LICENSE file for more information.
#version : 1.0
#usage : echo "testing" | xcopy.sh
# Get from standard input.
[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-"
input=$(cat $input)
trim=false
while getopts "t" opt; do
case $opt in
t) trim=true;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# If user has provided the -t flag then remove a trailing break line (if present).
if [ "$trim" = true ]; then
echo "$input" | grep '^' | head -c-1 - | xclip -selection c
else
echo "$input" | xclip -selection c
fi
exit 0