Skip to content

Instantly share code, notes, and snippets.

@sovrinbloc
Created August 5, 2022 23:44
Show Gist options
  • Save sovrinbloc/7bc8179cbb59362045da5bf2f0aafed8 to your computer and use it in GitHub Desktop.
Save sovrinbloc/7bc8179cbb59362045da5bf2f0aafed8 to your computer and use it in GitHub Desktop.
All Bash Color scheme variables and styles for iTerm/Bash Scripts, along with demonstration of usage.
#!/usr/bin/env bash
###############################################################################
# Joseph Alai. 2022/08/05
###############################################################################
# Color schemes for iTerm/Bash Scripts along with demonstration of usage.
###############################################################################
SCRIPT_NAME="Colors"
RED='\033[0;31m'
NC='\033[0m' # No Color
BLACK='\033[0;30m'
DARK_GRAY='\033[1;30m'
RED='\033[0;31m'
LIGHT_RED='\033[1;31m'
GREEN='\033[0;32m'
LIGHT_GREEN='\033[1;32m'
ORANGE='\033[0;33m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
LIGHT_BLUE='\033[1;34m'
PURPLE='\033[0;35m'
LIGHT_PURPLE='\033[1;35m'
CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
LIGHT_GRAY='\033[0;37m'
WHITE='\033[1;37m'
BLINK="$(tput blink)"
BOLD="$(tput bold)"
UNDERLINE="$(tput smul)"
NORMAL="$(tput sgr0)${NC}"
REVERSE="$(tput rev)"
function black() {
INPUT=${1:-}
printf "$BLACK%s$NC" "$INPUT"
}
function dark_gray() {
INPUT=${1:-}
printf "$DARK_GRAY%s$NC" "$INPUT"
}
function red() {
INPUT=${1:-}
printf "$RED%s$NC" "$INPUT"
}
function light_red() {
INPUT=${1:-}
printf "$LIGHT_RED%s$NC" "$INPUT"
}
function green() {
INPUT=${1:-}
printf "$GREEN%s$NC" "$INPUT"
}
function light_green() {
INPUT=${1:-}
printf "$LIGHT_GREEN%s$NC" "$INPUT"
}
function orange() {
INPUT=${1:-}
printf "$ORANGE%s$NC" "$INPUT"
}
function yellow() {
INPUT=${1:-}
printf "$YELLOW%s$NC" "$INPUT"
}
function blue() {
INPUT=${1:-}
printf "$BLUE%s$NC" "$INPUT"
}
function light_blue() {
INPUT=${1:-}
printf "$LIGHT_BLUE%s$NC" "$INPUT"
}
function purple() {
INPUT=${1:-}
printf "$PURPLE%s$NC" "$INPUT"
}
function light_purple() {
INPUT=${1:-}
printf "$LIGHT_PURPLE%s$NC" "$INPUT"
}
function cyan() {
INPUT=${1:-}
printf "$CYAN%s$NC" "$INPUT"
}
function light_cyan() {
INPUT=${1:-}
printf "$LIGHT_CYAN%s$NC" "$INPUT"
}
function light_gray() {
INPUT=${1:-}
printf "$LIGHT_GRAY%s$NC" "$INPUT"
}
function white() {
INPUT=${1:-}
printf "$WHITE%s$NC" "$INPUT"
}
function bold() {
INPUT=${1:-}
bold=$(tput bold)
normal=$(tput sgr0)
print "${bold}$INPUT${normal}\n"
}
function underlined() {
INPUT=${1:-}
ul=$(tput smul)
normal=$(tput rmul)
print "${ul}$INPUT${normal}\n"
}
function blink() {
INPUT=${1:-}
blink=$(tput blink)
normal=$(tput sgr0)
print "${blink}$INPUT${normal}\n"
}
function reset() {
tput sgr0
tput rmul
printf "${NC}"
}
function normal() {
reset
INPUT=${1:-}
echo $INPUT
}
function reverse() {
INPUT=${1:-}
rev=$(tput rev)
print "${rev}$INPUT$(reset)\n"
}
function colors::print_color_rows() {
for((i=16; i<256; i++)); do
printf "\e[48;5;${i}m%03d" $i;
printf '\e[0m';
if [ ! $((($i - 15) % 6)) -eq 0 ]; then
printf ' '
else
printf '\n'
fi
done
}
###############################################################################
# colors::styles - Prints out all the available styles.
function colors::styles() {
# STYLES
printf "\e[31;107;1;4;7m\tSet/Reset\e[5m.\e[25;39;49;0m\n"
printf "0: \e[0mReset/remove all modifier, foreground and background attributes: \e[0mNormal Text\n"
printf "1: \e[1mBold/Bright: \e[0mNormal Text\n"
printf "2: \e[2mDim: \e[0mNormal Text\n"
printf "4: \e[4mUnderlined: \e[0mNormal Text\n"
printf "5: \e[5mBlink (doesn't work in most terminals except XTerm): \e[0mNormal Text\n"
printf "7: \e[7mReverse/Invert: \e[0mNormal Text\n"
printf "8: \e[8mHidden (useful for sensitive info): \e[0mNormal Text\n"
printf "21: \e[21mReset/Remove bold/bright: \e[0mNormal Text\n"
printf "22: \e[22mReset/Remove dim: \e[0mNormal Text\n"
printf "24: \e[24mReset/Remove underline: \e[0mNormal Text\n"
printf "25: \e[25mReset/Remove blink: \e[0mNormal Text\n"
printf "27: \e[27mReset/Remove reverse/invert: \e[0mNormal Text\n"
printf "28: \e[28mReset/Remove hidden: \e[0mNormal Text\n"
# FOREGROUND
printf "\e[31mF\e[32mo\e[33mr\e[34me\e[35mg\e[36mr\e[37mo\e[90mu\e[91mn\e[92md\e[39m\n"
printf "39: \e[39mDefault (usually green, white or light gray): Default \e[39mDefault\n";
printf "30: Default \e[30mBlack (best combined with a background colour: Default \e[30;107mBlack on white\e[39;49m\n"
printf "31: \e[31mRed (don't use with green background) \e[39mNormal Text\n\e[39;49m"
printf "32: \e[32mGreen \e[39mNormal Text\n\e[39;49m"
printf "33: \e[33mYellow \e[39mNormal Text\n\e[39;49m"
printf "34: \e[34mBlue \e[39mNormal Text\n\e[39;49m"
printf "35: \e[35mMagenta/Purple \e[39mNormal Text\n\e[39;49m"
printf "36: \e[36mCyan \e[39mNormal Text\n\e[39;49m"
printf "37: \e[37mLight Gray \e[39mNormal Text\n\e[39;49m"
printf "90: \e[90mDark Gray \e[39mNormal Text\n\e[39;49m"
printf "91: \e[91mLight Red \e[39mNormal Text\n\e[39;49m"
printf "92: \e[92mLight Green \e[39mNormal Text\n\e[39;49m"
printf "93: \e[93mLight Yellow \e[39mNormal Text\n\e[39;49m"
printf "94: \e[94mLight Blue \e[39mNormal Text\n\e[39;49m"
printf "95: \e[95mLight Magenta/Pink \e[39mNormal Text\n\e[39;49m"
printf "96: \e[96mLight Cyan \e[39mNormal Text\n\e[39;49m"
printf "97: \e[97mWhite \e[39mNormal Text\n\e[39;49m"
# BACKGROUND
printf "\e[102;90m B \e[41m a \e[42m c \e[43m k \e[44m g \e[45m r \e[46m o \e[47m u \e[100;31m n \e[101;32m d \e[39;49m\n"
printf "49: \e[49mDefault background color (usually black or blue) \e[49mNormal Background\n\e[39;49m"
printf "40: \e[40mBlack \e[49mNormal Background\n\e[39;49m"
printf "41: \e[41mRed \e[49mNormal Background\n\e[39;49m"
printf "42: \e[42mGreen \e[49mNormal Background\n\e[39;49m"
printf "43: \e[43mYellow \e[49mNormal Background\n\e[39;49m"
printf "44: \e[44mBlue \e[49mNormal Background\n\e[39;49m"
printf "45: \e[45mMagenta/Purple \e[49mNormal Background\n\e[39;49m"
printf "46: \e[46mCyan \e[49mNormal Background\n\e[39;49m"
printf "47: \e[47;5;34mLight Gray (don't use with white foreground) \e[39;49;25mNormal Background\n\e[39;49m"
printf "100: \e[100mDark Gray (don't use with black foreground) \e[49mNormal Background\n\e[39;49m"
printf "101: \e[101mLight Red \e[49mNormal Background\n\e[39;49m"
printf "102: \e[102mLight Green (don't use with white foreground) \e[49mNormal Background\n\e[39;49m"
printf "103: \e[103mLight Yellow (don't use with white foreground) \e[49mNormal Background\n\e[39;49m"
printf "104: \e[104mLight Blue (don't use with light yellow foreground) \e[49mNormal Background\n\e[39;49m"
printf "105: \e[105mLight Magenta/Pink (don't use with light foreground) \e[49mNormal Background\n\e[39;49m"
printf "106: \e[106mLight Cyan (don't use with white foreground) \e[49mNormal Background\n\e[39;49m"
printf "107: \e[107;5;34;mWhite (don't use with light foreground) \e[25;49;39mNormal Background\n\e[39;49m"
}
colors::styles
colors::print_color_rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment