From c84c0e3a990f5736510daa1f22e9c8eb504b0460 Mon Sep 17 00:00:00 2001 From: Lucas Date: Sun, 8 Dec 2019 18:14:46 +0000 Subject: [PATCH] Unify shell script style --- bin/ZZZ.sh | 2 +- bin/browser.sh | 2 +- bin/credentials.sh | 7 ++----- bin/fetch.sh | 9 ++++----- bin/imgresize.sh | 36 ++++++++++++++++-------------------- bin/invidious.sh | 31 ++++++++++++++++--------------- bin/rfcopen.sh | 23 +++++++++++++---------- bin/screenshot.sh | 32 ++++++++++++++------------------ bin/tor-browser.sh | 2 +- bin/w3m-copy-link.sh | 2 +- bin/xsekrit.sh | 18 ++++++++++++------ 11 files changed, 81 insertions(+), 83 deletions(-) diff --git a/bin/ZZZ.sh b/bin/ZZZ.sh index 9277d81..fe88ec6 100644 --- a/bin/ZZZ.sh +++ b/bin/ZZZ.sh @@ -1,5 +1,5 @@ #!/bin/sh -# env +# ZZZ # Written in 2019 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved # diff --git a/bin/browser.sh b/bin/browser.sh index 3e35f35..3868188 100644 --- a/bin/browser.sh +++ b/bin/browser.sh @@ -1,5 +1,5 @@ #!/bin/sh -# env +# browser # Written in 2019 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved # diff --git a/bin/credentials.sh b/bin/credentials.sh index 6e4f8d1..c28ef80 100644 --- a/bin/credentials.sh +++ b/bin/credentials.sh @@ -1,5 +1,5 @@ #!/bin/sh -# env +# credentials # Written in 2019 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved # @@ -12,10 +12,7 @@ usage() { - cat - <<. >&2 -Usage: - ${0##*/} [-2pu] service -. + printf "Usage: %s [-2pu] service\n" "${0##*/}" >&2 exit 1 } diff --git a/bin/fetch.sh b/bin/fetch.sh index 40e3cf8..5e26232 100644 --- a/bin/fetch.sh +++ b/bin/fetch.sh @@ -1,5 +1,5 @@ #!/bin/sh -# env +# fetch # Written in 2019 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved # @@ -9,9 +9,10 @@ # warranty. You should have received a copy of the CC0 Public Domain # Dedication along with this software. If not, see # . + usage() { - printf "Usage: %s [-T] URL [URLs...]\n" "${0##*/}">&2 + printf "Usage: %s [-T] URL [URL ...]\n" "${0##*/}">&2 exit 1 } @@ -34,9 +35,7 @@ while getopts T flag; do esac done shift $(($OPTIND - 1)) -if [ $# -eq 0 ]; then - usage -fi +[ $# -gt 0 ] || usage : ${ARCHIVE_BASEDIR:=~/tmp/archive} mkdir -p "$ARCHIVE_BASEDIR" diff --git a/bin/imgresize.sh b/bin/imgresize.sh index 98d47a6..245ac49 100644 --- a/bin/imgresize.sh +++ b/bin/imgresize.sh @@ -1,5 +1,5 @@ #!/bin/sh -# env +# imgresize # Written in 2019 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved # @@ -10,7 +10,8 @@ # Dedication along with this software. If not, see # . -usage() { +usage() +{ cat - <<. >&2 Usage: ${0##*/} size in-file out-file @@ -20,24 +21,21 @@ Usage: exit 1 } -check_dimension_format() { +err() +{ + printf "%s: %s\n" "${0##*/}" "$*" >&2 + exit 1 +} + +check_dimension_format() +{ printf "%s\n" "$1" | grep -q "^[0-9]*x[0-9]*\$" \ && [ "$1" != "x" ] } -if [ $# -ne 3 ] || ! check_dimension_format "$1"; then - usage -fi -if [ -z "$2" ]; then - printf "%s: Input file name can't be empty.\n" \ - "${0##*/}" >&2 - exit 1 -fi -if [ -z "$3" ]; then - printf "%s: Output file name can't be empty.\n" \ - "${0##*/}" >&2 - exit 1 -fi +[ $# -eq 3 ] && check_dimension_format "$1" || usage +[ -n "$2" ] || err "Input file name can't be empty." +[ -n "$3" ] || err "Output file name can't be empty." size=$1 w=${size%x*} @@ -52,8 +50,7 @@ case $infile in ;; *.png) inprog=pngtopam ;; -*) printf "%s: Unknown input format.\n" "${0##*/}" >&2 - exit 1 +*) err "Unknown input format." ;; esac @@ -64,8 +61,7 @@ case $outfile in ;; *.png) outprog=pamtopng ;; -*) printf "%s: Unknown output format.\n" "${0##*/}" >&2 - exit 1 +*) err "Unknown output format." ;; esac diff --git a/bin/invidious.sh b/bin/invidious.sh index 8d77d61..bd1ddba 100644 --- a/bin/invidious.sh +++ b/bin/invidious.sh @@ -1,5 +1,5 @@ #!/bin/sh -# env +# invidious # Written in 2019 by Leslie # Modified in 2019 by Lucas # CC0 1.0 Universal/Public domain - No rights reserved @@ -11,20 +11,25 @@ # Dedication along with this software. If not, see # . -usage() { +usage() +{ printf "Usage: %s url\n" "${0##*/}" >&2 exit 1 } -if [ $# -ne 1 ]; then - usage -fi +err() +{ + printf "%s: %s\n" "${0##*/}" "$*" >&2 + exit 1 +} + +[ $# -eq 1 ] || usage case $1 in "https://invidio.us/watch?v="*) ;; -*) printf "%s: Not an invidio.us url.\n" "${0##*/}" >&2 - exit 1 +*) err "Not an invidio.us url." + ;; esac video_id= @@ -34,21 +39,17 @@ for param in $(printf "%s\n" "${1##*"?"}" | tr "&" "\n"); do v=${param#*=} if [ ${#v} -ne 11 ]; then - printf "%s: "%s": not a video id.\n" "${0##*/}" "$v" >&2 + printf "%s: \"%s\": not a video ID." "${0##*/}" "$v" >&2 continue fi video_id=$v break done -if [ -z "$video_id" ]; then - printf "%s: no video ID in URL.\n" "${0##*/}" >&2 - exit 1 -fi +[ -n "$video_id" ] || err "no video ID in URL." -dl_option=$(ftp -o - "$1" 2>/dev/null \ - | grep "