#!/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 -
