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 ".
-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"
diff --git a/bin/screenshot.sh b/bin/screenshot.sh
index 5a601b9..b3764ab 100644
--- a/bin/screenshot.sh
+++ b/bin/screenshot.sh
@@ -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
# .
-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
diff --git a/bin/tor-browser.sh b/bin/tor-browser.sh
index 6b46d46..9de04eb 100644
--- a/bin/tor-browser.sh
+++ b/bin/tor-browser.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# env
+# tor-browser
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
diff --git a/bin/w3m-copy-link.sh b/bin/w3m-copy-link.sh
index 0a57a91..7421185 100644
--- a/bin/w3m-copy-link.sh
+++ b/bin/w3m-copy-link.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# env
+# w3m-copy-link
# Written in 2019 by Lucas
# CC0 1.0 Universal/Public domain - No rights reserved
#
diff --git a/bin/xsekrit.sh b/bin/xsekrit.sh
index 9d4e140..183d62d 100644
--- a/bin/xsekrit.sh
+++ b/bin/xsekrit.sh
@@ -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
# .
-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