Last active
September 16, 2020 17:15
-
-
Save gregswift/11ee552bc443e1051eef9454c833c07f to your computer and use it in GitHub Desktop.
colorize.bashrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function colorize() { | |
case "${2}" in | |
black) | |
FG_COLOR=0 | |
;; | |
red) | |
FG_COLOR=1 | |
;; | |
green) | |
FG_COLOR=2 | |
;; | |
yellow) | |
FG_COLOR=3 | |
;; | |
blue) | |
FG_COLOR=4 | |
;; | |
magenta) | |
FG_COLOR=5 | |
;; | |
cyan) | |
FG_COLOR=6 | |
;; | |
white) | |
FG_COLOR=7 | |
;; | |
*) | |
FG_COLOR=${2} | |
;; | |
esac | |
FG_CODE="$(tput setaf ${FG_COLOR})" | |
BG_CODE="$(tput setab 0)" | |
OPEN_ESC=$'\001' | |
CLOSE_ESC=$'\002' | |
RESTORE="$(tput sgr0)" | |
echo "${OPEN_ESC}${FG_CODE}${BG_CODE}${CLOSE_ESC}${1}${OPEN_ESC}${RESTORE}${CLOSE_ESC}" | |
} | |
function colorize_tier() { | |
case "$1" in | |
*dev*) | |
COLOR=green | |
;; | |
*test*) | |
COLOR=blue | |
;; | |
*stage*) | |
COLOR=yellow | |
;; | |
*prod*) | |
COLOR=red | |
;; | |
*) | |
COLOR=white | |
esac | |
echo $(colorize ${1} ${COLOR}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment