Skip to content

Instantly share code, notes, and snippets.

@KunalSin9h
Created August 29, 2022 07:53
Show Gist options
  • Save KunalSin9h/cd2ac276ddbb2131287b8ec2f426e618 to your computer and use it in GitHub Desktop.
Save KunalSin9h/cd2ac276ddbb2131287b8ec2f426e618 to your computer and use it in GitHub Desktop.
This is colour output snippet for shell script.
#!/bin/bash
# Reset
Color_Off=''
# Regular Colors
Red=''
Green=''
Yellow=''
Cyan=''
Magenta=''
Dim='' # White
# Bold
Bold_White=''
Bold_Green=''
if [[ -t 1 ]]; then
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[1;33m' # Yellow
Cyan='\033[0;36m'
Magenta='\033[1;35m'
Dim='\033[0;2m' # White
# Bold
Bold_Green='\033[1;32m' # Bold Green
Bold_White='\033[1m' # Bold White
fi
error() {
echo -e "${Red}error${Color_Off}:" "$@" >&2
exit 1
}
info() {
echo -e "${Dim}$@ ${Color_Off}"
}
info_bold() {
echo -e "${Bold_White}$@ ${Color_Off}"
}
success() {
echo -e "${Green}$@ ${Color_Off}"
}
bold_success() {
echo -e "${Bold_Green}$@ ${Color_Off}"
}
intro() {
echo -e "${Yellow}$@ ${Color_Off}"
}
@KunalSin9h
Copy link
Author

more example

# Reset
Color_Off=''

# Regular Colors
Red=''
Green=''
Yellow=''
Dim='' # White

if [[ -t 1 ]]; then
    # Reset
    Color_Off='\033[0m' # Text Reset

    # Regular Colors
    Red='\033[1;31m'   # Red
    Green='\033[1;32m' # Green
    Yellow='\033[1;33m' # Yellow
    Dim='\033[1;2m'    # White
fi


status() { echo -e "${Dim}INFO   ${Color_Off}: $*" >&2; }
success() { echo -e "${Green}SUCCESS${Color_Off}: $*"; }
error() { echo -e "${Red}ERROR${Color_Off}  : $*"; exit 1; }
warning() { echo -e "${Yellow}WARNING${Color_Off}: $*"; }

status 'Ths is status' 
success 'MeltCD installed'
warning 'This is warning'
error 'This is error'

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