prompto

module
v0.0.0-...-fb30631 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: GPL-3.0

README

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

Directories

Path Synopsis
internal
prompto/adapter/segment
Package segment defines all segments and exposes an unique way to provide them.
Package segment defines all segments and exposes an unique way to provide them.
prompto/domain
Package domain defines all models.
Package domain defines all models.
prompto/domain/usecase
Package usecase contains the pure business-related methods.
Package usecase contains the pure business-related methods.
prompto/port/command
Package command defines the CLI port.
Package command defines the CLI port.
pkg
color
Package color handles ANSI colors and colorization.
Package color handles ANSI colors and colorization.
pathx
Package pathx defines multiple helpers around paths.
Package pathx defines multiple helpers around paths.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL