<commit_before>#!/bin/zsh

# Prompt constants
__PROMPT_BASIC="${debian_chroot:+($debian_chroot)}$COLOR_GREEN_BOLD%n@%m$COLOR_RESET:$COLOR_BLUE_BOLD%~$COLOR_RESET\$ "
__PROMPT_BASIC_NO_COLORS="${debian_chroot:+($debian_chroot)}%n@%m:%~\$ "
__PROMPT_UNPRINTABLE_PREFIX="%{"
__PROMPT_UNPRINTABLE_SUFFIX="%}"
__PROMPT_TITLE_PREFIX="%{\e]0;"
__PROMPT_TITLE_SUFFIX="\007%}"
__PROMPT_GIT_UNTRACKED_FILES="%%"
__PROMPT_PS2=0
__PROMPT_PS4=0

# Defaults - disable some info in left to enable it in rprompt
: ${__PROMPT_GIT:=0}
: ${__PROMPT_TIMER:=0}
: ${__PROMPT_SHLVL:=0}

source $BASH_DIR/prompts/custom.sh

rebuildPrompts2() {

    buildRprompt() {
        [ $__PROMPT_SIMPLE -eq 1 ] || [ $__RPROMPT_ENABLED = 0 ] && return
        local rprompt=""
        [ $__RPROMPT_TIMER != 0 ] && rprompt+="$__PROMPT_TIMER_COLOR\$(__promptTimer $__RPROMPT_TIMER)"
        [ $__RPROMPT_STATUS != 0 ] && rprompt+="\$(declare cmdstatus=\$?; [ \$cmdstatus != 0 ] && echo \"${__PROMPT_CMD_ERR_COLOR}[err:\$cmdstatus]${__PROMPT_COLOR_RESET}\"; exit \$cmdstatus)"
        [ $__RPROMPT_GIT != 0 ] && rprompt+="$__PROMPT_REPO_COLOR\$(__promptGitStatus)"
        [ $__RPROMPT_TIMESTAMP != 0 ] && rprompt+="$__PROMPT_TIMESTAMP_COLOR\$(__promptTimestamp)"
        [ $__RPROMPT_SHLVL != 0 ] && rprompt+="$__PROMPT_SHLVL_COLOR\$(__promptShlvl $__RPROMPT_SHLVL \"/\" \"\")"
        rprompt+="$__PROMPT_COLOR_RESET"
        echo "$rprompt";
    }

    buildPS4() {
        if [ $__PROMPT_SIMPLE -eq 1 ]; then
            echo "+ "
            return;
        fi
        local gray blue reset cyan magenta
        if [ $__PROMPT_COLORS != 0 ]; then
            local gray=$COLOR_GRAY_INT_BOLD
            local blue=$COLOR_BLUE_BOLD
            local reset=$COLOR_RESET
            local cyan=$COLOR_CYAN_BOLD
            local magenta=$COLOR_MAGENTA
        fi
        local tab="\011"
        local PS4="+ ";
        PS4+="$gray%D{%H:%M:%S} "
        PS4+="$blue%x$reset:$cyan%I"
        PS4+="$reset$tab$magenta%N$gray()$reset:$tab"
        PS4+="$reset"
        echo "$PS4";
    }

    buildPS2() {
        if [ $__PROMPT_SIMPLE -eq 1 ]; then
            echo "> "
            return;
        fi
        local reset cyan
        if [ $__PROMPT_COLORS != 0 ]; then
            local reset=$COLOR_RESET
            local cyan=$COLOR_CYAN_BOLD
        fi
        echo "$cyan(%_)>$reset ";
    }

    export RPROMPT="$(buildRprompt)"
    export PS2="$(buildPS2)"
    export PS4="$(buildPS4)"
}

