Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #!/bin/bash
  2. # ANSI color table that relates to RGB (NOT true RGB)
  3. # Haters gonna hate
  4. # Written by Robert J.
  5.  
  6. # _/ _/ _/ _/ _/
  7. # _/_/_/_/_/ _/ _/_/_/ _/_/_/ _/_/_/ _/_/_/
  8. # _/ _/ _/ _/ _/ _/ _/ _/_/ _/ _/
  9. # _/_/_/_/_/ _/ _/ _/ _/ _/_/ _/ _/
  10. # _/ _/ _/ _/_/_/ _/_/_/ _/_/_/ _/ _/
  11.  
  12. # Display help
  13. [[ $1 = "--help" ]] && {
  14. printf "\n"
  15. printf "\tansi-color --table : Outputs table of 216 escaped colors with approx RGB\n"
  16. printf "\tansi-color -RGB RED GREEN BLUE {0-255} : Closest ANSI color with escape code\n"
  17. printf "\n"
  18. exit
  19. }
  20.  
  21. [[ $1 = "--table" ]] && {
  22. # Set variables to 0
  23. r=0
  24. g=0
  25. b=0
  26.  
  27. # Initiate while loop
  28. while : ;
  29. do
  30. # Starting with red (RGB)
  31. for ((r=0;r<6;r++));
  32. do
  33. # Perform color calculations
  34. color=$((16+36*r+6*g+b));
  35. # Print Color with RGB structure tabbing at the completion
  36. printf "\033[38;5; %s m$r,$g,$b;\033[0;00m color code: %s \t" "$color" "$color";
  37. done;
  38. # perform a line return after the first set of red is completed
  39. printf "\n"
  40. # Increase blue by one incriment
  41. ((b++)) && {
  42. # Reset bule to zero if it equals 6
  43. [[ $b = 6 ]] && b=0 && {
  44. # Increase green by one incriment until it equals 6 at which point,
  45. # break the while loop
  46. ((g++)) && [[ $g = 6 ]] && break;
  47. }
  48. }
  49. done;
  50. exit;
  51. }
  52.  
  53. # Error Checking
  54. [[ $# != 4 ]] && {
  55. printf "Syntax Error: Missing Operator see:\n\tansi-color --help\n"
  56. exit
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement