Created
July 18, 2016 11:56
-
-
Save cmd-johnson/2ef76363313b77668cf702aced471181 to your computer and use it in GitHub Desktop.
Bash RGB
This file contains 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
#!/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