feat: implement colored logging functions for improved visibility and formatting
Some checks failed
Nix Format Check / check-format (push) Has been cancelled
Some checks failed
Nix Format Check / check-format (push) Has been cancelled
This commit is contained in:
parent
52aaa71f84
commit
620abb2ffe
90
setup.sh
90
setup.sh
@ -9,27 +9,99 @@ readonly GIT_REPO="https://git.mvl.sh/vleeuwenmenno/dotfiles.git" # Dotfiles r
|
||||
readonly DOTFILES_PATH="${HOME}/.dotfiles" # Dotfiles directory
|
||||
readonly SETUP_MARKER="${HOME}/.dotfiles-setup" # Setup marker file indicates setup has been run
|
||||
|
||||
# Color constants
|
||||
readonly RED='\033[0;31m'
|
||||
readonly GREEN='\033[0;32m'
|
||||
readonly YELLOW='\033[0;33m'
|
||||
readonly NC='\033[0m' # No Color
|
||||
#Color print function, usage: println "message" "color"
|
||||
println() {
|
||||
color=$2
|
||||
printfe "%s\n" $color "$1"
|
||||
}
|
||||
|
||||
# print colored with printf (args: format, color, message ...)
|
||||
printfe() {
|
||||
format=$1
|
||||
color=$2
|
||||
message=$3
|
||||
show_time=true
|
||||
|
||||
# Check if $4 is explicitly set to false, otherwise default to true
|
||||
if [ ! -z "$4" ] && [ "$4" == "false" ]; then
|
||||
show_time=false
|
||||
fi
|
||||
|
||||
red=$(tput setaf 1)
|
||||
green=$(tput setaf 2)
|
||||
yellow=$(tput setaf 3)
|
||||
blue=$(tput setaf 4)
|
||||
magenta=$(tput setaf 5)
|
||||
cyan=$(tput setaf 6)
|
||||
normal=$(tput sgr0)
|
||||
grey=$(tput setaf 8)
|
||||
|
||||
case $color in
|
||||
"red")
|
||||
color=$red
|
||||
;;
|
||||
"green")
|
||||
color=$green
|
||||
;;
|
||||
"yellow")
|
||||
color=$yellow
|
||||
;;
|
||||
"blue")
|
||||
color=$blue
|
||||
;;
|
||||
"magenta")
|
||||
color=$magenta
|
||||
;;
|
||||
"cyan")
|
||||
color=$cyan
|
||||
;;
|
||||
"grey")
|
||||
color=$grey
|
||||
;;
|
||||
*)
|
||||
color=$normal
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$show_time" == "false" ]; then
|
||||
printf "$color$format$normal" "$message"
|
||||
return
|
||||
fi
|
||||
|
||||
printf $grey"%s" "$(date +'%H:%M:%S')"$normal
|
||||
|
||||
case $color in
|
||||
$green | $cyan | $blue | $magenta | $normal)
|
||||
printf "$green INF $normal"
|
||||
;;
|
||||
$yellow)
|
||||
printf "$yellow WRN $normal"
|
||||
;;
|
||||
$red)
|
||||
printf "$red ERR $normal"
|
||||
;;
|
||||
*)
|
||||
printf "$normal"
|
||||
;;
|
||||
esac
|
||||
printf "$color$format$normal" "$message"
|
||||
}
|
||||
|
||||
# Helper functions
|
||||
log_info() {
|
||||
echo -e "${YELLOW}$1${NC}"
|
||||
println "$1" "green"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}$1${NC}"
|
||||
println "$1" "green"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}$1${NC}" >&2
|
||||
println "$1" "red" >&2
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}$1${NC}" >&2
|
||||
println "$1" "yellow" >&2
|
||||
}
|
||||
|
||||
die() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user