cecho
"/home/yossef/notes/git/scripts/cecho.md"
path: git/scripts/cecho.md
- **fileName**: cecho
- **Created on**: 2025-03-26 14:07:45
#!/usr/bin/env bash
# Define color variables
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
BLUE='\e[34m'
RESET='\e[0m'
# cecho function:
# It takes a message (which can have spaces) and a color (optional,
# defaults to reset).
cecho() {
local message
local color
local color_code
# Check if the last argument is a recognized color
case "${!#}" in
red|green|yellow|blue)
color="${!#}"
message="${@:1:$#-1}"
;;
*)
color="reset" # Default color if none provided
message="$*" # Take all arguments as message
;;
esac
# Map the color to its corresponding code
case "$color" in
red) color_code="$RED" ;;
green) color_code="$GREEN" ;;
yellow) color_code="$YELLOW" ;;
blue) color_code="$BLUE" ;;
*) color_code="$RESET" ;; # Default to no color if unrecognized
esac
# Print the message prefixed with "==>" in the selected color, then reset
printf "${color_code}==> %s${RESET}\n" "$message <=="
}
cecho $1 $2
continue:./cpkm.md
before:./_commend_exists.md