Skip to content

Instantly share code, notes, and snippets.

@micalevisk
Last active December 26, 2021 17:44
Show Gist options
  • Save micalevisk/a1eeb59dff4b3490a3dff37649170c6f to your computer and use it in GitHub Desktop.
Save micalevisk/a1eeb59dff4b3490a3dff37649170c6f to your computer and use it in GitHub Desktop.
Minimal bash script to convert RGB to 256 terminal color wisely.
#!/bin/bash
## convert RGB to 256 terminal color
rgb="${1//[!0-9,]/}" # 0..255,0..255,0..255
echo -n "\e[0;38;2;${rgb//,/;}m"
@micalevisk
Copy link
Author

micalevisk commented Dec 26, 2017

testing

➜ sh from_hex_to_256.bash 255, 100, 104
\e[0;38;2;255;100;104m
➜ sh from_hex_to_256.bash "rgb(255, 100, 104)"
\e[0;38;2;255;100;104m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment