From a05c02e1fb31a6c44d442ddda43ffb8ef5e74b9b Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 31 Dec 2019 17:03:22 -0600 Subject: [PATCH] Fancy colors --- bin/email-via-mailgun-smtp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/email-via-mailgun-smtp b/bin/email-via-mailgun-smtp index 3b885cf..2b2dfb5 100755 --- a/bin/email-via-mailgun-smtp +++ b/bin/email-via-mailgun-smtp @@ -1,11 +1,29 @@ #!/usr/bin/env bash 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() { - >&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 <&2 echo "Finished reading body. Sending email..." swaks --auth \ --server smtp.mailgun.org \