BadSegway

Atlanta, GA, USA

https://gitlab.com/badsegway

☕ null

Free badge offered; thereforce, I shall insert pointless things here, sooooo:

u haz a bash script coloring library?

#!/bin/bash
# -------------------------------------------
# Simple functions for making tasty logging scripts ;)
# ~ @BadSegway, 2019 - MIT License (if anyone cares/asks)
# https://gitlab.com/snippets/1838117/raw
# -------------------------------------------

# Set some functions for logging in color
color()     { echo -e "[\033[0;35m$(date -u)\033[0m] \033[1;${1}m${@:2}\033[0m"; }
success()   { color 32 "SUCCESS: ${@}"; }
warn()      { color 33 "WARN:    ${@}"; }
comment()   { color 36 "COMMENT: ${@}"; }
err()       { color 31 "ERROR:   ${@}"; exit 1; }
ctrlc()     { echo ""; err "CTRL-C pressed; quitting ..."; }
info()      { color 37 "INFO:    ${@}"; }

# Exit on error
trap 'ctrlc' SIGINT
trap 'err "line $LINENO; exitting ..."' ERR

# -------------------------------------------
# If you run this file with "demo" as an
# argument, the below demo code will run
# -------------------------------------------
if [[ $# -gt 0 && $1 = "demo" ]]; then

SCRIPTUSER="${USER}"
SCRIPTPATH="${BASH_SOURCE}"

sudo -u "${SCRIPTUSER}" bash -s <<EOF
    # Load awesome coloring ;)
    source "${SCRIPTPATH}"

    # Used like:
    success Something went right
    warn    Something may have went wrong
    comment Something is just a comment
    info    Something is normal

    # We can type a command wrong (and we'll auto exit due
    # to the ERR trap we set in the utils script above)
    # Try running:
    # $ some_command_that_shouldnt_exist_and_will_throw_an_error

    # We can also explicitly exit when something goes wrong
    # but doesn't throw an exit code error
    err     'Something went wrong (we did it ;)) quitting'
EOF
echo ""
fi
Top Questions
No questions with score of 5 or more
Top Answers
No answers with score of 5 or more