summaryrefslogtreecommitdiff
path: root/bin/pastebin
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pastebin')
-rwxr-xr-xbin/pastebin40
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/pastebin b/bin/pastebin
new file mode 100755
index 0000000..46be94a
--- /dev/null
+++ b/bin/pastebin
@@ -0,0 +1,40 @@
+#!/bin/sh -eu
+
+expires=
+while getopts e:h opt; do
+ case "$opt" in
+ e)
+ if ! printf %d "$OPTARG" >/dev/null 2>&1; then
+ printf "%s: invalid number '%d'\n" "${0##*/}" "$OPTARG"
+ exit 1
+ fi
+ expires="$OPTARG"
+ ;;
+ h)
+ cat <<-EOF
+Usage: ${0##*/} [-e EXPIRES] [FILE]
+
+Upload FILE (or stdin) to 0x0.st and print the URL
+
+ -e EXPIRES Set the expiration time, either hours or epoch milliseconds
+ EOF
+ exit 0
+ ;;
+ ?)
+ printf 'Usage: %s [-e EXPIRES] [FILE]\n' "${0##*/}"
+ exit 1
+ ;;
+ esac
+done
+shift $((OPTIND-1))
+if [ $# -gt 1 ]; then
+ printf 'Usage: %s [-e EXPIRES] [FILE]\n' "${0##*/}"
+ exit 1
+fi
+file="${1:-/dev/stdin}"
+[ "$file" = '-' ] && file="/dev/stdin"
+
+url="$(curl -fsS -F file=@"$file" ${expires:+-F expires="$expires"} https://0x0.st)"
+printf '%s\n' "$url"
+wl-copy "$url"
+xdg-open "$url"