Skip to content

Instantly share code, notes, and snippets.

@gregohardy
Last active September 3, 2023 00:52
Show Gist options
  • Save gregohardy/d148db9e01aa721ea42daf4abbba725e to your computer and use it in GitHub Desktop.
Save gregohardy/d148db9e01aa721ea42daf4abbba725e to your computer and use it in GitHub Desktop.
Bash colours/italics/bold for echo. (works in macos)
#/bin/bash
function bold()
{
echo "\033[1m${1}\033[22m"
}
function dim()
{
echo "\033[2m${1}\033[22m"
}
function italic()
{
echo "\033[3m${1}\033[23m"
}
function underline()
{
echo "\033[4m${1}\033[24m"
}
function red()
{
echo "\033[31m${1}\033[39m"
}
function green()
{
echo "\033[32m${1}\033[39m"
}
function yellow()
{
echo "\033[33m${1}\033[39m"
}
function blue()
{
echo "\033[35m${1}\033[39m"
}
function purple()
{
echo "\033[35m${1}\033[39m"
}
function aqua()
{
echo "\033[36m${1}\033[39m"
}
function brightred()
{
echo "\033[91m${1}\033[39m"
}
bold "bold"
dim "dim"
italic "italic"
underline "underline"
red "red"
brightred "brightred"
green "green"
yellow "yellow"
blue "blue"
aqua "aqua"
#/bin/bash
echo '\033[1mYOUR_STRING\033[0m'
echo '\033[1mbold\033[22m'
echo '\033[2mdim\033[22m'
echo '\033[3mitalic\033[23m'
echo '\033[4munderline\033[24m'
echo '\033[31mred\033[39m'
echo '\033[32mgreen\033[39m'
echo '\033[33myellow\033[39m'
echo '\033[34mblue\033[39m'
echo '\033[35mpurple\033[39m'
echo '\033[36maqua\033[39m'
echo '\033[37mwhite\033[39m'
echo '\033[4:1mthis is also underline (new in 0.52)\033[4:0m'
echo '\033[21mdouble underline (new in 0.52)\033[24m'
echo '\033[4:2mthis is also double underline (new in 0.52)\033[4:0m'
echo '\033[4:3mcurly underline (new in 0.52)\033[4:0m'
echo '\033[5mblink (new in 0.52)\033[25m'
echo '\033[7mreverse\033[27m'
echo '\033[8minvisible\033[28m <- invisible (but copy-pasteable)'
echo '\033[9mstrikethrough\033[29m'
echo '\033[53moverline (new in 0.52)\033[55m'
echo '\033[31mred\033[39m'
echo '\033[91mbright red\033[39m'
echo '\033[38:5:42m256-color, de jure standard (ITU-T T.416)\033[39m'
echo '\033[38;5;42m256-color, de facto standard (commonly used)\033[39m'
echo '\033[38:2::240:143:104mtruecolor, de jure standard (ITU-T T.416) (new in 0.52)\033[39m'
echo '\033[38:2:240:143:104mtruecolor, rarely used incorrect format (might be removed at some point)\033[39m'
echo '\033[38;2;240;143;104mtruecolor, de facto standard (commonly used)\033[39m'
echo '\033[46mcyan background\033[49m'
echo '\033[106mbright cyan background\033[49m'
echo '\033[48:5:42m256-color background, de jure standard (ITU-T T.416)\033[49m'
echo '\033[48;5;42m256-color background, de facto standard (commonly used)\033[49m'
echo '\033[48:2::240:143:104mtruecolor background, de jure standard (ITU-T T.416) (new in 0.52)\033[49m'
echo '\033[48:2:240:143:104mtruecolor background, rarely used incorrect format (might be removed at some point)\033[49m'
echo '\033[48;2;240;143;104mtruecolor background, de facto standard (commonly used)\033[49m'
echo '\033[21m\033[58:5:42m256-color underline (new in 0.52)\033[59m\033[24m'
echo '\033[21m\033[58;5;42m256-color underline (new in 0.52)\033[59m\033[24m'
echo '\033[4:3m\033[58:2::240:143:104mtruecolor underline (new in 0.52) (*)\033[59m\033[4:0m'
echo '\033[4:3m\033[58:2:240:143:104mtruecolor underline (new in 0.52) (might be removed at some point) (*)\033[59m\033[4:0m'
echo '\033[4:3m\033[58;2;240;143;104mtruecolor underline (new in 0.52) (*)\033[59m\033[4:0m'
@itay-moav
Copy link

Shouldn't u add -e to echo?
echo -e '....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment