diff --git a/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg b/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg index 847d5ccb..5d809e65 100644 --- a/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg +++ b/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg @@ -113,57 +113,6 @@ formatFaint() { echo -e "$ANSI_STR_FORMATTED" } -# @description Logs using Node.js -# @example logger info "An informative log" -logg() { - if echo "$0" | grep -Eq "log.$"; then - TYPE="$1" - MSG="$2" - else - TYPE="$0" - MSG="$1" - fi - if [ "$TYPE" == 'error' ]; then - "$GUM_PATH" style --border="thick" "$("$GUM_PATH" style --foreground="#ff0000" "✖") $("$GUM_PATH" style --bold --background="#ff0000" --foreground="#ffffff" " ERROR ") $("$GUM_PATH" style --bold "$(format "$MSG")")" - elif [ "$TYPE" == 'info' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ffff" "○") $MSG" - elif [ "$TYPE" == 'md' ]; then - # @description Ensure glow is installed - if [ "${container:=}" != 'docker' ]; then - if type glow &> /dev/null; then - GLOW_PATH="$(which glow)" - elif [ -f "$HOME/.local/bin/glow" ]; then - GLOW_PATH="$HOME/.local/bin/glow" - elif [ -f "$(dirname "${BASH_SOURCE[0]}")/glow" ]; then - GLOW_PATH="$(dirname "${BASH_SOURCE[0]}")/glow" - elif type brew &> /dev/null; then - brew install glow - GLOW_PATH="$(which glow)" - else - installGlow - fi - - if [ -n "$GLOW_PATH" ]; then - chmod +x "$GLOW_PATH" - ENHANCED_LOGGING=true - fi - fi - "$GLOW_PATH" "$MSG" - elif [ "$TYPE" == 'prompt' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00008b" "▶") $("$GUM_PATH" style --bold "$(format "$MSG")")" - elif [ "$TYPE" == 'star' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --underline "$(format "$MSG")")" - elif [ "$TYPE" == 'start' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$MSG")")" - elif [ "$TYPE" == 'success' ]; then - "$GUM_PATH" style "$("$GUM_PATH" style --foreground="#00ff00" "✔") $("$GUM_PATH" style --bold "$(format "$MSG")")" - elif [ "$TYPE" == 'warn' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --background="#ffff00" --foreground="#000000" " WARNING ") $("$GUM_PATH" style --bold --italic "$(format "$MSG")")" - else - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$MSG")")" - fi -} - # @description Logs using Node.js # @example logger info "An informative log" logg() { @@ -198,13 +147,13 @@ logg() { elif [ "$TYPE" == 'prompt' ]; then "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00008b" "▶") $("$GUM_PATH" style --bold "$(format "$MSG")")" elif [ "$TYPE" == 'star' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --underline "$(format "$MSG")")" + "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold "$(format "$MSG")")" elif [ "$TYPE" == 'start' ]; then "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$MSG")")" elif [ "$TYPE" == 'success' ]; then "$GUM_PATH" style "$("$GUM_PATH" style --foreground="#00ff00" "✔") $("$GUM_PATH" style --bold "$(format "$MSG")")" elif [ "$TYPE" == 'warn' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --background="#ffff00" --foreground="#000000" " WARNING ") $("$GUM_PATH" style --bold --italic "$(format "$MSG")")" + "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --background="#ffff00" --foreground="#000000" " WARNING ") $("$GUM_PATH" style --bold "$(format "$MSG")")" else "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$TYPE")")" fi diff --git a/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg b/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg index 0a031f0a..6c47d808 100644 --- a/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg +++ b/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg @@ -148,13 +148,13 @@ logger() { elif [ "$1" == 'prompt' ]; then "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00008b" "▶") $("$GUM_PATH" style --bold "$(format "$2")")" elif [ "$1" == 'star' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --underline "$(format "$2")")" + "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold "$(format "$2")")" elif [ "$1" == 'start' ]; then "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$2")")" elif [ "$1" == 'success' ]; then "$GUM_PATH" style "$("$GUM_PATH" style --foreground="#00ff00" "✔") $("$GUM_PATH" style --bold "$(format "$2")")" elif [ "$1" == 'warn' ]; then - "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --background="#ffff00" --foreground="#000000" " WARNING ") $("$GUM_PATH" style --bold --italic "$(format "$2")")" + "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#d1d100" "◆") $("$GUM_PATH" style --bold --background="#ffff00" --foreground="#000000" " WARNING ") $("$GUM_PATH" style --bold "$(format "$2")")" else "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$2")")" fi @@ -164,10 +164,12 @@ format() { # shellcheck disable=SC2001,SC2016 ANSI_STR_FORMATTED="$(echo "$1" | sed 's/^\([^`]*\)`\([^`]*\)`.*/\1\\u001b[47;30m \2 \\e[49;m/')" ANSI_STR="$(echo "$1" | sed 's/^\([^`]*\)`\([^`]*\)`\(.*\)$/\3/')" - if [[ $ANSI_STR == *'`'*'`'* ]]; then - ANSI_STR_FORMATTED="$ANSI_STR_FORMATTED$(format "$("$GUM_PATH" style --bold "$ANSI_STR")")" - else - ANSI_STR_FORMATTED="$("$GUM_PATH" style --bold "$ANSI_STR")" + if [ "$ANSI_STR_FORMATTED" != "$ANSI_STR" ]; then + if [[ $ANSI_STR == *'`'*'`'* ]]; then + ANSI_STR_FORMATTED="$ANSI_STR_FORMATTED$(format "$("$GUM_PATH" style --bold "$ANSI_STR")")" + else + ANSI_STR_FORMATTED="$("$GUM_PATH" style --bold "$ANSI_STR")" + fi fi echo -e "$ANSI_STR_FORMATTED" } @@ -176,10 +178,12 @@ formatFaint() { # shellcheck disable=SC2001,SC2016 ANSI_STR_FORMATTED="$(echo "$1" | sed 's/^\([^`]*\)`\([^`]*\)`.*/\1\\u001b[47;30m \2 \\e[49;m/')" ANSI_STR="$(echo "$1" | sed 's/^\([^`]*\)`\([^`]*\)`\(.*\)$/\3/')" - if [[ $ANSI_STR == *'`'*'`'* ]]; then - ANSI_STR_FORMATTED="$ANSI_STR_FORMATTED$(formatFaint "$("$GUM_PATH" style --faint "$ANSI_STR")")" - else - ANSI_STR_FORMATTED="$ANSI_STR_FORMATTED$("$GUM_PATH" style --faint "$ANSI_STR")" + if [ "$ANSI_STR_FORMATTED" != "$ANSI_STR" ]; then + if [[ $ANSI_STR == *'`'*'`'* ]]; then + ANSI_STR_FORMATTED="$ANSI_STR_FORMATTED$(formatFaint "$("$GUM_PATH" style --faint "$ANSI_STR")")" + else + ANSI_STR_FORMATTED="$ANSI_STR_FORMATTED$("$GUM_PATH" style --faint "$ANSI_STR")" + fi fi echo -e "$ANSI_STR_FORMATTED" }