Skip to content

Instantly share code, notes, and snippets.

@moontan
Last active August 1, 2020 08:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moontan/1a91b5a7de9c6247d5ca to your computer and use it in GitHub Desktop.
Save moontan/1a91b5a7de9c6247d5ca to your computer and use it in GitHub Desktop.
bash script ANSI sequences
#!/bin/bash
# use the following variables as in
# echo -e "[$TYPE…][$FG…][$BG…]formatted text[$TYPERSALL]"
# to set colours and other formatting
# 8<-------------------- ANSI-Sequences ------------------------
# (remove this paragraph if you prefer things plain and simple)
# --------------------------------------------------------------
# Type:
TYPERSALL="\x1B[0m" # reset all properties
TYPEBOLD="\x1B[1m" # bold type on
TYPENOBOLD="\x1B[22m" # no bold type
TYPEULINE="\x1B[4m" # underlined type on
TYPENOULINE="\x1B[24m" # no underlined type
TYPEBLINK="\x1B[5m" # blinking type on
TYPENOBLINK="\x1B[25m" # no blinking type
TYPEINVERT="\x1B[7m" # fg/bg inverse type on
TYPENOINVERT="\x1B[27m" # no fg/bg inverse type
TYPEHIDE="\x1B[8m" # concealed type on
TYPENOHIDE="\x1B[8m" # no concealed type
# Foreground Colour (normal/intense):
FGBLK="\x1B[30m" # black
FGIBLK="\x1B[90m" # intense black
FGRED="\x1B[31m" # red
FGIRED="\x1B[91m" # intense red
FGGRN="\x1B[32m" # green
FGIGRN="\x1B[92m" # intese green
FGYLW="\x1B[33m" # yellow
FGIYLW="\x1B[93m" # intense yellow
FGBLU="\x1B[34m" # blue
FGIBLU="\x1B[94m" # intense blue
FGMGT="\x1B[35m" # magenta
FGIMGT="\x1B[95m" # intense magenta
FGCYN="\x1B[36m" # cyan
FGICYN="\x1B[96m" # intense cyan
FGWHT="\x1B[37m" # white
FGIWHT="\x1B[97m" # intense white
FGDEFAULT="\x1B[39m" # default foreground colour
# Background Colour (normal/intense):
BGBLK="\x1B[40m" # black
BGIBLK="\x1B[100m" # intense black
BGRED="\x1B[41m" # red
BGIRED="\x1B[101m" # intense red
BGGRN="\x1B[42m" # green
BGIGRN="\x1B[102m" # intense green
BGYLW="\x1B[43m" # yellow
BGIYLW="\x1B[103m" # intense yellow
BGBLU="\x1B[44m" # blue
BGIBLU="\x1B[104m" # intense blue
BGMGT="\x1B[45m" # magenta
BGIMGT="\x1B[105m" # intense magenta
BGCYN="\x1B[46m" # cyan
BGICYN="\x1B[106m" # intense cyan
BGWHT="\x1B[47m" # white
BGIWHT="\x1B[107m" # intense white
BGDEFAULT="\x1B[49m" # default background colour
# Custom Foreground and Background Colour Palette (0~255)
for PAL in {0..255}
do
FGCSTM[$PAL]="\x1B[38;5;"$PAL"m"
BGCSTM[$PAL]="\x1B[48;5;"$PAL"m"
done
# 8<------------------ END ANSI-Sequences ----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment