#!/usr/bin/env bash

## Start the CUPS service and stop it after printing.
##
## Usage: cups
##
## Dependencies: CUPS, GNU sed, systemctl
##
## I wrote this script because I rarely use my printer and I prefer that
## software only runs when needed.

set -euo pipefail
shopt -s inherit_errexit

die() { echo "${0##*/}: $1" >&2; exit 1; }

[[ " $* " =~ ' --help ' ]] && sed -n 's/^## \?//p' "$0" && exit
(( $# )) && die 'invalid argument'

sudo systemctl start cups
echo 'Ready to print.'
read -n 1 -rsp 'Press any key when you are done printing.'
echo
sudo systemctl stop cups colord
