Skip to content

Instantly share code, notes, and snippets.

@nberlette
Created April 27, 2021 07:14
Show Gist options
  • Save nberlette/b5ecf3d74d11c777d50128d38a6bfd3a to your computer and use it in GitHub Desktop.
Save nberlette/b5ecf3d74d11c777d50128d38a6bfd3a to your computer and use it in GitHub Desktop.
#!/bin/bash
# hex2bash.sh
# rudamentary bash function to format hex colors into RGB form
# and output them as xterm-256color esc-code, with samples :D
# 2021 Nick Berlette
# https://github.com/nberlette
function hex2bash {
local hex=${1/'#'/''}
local rgb=$(printf "%d;%d;%d" 0x${hex:0:2} 0x${hex:2:2} 0x${hex:4:2})
echo -e "\e[38;2;${rgb}m \\\e[38;2;${rgb}m \e[0m \b\e[48;2;${rgb};38;2;0;0;0m \\\e[48;2;${rgb}m \e[0m\n"
}
# Usage:
hex2bash "$1"
@nberlette
Copy link
Author

hex2bash

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