aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2020-04-24 22:44:00 -0400
committerB. Watson <yalhcru@gmail.com>2020-04-24 22:44:00 -0400
commit19f7ab5fbb36ae3139d7dfe885fde01bff4869b5 (patch)
treed2b86a949394d8971d40ef2abcead168f1b01f05
parentd4ee19b25164ca8bf70f3d8235f20052444cf9ed (diff)
downloadmisc-scripts-19f7ab5fbb36ae3139d7dfe885fde01bff4869b5.tar.gz
Add termbin (paste stdin or file to termbin.com)
-rwxr-xr-xtermbin37
1 files changed, 37 insertions, 0 deletions
diff --git a/termbin b/termbin
new file mode 100755
index 0000000..80d083c
--- /dev/null
+++ b/termbin
@@ -0,0 +1,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 <yalhcru@gmail.com>, 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