Created
December 19, 2020 20:36
-
-
Save Yaulendil/7abb63a2837c42f6dd5e4f3d1eecc409 to your computer and use it in GitHub Desktop.
Bash Function for easy ANSI color codes
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 color() { | |
reset=(reset) | |
if ( [[ -z "$1" ]] || [[ "$@" == "$reset" ]] ); then | |
echo -en "\e[0m" | |
else | |
style=22 | |
class=3 | |
color=0 | |
for term in "$@"; do | |
case "$term" in | |
normal) style=22 ;; | |
bold) style=1 ;; | |
dim) style=2 ;; | |
italic) style=3 ;; | |
uline) style=4 ;; | |
blink) style=5 ;; | |
blink2) style=6 ;; | |
invert) style=7 ;; | |
hide) style=8 ;; | |
strike) style=9 ;; | |
normal) class=3 ;; | |
back | bg) class=4 ;; | |
bright | light) | |
class=9 ;; | |
bg-bright | bg-light) | |
class=10 ;; | |
black) color=0 ;; | |
red) color=1 ;; | |
green) color=2 ;; | |
yellow) color=3 ;; | |
blue) color=4 ;; | |
purple) color=5 ;; | |
cyan) color=6 ;; | |
white) color=7 ;; | |
clear) | |
style=22 | |
class=3 | |
color=0 | |
;; | |
esac | |
done | |
echo -en "\e[${style};${class}${color}m" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment