Last active
November 28, 2022 20:19
-
-
Save gbroques/453107c123265d2b608790c6966a912c to your computer and use it in GitHub Desktop.
RGB Colors in Bash
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
#!/bin/bash | |
# https://en.wikipedia.org/wiki/ANSI_escape_code#Colors | |
# Control Sequence Introducer | |
# https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences | |
function csi() { | |
ESC="\033" | |
parameters=$(echo $@ | sed -e 's/ /;/g') | |
echo "$ESC[${parameters}m" | |
} | |
function text_effect() { | |
RESET="0" | |
first_arg=$(echo "$@" | cut -d ' ' -f 1) | |
rest_of_args=$(echo "$@" | cut -d ' ' -f 2-) | |
echo "$(csi $rest_of_args)$first_arg$(csi $RESET)" | |
} | |
function red() { | |
RED_FG="31" | |
echo -e $(text_effect $1 $RED_FG) | |
} | |
function green() { | |
GREEN_FG="32" | |
echo -e $(text_effect $1 $GREEN_FG) | |
} | |
function blue() { | |
BLUE_FG="34" | |
echo -e $(text_effect $1 $BLUE_FG) | |
} | |
red $1 | |
green $1 | |
blue $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment