zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Simple prompt theme
Date: Fri, 15 Sep 2023 03:49:37 -0500	[thread overview]
Message-ID: <CAKc7PVACiiUwUezRsKpvQsNeHPYmnPfsYL0sHYFHsNX_LYCMRg@mail.gmail.com> (raw)


[-- Attachment #1.1.1: Type: text/plain, Size: 80 bytes --]

It's called sprint:
[image: prompt.png]

--
Best regards,
Sebastian Gniazdowski

[-- Attachment #1.1.2: Type: text/html, Size: 772 bytes --]

[-- Attachment #1.2: prompt.png --]
[-- Type: image/png, Size: 28611 bytes --]

[-- Attachment #2: prompt_sprint_setup --]
[-- Type: application/octet-stream, Size: 3687 bytes --]

# Created by Sebastian Gniazdowski 

prompt_sprint2_help () {
    cat <<EOF
This prompt is color themable. You can invoke it in following way:

prompt sprint2 <time/line color> <braces clr.> <text clr.> <at/colon clr.> <prompt clr.>

You can provide only N first arguments, N=1..5.

The default colors are: 39 green blue green yellow
EOF
}

prompt_sprint2_setup () {
    local col_time_line=${1:-'39'}
    local col_parens=${2:-'green'}
    local col_text=${3:-'blue'}
    local col_at_colon=${4:-'green'}
    local col_prompt=${5:-'yellow'}

    autoload -Uz vcs_info

    typeset -gA _psvar

    local cl_time_line="%B%F{$col_time_line}"
    local cl_text="%b%F{$col_text}"
    local cl_parens="%B%F{$col_parens}"
    local cl_at_colon="%b%F{$col_at_colon}"
    local cl_prompt="%B%F{$col_prompt}"
    local cl_rst="%b%f"

    local _lpar="${cl_parens}["
    local _rpar="${cl_parens}]"

    local _time="$cl_time_line%D{%H:%M}"
    _psvar[user]='%n'
    local _user="$cl_text"'${_psvar[user]}'
    _psvar[at]="@"
    _psvar[host]='%m'
    local _at="$cl_at_colon"'${_psvar[at]}'"$cl_text"'${_psvar[host]}'
    _psvar[colon]=':'
    local _path="$cl_at_colon"'${_psvar[colon]}'"$cl_text%28<*<%/%<<"
    local _line="$cl_time_line%i"
    local _prompt="$cl_prompt# "

    # You can instantly shorten the prompt by setting PSSHORT=1
    if [[ "$COLUMNS" -le 94 || "$PSSHORT" = "1" ]]; then
        _psvar=()
    else
        _psvar[user]='%n'
        _psvar[at]="@"
        _psvar[host]='%m'
        _psvar[colon]=':'
    fi

    PS1="$_time$_lpar$_user$_at$_path$_rpar$_line$_prompt$cl_rst"

    PS2="$cl_parens> $cl_rst"

    RPS1='${vcs_info_msg_0_}'
    prompt_opts=(cr subst percent)

    zstyle ':vcs_info:*' enable git svn darcs bzr hg
    zstyle ':vcs_info:*' stagedstr "%F{green}●$cl_rst"
    zstyle ':vcs_info:*' unstagedstr "%F{yellow}●$cl_rst"
    zstyle ':vcs_info:*' check-for-changes true
    zstyle ':vcs_info:*' formats '(%s)-[%b%u%c]-'

    add-zsh-hook precmd prompt_sprint2_precmd
}

prompt_sprint2_precmd () {
    setopt localoptions noxtrace noksharrays 

    # You can instantly shorten the prompt by setting PSSHORT=1
    if [[ "$COLUMNS" -le 94 || "$PSSHORT" = "1" ]]; then
        _psvar=()
    else
        _psvar[user]='%n'
        _psvar[at]="@"
        _psvar[host]='%m'
        _psvar[colon]=':'
    fi

    local -a changed_files
    changed_files=( )
    git diff --quiet 2>/dev/null || changed_files=( ${(f)"$( git diff --name-only 2>/dev/null )"} )
    changed_files=( $^changed_files(N) )
    if [[ "${#changed_files}" -gt 0 ]]; then
        local basedir
        basedir="$(git rev-parse --show-toplevel)/"
        changed_files=( ${(f)"$( find "${basedir}${^changed_files[@]}" -mtime +2 )"} )
    fi

    if [[ "${#changed_files}" -eq 0 ]]; then
        zstyle ':vcs_info:*' formats ' (%s)-[%b%u%c]'
    else
        zstyle ':vcs_info:*' formats ' (%s)-[%b%u%B%F{yellow}-OLD-%c%%b%f]'
    fi

    vcs_info
}

prompt_sprint2_preview () {
    local -a colors_time_line colors_text
    colors_time_line=(red yellow green blue magenta cyan)
    colors_text=(red yellow green blue magenta cyan)

    local ctime_line ctext i j

    if (( ! $#* )); then
        for (( i = 1; i <= ${#colors_time_line}; i++ )); do
            ctime_line="${colors_time_line[$i]}"
            for (( j = 1; j <= ${#colors_text}; j++ )); do
                ctext="${colors_text[$j]}"
                prompt_preview_theme sprint2 "$ctime_line" "red" "$ctext"
                (( i != ${#colors_time_line} || j != ${#colors_text} )) && print
            done
        done
    else
        prompt_preview_theme sprint2 "$@"
    fi
}

prompt_sprint2_setup "$@"

# vim:ft=zsh

                 reply	other threads:[~2023-09-15  2:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKc7PVACiiUwUezRsKpvQsNeHPYmnPfsYL0sHYFHsNX_LYCMRg@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).