Unify shell script style

This commit is contained in:
Lucas 2019-12-08 18:14:46 +00:00
parent 8d3ae231bb
commit c84c0e3a99
11 changed files with 81 additions and 83 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# ZZZ
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# browser
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#

View File

@ -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
}

View File

@ -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
# <http://creativecommons.org/publicdomain/zero/1.0/>.
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"

View File

@ -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
# <http://creativecommons.org/publicdomain/zero/1.0/>.
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

View File

@ -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
# <http://creativecommons.org/publicdomain/zero/1.0/>.
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 "<option value='{" \
| head -n 1 | cut -d "\"" -f 8)
dl_option=$(ftp -o - "$1" 2>/dev/null | grep -F "<option value='{" |
head -n 1 | cut -d "\"" -f 8)
printf "https://invidio.us/latest_version?id=%s&itag=%s\n" \
"$video_id" "$dl_option"

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# rfcopen
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
@ -10,12 +10,20 @@
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() {
usage()
{
printf "Usage: %s [-T] rfc-number\n" "${0##*/}" >&2
exit 1
}
tonumber() {
err()
{
printf "%s: %s\n" "${0##*/}" "$*" >&2
exit 1
}
tonumber()
{
printf "%u" "$1" 2>/dev/null
}
@ -32,18 +40,13 @@ while getopts T flag; do
done
shift $(($OPTIND - 1))
if [ $# -ne 1 ] || [ -z "$1" ] || ! n=$(tonumber "$1"); then
usage
fi
[ $# -eq 1 ] && [ -n "$1" ] && n=$(tonumber "$1") || usage
rfcfile=$RFCDIR/rfc$n.txt
url=https://tools.ietf.org/rfc/rfc$n.txt
mkdir -p "$RFCDIR"
if [ ! -f "$rfcfile" ]; then
if ! $torsocks ftp -Vo "$rfcfile" "$url"; then
printf "%s: Couldn't fetch RFC %u\n" "${0##*/}" "$n" >&2
exit 1
fi
$torsocks ftp -Vo "$rfcfile" "$url" || err "Couldn't fetch RFC $n."
fi
${PAGER:-more} "$rfcfile"

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# screenshot
# 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
# <http://creativecommons.org/publicdomain/zero/1.0/>.
usage() {
usage()
{
cat - <<. >&2
Usage:
${0##*/}
@ -21,30 +22,25 @@ Usage:
exit 1
}
save_screenshot() {
err()
{
printf "%s: %s\n" "${0##*/}" "$*" >&2
exit 1
}
save_screenshot()
{
xwdtopnm | pnmtopng >~/media/ss/"$(date +%Y%m%d-%H%M%S)".png
}
case $# in
0) xwd -silent -root | save_screenshot
;;
1) if [ "$1" != "-window" ]; then
printf "%s: Unknown option \"%s\".\n" \
"${0##*/}" "$1" >&2
exit 1
fi
1) [ "$1" = "-window" ] || err "Unknown option \"$1\"."
xwd -silent | save_screenshot
;;
2) if [ "$1" != "-id" ] && [ "$1" != "-name" ]; then
printf "%s: Unknown option \"%s\".\n" \
"${0##*/}" "$1" >&2
exit 1
fi
if [ -z "$2" ]; then
printf "%s: %s expects a non-empty parameter.\n" \
"${0##*/}" "$1" >&2
exit 1
fi
2) [ "$1" = "-id" ] || [ "$1" = "-name" ] || err "Unknown option \"$1\"."
[ -n "$2" ] || err "$1 expects a non-empty parameter."
xwd -silent "$1" "$2" | save_screenshot
;;
*) usage

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# tor-browser
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# w3m-copy-link
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#

View File

@ -1,5 +1,5 @@
#!/bin/sh
# env
# xsekrit
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
@ -10,12 +10,18 @@
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
if [ $# -ne 1 ] || [ -z "$1" ]; then
usage()
{
printf "Usage: %s key\n" "${0##*/}" >&2
exit 1
fi
if ! sekrit has "$1"; then
printf "%s: Unknown key \"%s\".\n" "${0##*/}" "$1" >&2
}
err()
{
printf "%s: %s\n" "${0##*/}" "$*" >&2
exit 1
fi
}
[ $# -eq 1 ] && [ -n "$1" ] || usage
sekrit has "$1" || err "Unknown key \"$1\"."
sekrit get "$1" | xclip -q -r -l 1 -sel clip 2>/dev/null