From 0b6b998298afe1b04f84ff11427d23c7cce2ea5d Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Wed, 4 Oct 2023 12:49:24 -0400 Subject: bin: add pastebin script --- bin/pastebin | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 bin/pastebin (limited to 'bin/pastebin') 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" -- cgit v1.2.3