Skip to content

Instantly share code, notes, and snippets.

@afruzan
Created September 5, 2024 18:32
Show Gist options
  • Save afruzan/4ed5c6b9bd6474ba34c8b676a4446f45 to your computer and use it in GitHub Desktop.
Save afruzan/4ed5c6b9bd6474ba34c8b676a4446f45 to your computer and use it in GitHub Desktop.
#!/bin/bash
cecho(){
RED="\033[1;31m" # <-- [1 means bold, [0 means not bold
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
CYAN="\033[1;36m"
RED_BACK="\033[7;31m"
GREEN_BACK="\033[7;32m"
YELLOW_BACK="\033[7;33m"
CYAN_BACK="\033[7;36m"
# ... Add more colors if you like
NC="\033[0m" # No Color
# printf "${(P)1}${2} ${NC}\n" # <-- zsh
printf "${!1}${2} ${NC}\n" # <-- bash
}
cecho YELLOW "fore yellow"
cecho CYAN_BACK "back cyan"
call :cecho CW "back Bright-Cyan fore Bright-White"
call :cecho cy "back Cyan fore yellow"
call :cecho w0 "back White fore black"
call :cecho rb "back Red fore Blue"
goto :eof
:: Colorized ECHO
:cecho
@echo off
IF [%ESC%] == [] for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
SET color=0%1
IF [%color%] == [0] SET color=07
SET fore=%color:~-1%
SET back=%color:~-2,1%
if %fore% == 0 SET color=%ESC%[30
if /i %fore% == b SET color=%ESC%[34
if /i %fore% == g SET color=%ESC%[32
if /i %fore% == c SET color=%ESC%[36
if /i %fore% == r SET color=%ESC%[31
if /i %fore% == p SET color=%ESC%[35
if /i %fore% == y SET color=%ESC%[33
if /i %fore% == w SET color=%ESC%[37
if /i %fore% == G SET color=%ESC%[90
if /i %fore% == B SET color=%ESC%[94
if /i %fore% == G SET color=%ESC%[92
if /i %fore% == C SET color=%ESC%[96
if /i %fore% == R SET color=%ESC%[91
if /i %fore% == P SET color=%ESC%[95
if /i %fore% == Y SET color=%ESC%[93
if /i %fore% == W SET color=%ESC%[97
if %back% == 0 SET color=%color%;40
if /i %back% == b SET color=%color%;44
if /i %back% == g SET color=%color%;42
if /i %back% == c SET color=%color%;46
if /i %back% == r SET color=%color%;41
if /i %back% == p SET color=%color%;45
if /i %back% == y SET color=%color%;43
if /i %back% == w SET color=%color%;47
if /i %back% == G SET color=%color%;100
if /i %back% == B SET color=%color%;104
if /i %back% == G SET color=%color%;102
if /i %back% == C SET color=%color%;106
if /i %back% == R SET color=%color%;101
if /i %back% == P SET color=%color%;105
if /i %back% == Y SET color=%color%;103
if /i %back% == W SET color=%color%;107
SET color=%color%m
echo %color%%~2%ESC%[0m
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment