wxrx/lib/utils.sh

36 lines
809 B
Bash
Raw Normal View History

2022-02-02 09:22:29 -08:00
# Lines starting with '##' are intended for usage documentation
2022-02-02 10:49:23 -08:00
# Does nothing if not using stdout
2022-02-02 09:22:29 -08:00
function usage() {
2022-02-02 10:49:23 -08:00
if [ -t 1 ]; then
grep '^##' "$prog" | sed -e 's/^##\s\?//' -e "s/__PROG__/$me/" 1>&2
fi
2022-02-02 09:22:29 -08:00
}
2022-01-22 15:15:37 -08:00
function nowstr() {
date -u +"%Y-%m-%dT%H:%M:%S%Z"
}
function log() {
2022-02-02 09:22:29 -08:00
if [ -t 1 ]; then
printf "$(tput setaf 2)[${me}]$(tput sgr0) ${1}\n" ${@:2}
else
printf "$(nowstr) [${me}] ${1}\n" ${@:2}
fi
2022-01-22 15:15:37 -08:00
}
2022-02-02 09:22:29 -08:00
function logerr() {
if [ -t 2 ]; then
2022-02-02 10:49:23 -08:00
printf "$(tput setaf 1)[${me}] ERROR:$(tput sgr0) ${1}\n" ${@:2} 1>&2
2022-02-02 09:22:29 -08:00
else
2022-02-02 10:49:23 -08:00
printf "$(nowstr) [${me}] ERROR: ${1}\n" ${@:2} 1>&2
2022-02-02 09:22:29 -08:00
fi
2022-01-22 15:15:37 -08:00
}
2022-02-03 06:29:26 -08:00
function logwarn() {
if [ -t 2 ]; then
printf "$(tput setaf 3)[${me}] WARNING:$(tput sgr0) ${1}\n" ${@:2} 1>&2
else
printf "$(nowstr) [${me}] WARNING: ${1}\n" ${@:2} 1>&2
fi
}