Fancy colors

This commit is contained in:
Daniel Flanagan 2019-12-31 17:03:22 -06:00
parent 026220fe26
commit a05c02e1fb

View file

@ -1,11 +1,29 @@
#!/usr/bin/env bash #!/usr/bin/env bash
err() { err() {
>&2 echo "ERROR: $@"; usage; exit 1 errpre=""
errpost=""
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
errpre="$(tput setaf 1)"
errpost="$(tput setaf 7)"
fi
fi
>&2 echo "${errpre}ERROR: $@${errpost}"; usage; exit 1
} }
warn() { warn() {
>&2 echo "$@" pre=""
post=""
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
pre="$(tput setaf 3)"
post="$(tput setaf 7)"
fi
fi
>&2 echo "${pre}WARNING: $@${post}"
} }
usage() { >&2 cat <<USAGEDOC usage() { >&2 cat <<USAGEDOC
@ -39,9 +57,11 @@ while read -r line; do
body="${body}\n${line}" body="${body}\n${line}"
done done
[[ -z $body ]] && err 'Body was blank.'
echo "Recipient: $recipient" echo "Recipient: $recipient"
warn "Finished reading body. Sending email..." >&2 echo "Finished reading body. Sending email..."
swaks --auth \ swaks --auth \
--server smtp.mailgun.org \ --server smtp.mailgun.org \