Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # ANSI color table that relates to RGB (NOT true RGB)
- # Haters gonna hate
- # Written by Robert J.
- # _/ _/ _/ _/ _/
- # _/_/_/_/_/ _/ _/_/_/ _/_/_/ _/_/_/ _/_/_/
- # _/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/
- # _/_/_/_/_/ _/ _/ _/ _/ _/_/ _/ _/
- # _/ _/ _/ _/_/_/ _/_/_/ _/_/_/ _/ _/
- # Display help
- [[ $1 = "--help" ]] && {
- printf "\n"
- printf "\tansi-color --table : Outputs table of 216 escaped colors with approx RGB\n"
- printf "\tansi-color -RGB RED GREEN BLUE {0-255} : Closest ANSI color with escape code\n"
- printf "\n"
- exit
- }
- [[ $1 = "--table" ]] && {
- # Set variables to 0
- r=0
- g=0
- b=0
- # Initiate while loop
- while : ;
- do
- # Starting with red (RGB)
- for ((r=0;r<6;r++));
- do
- # Perform color calculations
- color=$((16+36*r+6*g+b));
- # Print Color with RGB structure tabbing at the completion
- printf "\033[38;5; %s m$r,$g,$b;\033[0;00m color code: %s \t" "$color" "$color";
- done;
- # perform a line return after the first set of red is completed
- printf "\n"
- # Increase blue by one incriment
- ((b++)) && {
- # Reset bule to zero if it equals 6
- [[ $b = 6 ]] && b=0 && {
- # Increase green by one incriment until it equals 6 at which point,
- # break the while loop
- ((g++)) && [[ $g = 6 ]] && break;
- }
- }
- done;
- exit;
- }
- # Error Checking
- [[ $# != 4 ]] && {
- printf "Syntax Error: Missing Operator see:\n\tansi-color --help\n"
- exit
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement