#!/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 envs.sh 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://envs.sh)" printf '%s\n' "$url" wl-copy "$url"