aboutsummaryrefslogtreecommitdiff
path: root/termbin
blob: 441be32914d5d8c9db686f9a2f7a3c1b85fe3995 (plain)
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
#!/bin/sh

# 20200424 bkw: This used to be a one-line script:
# cat "${1:--}" | nc termbin.com 9999
# ...but I really wanted the "copy link to X clipboard" feature.

if [ "$1" = "--help" ]; then
	cat <<EOF
Usage: $( basename $0 ) <filename>

Uses nc (NetCat) to paste stdin to termbin.com, or pastes a file if
<filename> is given. Spits out paste URL on stdout. Also copies URL to
the X clipboard if X is running and either xsel or xclip is installed.

Written by B. Watson <urchlay@slackware.uk>, released under the WTFPL:
do WTF you want with this.
EOF
	exit 0
fi

if ! which nc &>/dev/null; then
	echo "$( basename $0 ): can't find nc on path, install nc or netcat package"
	exit 1
fi

url="$( cat "${1:--}" | nc termbin.com 9999 )"
[ -z "$url" ] && exit "$?"

echo "$url"

if [ -n "$DISPLAY" ]; then
	if   which xsel  &>/dev/null; then
		echo -n "$url" | xsel -i
	elif which xclip &>/dev/null; then
		echo -n "$url" | xclip
	fi
fi