diff --git a/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg b/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg.sh similarity index 52% rename from dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg rename to dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg.sh index 8fe46b1a..103ca5a6 100644 --- a/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg +++ b/dotfiles/.local/share/chezmoi/home/.chezmoitemplates/universal/logg.sh @@ -125,221 +125,6 @@ logg() { 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")")" else - echo "WARNING: Unknown log type" - echo "$2" - fi -} - -format() { - # shellcheck disable=SC2001,SC2016 - ANSI_STR="$(echo "$1" | sed 's/^\([^`]*\)`\([^`]*\)`/\1\\u001b[47;1;30m \2 \\e[0;39m/')" - if [[ $ANSI_STR == *'`'*'`'* ]]; then - ANSI_STR="$(format "$ANSI_STR")" - fi - echo -e "$ANSI_STR" -} - -# @description Display prompt that allows you to choose between options -# @example RESPONSE="$(.config/log choose "file.png" "another-file.jpg")" -choose() { - if type gum &> /dev/null; then - CHOOSE_ARGS="gum choose" - for CURRENT_VAR in "$@"; do - CHOOSE_ARGS="$CHOOSE_ARGS \"$CURRENT_VAR\"" - done - eval $CHOOSE_ARGS - else - echo "ERROR: gum is not installed!" - fi -} - -# @description Display a confirmation prompt that returns an exit code if "No" is selected -# @example RESPONSE="$(.config/log confirm "Are you sure?" "Yeah" "Naa")" -confirm() { - if type gum &> /dev/null; then - GUM_OPTS="" - if [ -n "$2" ]; then - # shellcheck disable=SC089 - GUM_OPTS="$GUM_OPTS --affirmative=""'$2'" - fi - if [ -n "$3" ]; then - GUM_OPTS="$GUM_OPTS --negative=""'$3'" - fi - if [ -n "$1" ]; then - if [ -n "$GUM_OPTS" ]; then - gum confirm "$1" "$GUM_OPTS" - else - gum confirm "$1" - fi - else - gum confirm - fi - else - echo "ERROR: gum is not installed!" - fi -} - -# @description Logs an error message -# @example .config/log error "Something happened!" -error() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger error "$1" - else - echo -e "\e[1;41m ERROR \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Display a filterable prompt that is populated with options from a text file -# @example echo Strawberry >> flavors.text && echo Banana >> flavors.text && RESPONSE="$(.config/log filter flavors.txt)" -filter() { - if type gum &> /dev/null; then - TMP="$(mktemp)" - gum filter < "$1" - else - echo "ERROR: gum is not installed!" - fi -} - -# @description Logs an info message -# @example .config/log info "Here is some information" -info() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger info "$1" - else - echo -e "\e[1;46m INFO \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Displays an input with masked characters -# @example INPUT="$(.config/log input 'Enter the value..')" -input() { - if type gum &> /dev/null; then - if [ -n "$1" ]; then - gum input --placeholder="$1" - else - gum input - fi - else - echo "ERROR: gum is not installed!" - fi -} - -# @description Logs a message written in markdown -# @example .config/log md "[styled_link](https://google.com)" -# @example .config/log md mymarkdown/file.md -md() { - if [ ! -f "$1" ]; then - echo "ERROR: A markdown file must be passed in as the parameter" && exit 1 - fi - if [ -n "$ENHANCED_LOGGING" ]; then - logger md "$1" - fi -} - -# @description Displays an input with masked characters -# @example PASSWORD="$(.config/log password 'Enter the Ansible vault password')" -password() { - if type gum &> /dev/null; then - if [ -n "$1" ]; then - gum input --password --placeholder="$1" - else - gum input --password - fi - else - echo "ERROR: gum is not installed!" - fi -} - -# @description Logs a message that describes a prompt -# @example .config/log prompt "Enter text into the following prompt" -prompt() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger prompt "$1" - else - echo -e "\e[1;104m PROMPT \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Display a spinner that stays until a command is completed -# @example .config/log spin "brew install yq" "Installing yq..")" -spin() { - if type gum &> /dev/null; then - if [ -n "$1" ] && [ -n "$2" ]; then - gum spin --title="$2" "$1" - elif [ -n "$1" ]; then - gum spin "$1" - else - gum input - fi - else - echo "ERROR: gum is not installed!" - fi -} - -# @description Logs a message that starts with a star emoji -# @example .config/log star "Congratulations" -star() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger star "$1" - else - echo -e "\e[1;104m LINK \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Logs a message at the beginning of a task -# @example .config/log start "Starting the process.." -start() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger start "$1" - else - echo -e "\e[1;46m START \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Logs a success message -# @example .config/log success "Yay!" -success() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger success "$1" - else - echo -e "\e[1;42m SUCCESS \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Logs a warning message -# @example .config/log warn "Just so you know.." -warn() { - if [ -z "$NO_LOGGING" ]; then - if [ -n "$ENHANCED_LOGGING" ]; then - logger warn "$1" - else - echo -e "\e[1;43m WARNING \e[0m $(format "$1")\e[0;39m" - fi - fi -} - -# @description Displays a multi-line prompt for text input -# @example .config/log write "Write something..")" -write() { - if type gum &> /dev/null; then - if [ -n "$1" ]; then - gum write --placeholder="$1" - else - gum write - fi - else - echo "ERROR: gum is not installed!" + "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$2")")" 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 37566fbd..88d58886 100644 --- a/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg +++ b/dotfiles/.local/share/chezmoi/home/dot_local/bin/executable_logg @@ -156,8 +156,7 @@ logger() { 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")")" else - echo "WARNING: Unknown log type" - echo "$2" + "$GUM_PATH" style " $("$GUM_PATH" style --foreground="#00ff00" "▶") $("$GUM_PATH" style --bold "$(format "$2")")" fi }