function __rprompt_define_opt() {
    local funcname=$1
    local varname=$2
    local default=$3
    # Setup default value
    eval $varname=\${$varname-$default}
    # Setup toggle function
    eval "$(echo "
    function $funcname() {
        local a=\$(echo "\$1" | tr '[:lower:]' '[:upper:]')
        if [ -z \$a ]; then
            [ \$$varname = 0 ] && $varname=1 || $varname=0;
        elif [ "\$a" = "TRUE" ] || [ "\$a" = "T" ] || [ "\$a" = "1" ]; then
            $varname=1
        elif [ "\$a" = "FALSE" ] || [ "\$a" = "F" ] || [ "\$a" = "0" ]; then
            $varname=0
        else
            $varname=\$1
        fi
        echo \"$varname=\$$varname\"
        rebuildPrompts2
    }")"
}

# Right Prompt Config
## Show right prompt
__rprompt_define_opt prompt_rprompt_enabled __RPROMPT_ENABLED 1
## Show GIT status
__rprompt_define_opt prompt_rprompt_git __RPROMPT_GIT $(hash git 2>/dev/null && echo 1)
## Show last command result status
__rprompt_define_opt prompt_rprompt_status __RPROMPT_STATUS 1
## Add timestamp to prompt (date format)
__rprompt_define_opt prompt_rprompt_timestamp __RPROMPT_TIMESTAMP 0
## Time cmd execution (-1=all, 0=never, x>0=mesure those above x ms)
__rprompt_define_opt prompt_rprompt_timer __RPROMPT_TIMER -1
## Show subshell count from SHLVL (-1=all, 0=never, x>0=mesure those above x)
__rprompt_define_opt prompt_rprompt_shlvl __RPROMPT_SHLVL 1


# Initial prompt build
rebuildPrompts

# Timer mechanism
autoload -U add-zsh-hook
add-zsh-hook preexec __promptPreExec
add-zsh-hook precmd __promptPreCmd<commit_msg>Removing buggy rprompt from zsh<commit_after>#!/bin/zsh

rebuildPrompts2() {

    buildRprompt() {
        [ $__PROMPT_SIMPLE -eq 1 ] || [ $__RPROMPT_ENABLED = 0 ] && return
        local rprompt=""
        [ $__RPROMPT_TIMER != 0 ] && rprompt+="$__PROMPT_TIMER_COLOR\$(__promptTimer $__RPROMPT_TIMER)"
        [ $__RPROMPT_STATUS != 0 ] && rprompt+="\$(declare cmdstatus=\$?; [ \$cmdstatus != 0 ] && echo \"${__PROMPT_CMD_ERR_COLOR}[err:\$cmdstatus]${__PROMPT_COLOR_RESET}\"; exit \$cmdstatus)"
        [ $__RPROMPT_GIT != 0 ] && rprompt+="$__PROMPT_REPO_COLOR\$(__promptGitStatus)"
        [ $__RPROMPT_TIMESTAMP != 0 ] && rprompt+="$__PROMPT_TIMESTAMP_COLOR\$(__promptTimestamp)"
        [ $__RPROMPT_SHLVL != 0 ] && rprompt+="$__PROMPT_SHLVL_COLOR\$(__promptShlvl $__RPROMPT_SHLVL \"/\" \"\")"
        rprompt+="$__PROMPT_COLOR_RESET"
        echo "$rprompt";
    }

    buildPS4() {
        if [ $__PROMPT_SIMPLE -eq 1 ]; then
            echo "+ "
            return;
        fi
        local gray blue reset cyan magenta
        if [ $__PROMPT_COLORS != 0 ]; then
            local gray=$COLOR_GRAY_INT_BOLD
            local blue=$COLOR_BLUE_BOLD
            local reset=$COLOR_RESET
            local cyan=$COLOR_CYAN_BOLD
            local magenta=$COLOR_MAGENTA
        fi
        local tab="\011"
        local PS4="+ ";
        PS4+="$gray%D{%H:%M:%S} "
        PS4+="$blue%x$reset:$cyan%I"
        PS4+="$reset$tab$magenta%N$gray()$reset:$tab"
        PS4+="$reset"
        echo "$PS4";
    }

    buildPS2() {
        if [ $__PROMPT_SIMPLE -eq 1 ]; then
            echo "> "
            return;
        fi
        local reset cyan
        if [ $__PROMPT_COLORS != 0 ]; then
            local reset=$COLOR_RESET
            local cyan=$COLOR_CYAN_BOLD
        fi
        echo "$cyan(%_)>$reset ";
    }

    export RPROMPT="$(buildRprompt)"
    export PS2="$(buildPS2)"
    export PS4="$(buildPS4)"
}

