Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cmd-johnson/2ef76363313b77668cf702aced471181 to your computer and use it in GitHub Desktop.
Save cmd-johnson/2ef76363313b77668cf702aced471181 to your computer and use it in GitHub Desktop.
Bash RGB
#!/usr/env/bash
rgb()
{
# takes three values for red, green and blue ranging from
# 0-5 each and prints the corresponding color escape sequence
# (formula from http://stackoverflow.com/a/27165165)
local r="${1:-"0"}"
local g="${2:-"0"}"
local b="${3:-"0"}"
value=$((16 + 36 * $r + 6 * $g + $b))
echo -e "\e[38;5;"$value"m"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment