From f909ab3cd1487bc463ea10e0ec9df54cdc99edee Mon Sep 17 00:00:00 2001 From: clsr Date: Wed, 16 Nov 2016 20:38:58 +0100 Subject: Add --service flag to gomfload.sh --- gomfload.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/gomfload.sh b/gomfload.sh index d3963f9..77dcbed 100755 --- a/gomfload.sh +++ b/gomfload.sh @@ -6,7 +6,7 @@ # requires: POSIX sh, curl, tr -host="${GOMF_HOST:-https://example.com/}" +service="${GOMF_HOST:-https://example.com/}" prog="$(basename "$0")" stdin=1 @@ -15,6 +15,14 @@ usage() { printf "Usage: %s < file\n" "$prog" printf " command | %s\n" "$prog" printf " %s file1 file2 file3 ...\n" "$prog" + printf "\n" + printf "Options (applies for all files following the flag):\n" + printf " -S, --service=ADDR uses ADDR as the service URL\n" + printf " -h, --help display this help and exit\n" + printf " -- stop processing options and treat all following arguments as filenames\n" + printf "\n" + printf "Example: %s foo -lsh bar -u baz -p quux -L qwe asd\n" "$prog" + printf " will post 'foo' and 'baz' as files, 'bar' and 'quux' as .sh pastes and 'qwe' and 'asd' as raw pastes\n" exit } @@ -26,7 +34,7 @@ upload() { file=";filename=$filename" fi fi - url="$(curl --progress-bar -F "files[]=@-$file" "${host%/}/upload.php?output=gyazo")" + url="$(curl --progress-bar -F "files[]=@-$file" "${service%/}/upload.php?output=gyazo")" case "$url" in http*) printf "%s\n" "$url" @@ -56,6 +64,24 @@ while [ $# -gt 0 ]; do usage ;; + -S|--service) + if [ $# -ge 2 ]; then + service="$2" + shift + else + printf "%s: option '%s' requires an argument\n" "$prog" "$1" >&2 + exit 2 + fi + ;; + + -S?*) + service="${1#-S}" + ;; + + --service=*) + service="${1#*=}" + ;; + --) shift break -- cgit