Skip to content

A fast, modulable and extremely configurable prompt for any shells

License

Notifications You must be signed in to change notification settings

krostar/prompto

Repository files navigation

prompto

godoc Licence Latest version

A fast, modulable and extremely configurable prompt for any shells.

Motivation

// TODO

Installation

// TODO

Bash

_prompt_command_timer_start() {
    { [ ! -t 1 ] || [ -p /dev/stdout ] || [[ ! -t 1 && ! -p /dev/stdout ]] || [ -n "$COMP_LINE" ] || [[ "$BASH_COMMAND" == "$PROMPT_COMMAND" ]]; } && return
    prompt_command_started_at=$(date +'%s')
}

_prompt() {
    local -r last_cmd_status="$?"
    local last_cmd_duration=0
    
    if [ -n "$prompt_command_started_at" ]; then
        last_cmd_duration="$((($(date +'%s') - prompt_command_started_at) * 1000000000))"
        unset prompt_command_started_at
    fi

    local -r LPROMPT="$(prompto --left -s $last_cmd_status -d $last_cmd_duration)"
    local -r RPROMPT="$(prompto --right)"
    local -r RPROMPT_NOCOLOR="$(echo "$RPROMPT" | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g')"
    local -r RPROMPT_LEN="$((${#RPROMPT_NOCOLOR}-1))"

    PS1="\[\e[s\e[${COLUMNS:-$(tput cols)}C\e[${RPROMPT_LEN}D${RPROMPT}\e[u\]${LPROMPT}"
}

PROMPT_COMMAND=_prompt
trap _prompt_command_timer_start DEBUG

ZSH

zmodload zsh/datetime
zmodload zsh/mathfunc

function preexec() {
    prompt_command_started_at="$EPOCHREALTIME"
}

function _prompt() {
    local last_cmd_status=$?
    local last_cmd_duration=0

    if [ -n "$prompt_command_started_at" ]; then
        last_cmd_duration="$((int(rint((EPOCHREALTIME - prompt_command_started_at) * 1000000000))))"
        unset prompt_command_started_at
    fi

    PROMPT="$(prompto/build/bin/prompto --left --shell zsh -s $last_cmd_status -d $last_cmd_duration)"
    RPROMPT="$(prompto/build/bin/prompto --right --shell zsh)"
    ZLE_RPROMPT_INDENT=0

    export PROMPT RPROMPT ZLE_RPROMPT_INDENT
}

function _init_prompt() {
    for s in "${precmd_functions[@]}"; do
        if [ "$s" = "_prompt" ]; then
            return
        fi
    done
    precmd_functions+=(_prompt)
}

if [ "$TERM" != "linux" ]; then
    _init_prompt
fi

Fish

function fish_prompt
    set -l exitcode $status
    set -l duration (math "$CMD_DURATION * 1000000")
    prompto --left -d $duration -s $exitcode
end

function fish_right_prompt
    prompto --right
end

Configuration

// TODO

Limitation

// TODO

Comparaison

Command Mean [ms] Min [ms] Max [ms] Relative
prompto --config cmd/prompto/testdata/prompto.yml 21.5 ± 8.5 18.8 102.6 1.00
powerline-go -shell bare -eval -numeric-exit-codes -modules duration,exit,perms,cwd,git -duration 10 -error 42 -theme cmd/prompto/testdata/powerline.json 22.6 ± 3.0 20.2 44.9 1.05 ± 0.43

About

A fast, modulable and extremely configurable prompt for any shells

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published