function __rprompt_define_opt() {
    local funcname=$1
    local varname=$2
    local default=$3
    # Setup default value
    eval $varname=\${$varname-$default}
    # Setup toggle function
    eval "$(echo "
    function $funcname() {
        local a=\$(echo "\$1" | tr '[:lower:]' '[:upper:]')
        if [ -z \$a ]; then
            [ \$$varname = 0 ] && $varname=1 || $varname=0;
        elif [ "\$a" = "TRUE" ] || [ "\$a" = "T" ] || [ "\$a" = "1" ]; then
            $varname=1
        elif [ "\$a" = "FALSE" ] || [ "\$a" = "F" ] || [ "\$a" = "0" ]; then
            $varname=0
        else
            $varname=\$1
        fi
        echo \"$varname=\$$varname\"
        rebuildPrompts2
    }")"
}

# Right Prompt Config
## Show right prompt
__rprompt_define_opt prompt_rprompt_enabled __RPROMPT_ENABLED 1
## Show GIT status
__rprompt_define_opt prompt_rprompt_git __RPROMPT_GIT $(hash git 2>/dev/null && echo 1)
## Show last command result status
__rprompt_define_opt prompt_rprompt_status __RPROMPT_STATUS 1
## Add timestamp to prompt (date format)
__rprompt_define_opt prompt_rprompt_timestamp __RPROMPT_TIMESTAMP 0
## Time cmd execution (-1=all, 0=never, x>0=mesure those above x ms)
__rprompt_define_opt prompt_rprompt_timer __RPROMPT_TIMER -1
## Show subshell count from SHLVL (-1=all, 0=never, x>0=mesure those above x)
__rprompt_define_opt prompt_rprompt_shlvl __RPROMPT_SHLVL 1

# Prompt constants
__PROMPT_BASIC="${debian_chroot:+($debian_chroot)}$COLOR_GREEN_BOLD%n@%m$COLOR_RESET:$COLOR_BLUE_BOLD%~$COLOR_RESET\$ "
__PROMPT_BASIC_NO_COLORS="${debian_chroot:+($debian_chroot)}%n@%m:%~\$ "
__PROMPT_UNPRINTABLE_PREFIX="%{"
__PROMPT_UNPRINTABLE_SUFFIX="%}"
__PROMPT_TITLE_PREFIX="%{\e]0;"
__PROMPT_TITLE_SUFFIX="\007%}"
__PROMPT_GIT_UNTRACKED_FILES="%%"
__PROMPT_PS2=0
__PROMPT_PS4=0

# Defaults - disable some info in left to enable it in rprompt
: ${__PROMPT_GIT:=0}
: ${__PROMPT_TIMER:=0}
: ${__PROMPT_SHLVL:=0}

# Initial prompt build
source $BASH_DIR/prompts/custom.sh
rebuildPrompts

# Timer mechanism
autoload -U add-zsh-hook
add-zsh-hook preexec __promptPreExec
add-zsh-hook precmd __promptPreCmd
{'fraction_non_alphanumeric': 0.1488833746898263, 'fraction_numerical': 0.016129032258064516, 'mean_word_length': 3.0568696527428285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4296620', 'n_tokens_mistral': 3186, 'n_tokens_neox': 2917, 'n_words': 555}