Skip to content

Instantly share code, notes, and snippets.

@neuralpain
Last active February 8, 2024 01:27
Show Gist options
  • Save neuralpain/f27ff19311ed0466feac46fa721dd391 to your computer and use it in GitHub Desktop.
Save neuralpain/f27ff19311ed0466feac46fa721dd391 to your computer and use it in GitHub Desktop.
Predefined functions for displaying colored CLI messages based on type, i.e., success, error and information
# extracted from: https://bun.sh/install
# https://github.com/oven-sh/bun
# Reset
Color_Off=''
# Regular Colors
Red=''
Green=''
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
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}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment