Last active
December 18, 2015 00:09
-
-
Save fbender/5694946 to your computer and use it in GitHub Desktop.
Simple helper function for the lazy to colorize terminal scripts. MIT License. Color codes from https://wiki.archlinux.org/index.php/Color_Bash_Prompt#Advanced_prompts
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
#!/bin/bash | |
# Copyright (c) 2013 Florian Bender | |
# License: MIT (see http://opensource.org/licenses/MIT) | |
function colorset { | |
style="" | |
case $1 in | |
text) style="0;3" ;; ## regular text | |
HItext) style="0;9" ;; ## high intensity regular text | |
bold) style="1;3" ;; ## bold text | |
HIbold) style="1;9" ;; ## high intensity bold | |
undl) style="4;3" ;; ## underline | |
back) style="4" ;; ## background color | |
HIback) style="0;10" ;; ## high intensity background color | |
esac | |
color="" | |
case $2 in | |
black) color="0" ;; | |
red) color="1" ;; | |
green) color="2" ;; | |
yellow) color="3" ;; | |
blue) color="4" ;; | |
purple) color="5" ;; | |
cyan) color="6" ;; | |
white) color="7" ;; | |
esac | |
if [ -n "$style" -a -n "$color" ] | |
then | |
echo -en "\e[${style}${color}m" | |
else | |
echo -en "\e[0m" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case:
If an invalid keyword for either $style or $color is provided, the style will be reset to the default.
Tip:
echo -n TEXT
will suppress the newline character at the end of the statement, so you can use different formats on one line.