aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/bin/duplex140
-rwxr-xr-xsrc/bin/qr56
-rwxr-xr-xsrc/bin/rfc98
3 files changed, 294 insertions, 0 deletions
diff --git a/src/bin/duplex b/src/bin/duplex
new file mode 100755
index 00000000..12b254e8
--- /dev/null
+++ b/src/bin/duplex
@@ -0,0 +1,140 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ duplex [-q QUALITY] [FILE...]
+ duplex -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -q QUALITY choose the print quality, either:
+ low, medium (default) or high.
+ -h, --help show this message
+
+ Examples:
+
+ Print the given PostScript file with default quality:
+ duplex f1.ps
+
+ Print multiple PDF files with high quality:
+ duplex -q high *.pdf
+
+ Print the file from STDIN:
+ cat f2.ps | duplex
+EOF
+}
+
+mkdtemp() {
+ name="$(echo 'mkstemp(template)' |
+ m4 -D template="${TMPDIR:-/tmp}/m4-tmpname.")"
+ rm -f "$name"
+ mkdir "$name"
+ echo "$name"
+}
+
+n_pages() {
+ pdftk "$1" dump_data | awk '/NumberOfPages/ { print $2 }'
+}
+
+main() {
+ if file -b in-tmp | grep -q PostScript; then
+ ps2pdf in-tmp in.pdf
+ elif file -b in-tmp | grep -q PDF; then
+ cp in-tmp in.pdf
+ else
+ printf "Don't know how to duplex print input file:\n" >&2
+ file in-tmp >&2
+ printf '\nGive me either a PostScript or PDF file instead.\n' >&2
+ exit 2
+ fi
+
+ FULL="$(n_pages in.pdf)"
+ if [ "$FULL" = '1' ]; then
+ lp in.pdf
+ return
+ fi
+
+ pdftk A=in.pdf cat Aodd output odd.pdf
+ pdftk A=in.pdf cat Aeven output even.pdf
+
+ NODD="$(n_pages odd.pdf)"
+ NEVEN="$(n_pages even.pdf)"
+
+ printf 'Printing odd pages...\n' >&2
+ lp odd.pdf
+ printf 'Has printing finished yet? Once it does, reload the pages and hit it enter to continue. '
+ read -r < /dev/tty
+ lp even.pdf
+
+ if [ "$NODD" != "$NEVEN" ]; then
+ printf '\n' | lp
+ fi
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+lpoptions -o PrintQuality=standard
+while getopts 'hq:' flag; do
+ case "$flag" in
+ q)
+ case "$OPTARG" in
+ low)
+ lpoptions -o PrintQuality=draft
+ ;;
+ medium)
+ lpoptions -o PrintQuality=standard
+ ;;
+ high)
+ lpoptions -o PrintQuality=high
+ ;;
+ *)
+ echo "Bad QUALITY option: \"$OPTARG\"" >&2
+ exit 2
+ ;;
+ esac
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+OLDDIR="$PWD"
+cd "$(mkdtemp)" #FIXME
+if [ -z "${1:-}" ]; then
+ cat - > in-tmp
+ main
+else
+ for f in "$@"; do
+ # ABS="$(echo "$(cd "$(dirname "$f")"; pwd -P)/$(basename "$f")")"
+ # echo "$ABS"
+ cp "$OLDDIR/$(basename "$f")" in-tmp
+ main
+ done
+fi
diff --git a/src/bin/qr b/src/bin/qr
new file mode 100755
index 00000000..0fce2343
--- /dev/null
+++ b/src/bin/qr
@@ -0,0 +1,56 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ qr [-s PIXEL_SIZE] [DATA|-]
+ qr -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -s size of the pixel (default 10)
+ -h, --help show this help message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+PIXEL_SIZE=10
+while getopts 's:h' flag; do
+ case "$flag" in
+ s)
+ PIXEL_SIZE="$OPTARG"
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+echo "${1:-$(cat -)}" | qrencode -s "$PIXEL_SIZE" -o- | feh -
diff --git a/src/bin/rfc b/src/bin/rfc
new file mode 100755
index 00000000..27d5357b
--- /dev/null
+++ b/src/bin/rfc
@@ -0,0 +1,98 @@
+#!/bin/sh
+set -eu
+set -o pipefail
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ rfc [-w FORMAT] RFC_NUMBER
+ rfc -h
+EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -w FORMAT Choose between text (txt, the default) and
+ JSON (json)
+ -h, --help show this message
+EOF
+}
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+FORMAT='txt'
+while getopts 'w:h' flag; do
+ case "$flag" in
+ w)
+ case "$OPTARG" in
+ json|txt)
+ FORMAT="$OPTARG"
+ ;;
+ *)
+ printf 'Bad FORMAT options: %s\n' \
+ "$OPTARG" >&2
+ exit 2
+ ;;
+ esac
+ ;;
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+if [ -z "${1:-}" ]; then
+ echo 'Missing argument RFC_NUMBER' >&2
+ usage >&2
+ exit 2
+fi
+
+if [ ! -e "$HOME/.local/share/doc/rfc/rfc$1.$FORMAT" ]; then
+ printf 'Given RFC_NUMBER "%s" does not exist\n' "$1" >&2
+ exit 2
+fi
+
+view() {
+ if [ -t 1 ]; then
+ $PAGER
+ else
+ cat -
+ fi
+}
+
+case "$FORMAT" in
+ txt)
+ cat "$HOME/.local/share/doc/rfc/rfc$1.txt" | view
+ ;;
+ json)
+ jq < "$HOME/.local/share/doc/rfc/rfc$1.json" | view
+ ;;
+ *)
+ printf 'Unreachable: unsupported FORMAT "%s"\n' \
+ "$FORMAT" >&2
+ exit 2
+ ;;
+esac