Last active
December 17, 2015 13:25
-
-
Save WebReflection/02cdcb6d4ce0dfa38fac to your computer and use it in GitHub Desktop.
A simple bash/sh utility to write console text with some color and bold
This file contains hidden or 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
| # slightly enriched echo | |
| # - - - - - - - - - - - - - - | |
| # by Andrea Giammarchi | |
| icho() { | |
| # [*][g]✔[/] [*][r]x[/] [*][y]![/] | |
| # resets | |
| local reset_all=$(tput sgr0) # [/] usable as reset for each style | |
| local reset_color=$(tput setaf 9) # [/(d|r|g|y|b|m|c|w)] | |
| local reset_bgcolor=$(tput setab 9) # [/(bd|br|bg|by|bb|bm|bc|bw)] | |
| local reset_underline=$(tput rmul) # [/_] | |
| local reset_stand_out=$(tput rmso) # [/o] | |
| # colors | |
| local black=$(tput setaf 0) # [d]dark[/d] | |
| local red=$(tput setaf 1) # [r]red[/r] | |
| local green=$(tput setaf 2) # [g]green[/g] | |
| local yellow=$(tput setaf 3) # [y]yellow[/y] | |
| local blue=$(tput setaf 4) # [b]blue[/b] | |
| local magenta=$(tput setaf 5) # [m]magenta[/m] | |
| local cyan=$(tput setaf 6) # [c]cyan[/c] | |
| local white=$(tput setaf 7) # [w]white[/w] | |
| # background colors | |
| local bgblack=$(tput setab 0) # [bd]bg dark[/bd] | |
| local bgred=$(tput setab 1) # [br]bg red[/br] | |
| local bggreen=$(tput setab 2) # [bg]bg green[/bg] | |
| local bgyellow=$(tput setab 3) # [by]bg yellow[/by] | |
| local bgblue=$(tput setab 4) # [bb]bg blue[/bb] | |
| local bgmagenta=$(tput setab 5) # [bm]bg magenta[/bm] | |
| local bgcyan=$(tput setab 6) # [bc]bg cyan[/bc] | |
| local bgwhite=$(tput setab 7) # [bw]bg white[/bw] | |
| # styles | |
| local start_stand_out=$(tput smso) # [o] | |
| local start_under=$(tput smul) # [_][/_] | |
| local start_bold=$(tput bold) # [*][/*] | |
| # [*][/] | |
| # not implemented | |
| # rev Start reverse video | |
| # blink Start blinking text | |
| # invis Start invisible text | |
| # phrase replacement | |
| local phrase=$(echo "${1}" | | |
| sed -e "s/\[o\]/\\${start_stand_out}/g" | sed -e "s/\[\/o\]/\\${reset_stand_out}/g" | | |
| sed -e "s/\[\*\]/\\${start_bold}/g" | sed -e "s/\[\/\*\]/\\${reset_all}/g" | | |
| sed -e "s/\[_\]/\\${start_under}/g" | sed -e "s/\[\/_\]/\\${reset_underline}/g" | | |
| sed -e "s/\[d\]/\\${black}/g" | sed -e "s/\[\/d\]/\\${reset_color}/g" | | |
| sed -e "s/\[r\]/\\${red}/g" | sed -e "s/\[\/r\]/\\${reset_color}/g" | | |
| sed -e "s/\[g\]/\\${green}/g" | sed -e "s/\[\/g\]/\\${reset_color}/g" | | |
| sed -e "s/\[y\]/\\${yellow}/g" | sed -e "s/\[\/y\]/\\${reset_color}/g" | | |
| sed -e "s/\[b\]/\\${blue}/g" | sed -e "s/\[\/b\]/\\${reset_color}/g" | | |
| sed -e "s/\[m\]/\\${magenta}/g" | sed -e "s/\[\/m\]/\\${reset_color}/g" | | |
| sed -e "s/\[c\]/\\${cyan}/g" | sed -e "s/\[\/c\]/\\${reset_color}/g" | | |
| sed -e "s/\[w\]/\\${white}/g" | sed -e "s/\[\/w\]/\\${reset_color}/g" | | |
| sed -e "s/\[bd\]/\\${bgblack}/g" | sed -e "s/\[\/bd\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[br\]/\\${bgred}/g" | sed -e "s/\[\/br\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[bg\]/\\${bggreen}/g" | sed -e "s/\[\/bg\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[by\]/\\${bgyellow}/g" | sed -e "s/\[\/by\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[bb\]/\\${bgblue}/g" | sed -e "s/\[\/bb\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[bm\]/\\${bgmagenta}/g" | sed -e "s/\[\/bm\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[bc\]/\\${bgcyan}/g" | sed -e "s/\[\/bc\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[bw\]/\\${bgwhite}/g" | sed -e "s/\[\/bw\]/\\${reset_bgcolor}/g" | | |
| sed -e "s/\[\/\]/\\${reset_all}/g" | |
| ) | |
| echo -e "${phrase}${reset_all}" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment