From aa6cf52d63a1ddea59c4316227e0f6f221465d0b Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Mon, 29 Jul 2024 01:54:52 +0200 Subject: [PATCH] zsh: add transient prompt --- config/zsh/prompt.zsh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/config/zsh/prompt.zsh b/config/zsh/prompt.zsh index 331c108..8e3913a 100644 --- a/config/zsh/prompt.zsh +++ b/config/zsh/prompt.zsh @@ -27,7 +27,7 @@ typeset -gA icons=( [clock]=" " ) -fs-prompt-render() { +fs-prompt-render-full() { setopt localoptions shortloops local separator="${zfg[faded]} ❯ " @@ -40,21 +40,23 @@ fs-prompt-render() { "$(fs-prompt-jobs)" "$(fs-prompt-exec-time)" ) - echo "${(@pj.$separator.)sections:#}${zfg[rst]}" + echo "\n${(@pj.$separator.)sections:#}${zfg[rst]}" - local prompt_color if ((PROMPT_EXIT_CODE == 0)); then - prompt_color="${zfg[faded]}" + echo -n "${zfg[faded]}" elif ((PROMPT_EXIT_CODE > 128 && PROMPT_EXIT_CODE < 160)); then - prompt_color="${zfg[white]}" + echo -n "${zfg[white]}" else - prompt_color="${zfg[red]}" + echo -n "${zfg[red]}" fi - echo -n "$prompt_color" (($SHLVL > 1)) && printf '󰅂%.0s' {2..$SHLVL} echo -n "❯ ${zfg[rst]}" } +fs-prompt-render-compact() { + echo -n "${zfg[magenta]}❯ ${zfg[rst]}" +} + fs-prompt-exit-code() { ((PROMPT_EXIT_CODE == 0)) && return @@ -203,6 +205,13 @@ fs-prompt-precmd() { unset PROMPT_EXEC_START # needed because preexec is not always called local job_count='%j'; PROMPT_JOB_COUNT=${(%)job_count} + + PS1='$(fs-prompt-render-full)' +} + +fs-prompt-zle-line-finish() { + PS1='$(fs-prompt-render-compact)' + zle reset-prompt } fs-setup-prompt() { @@ -216,7 +225,9 @@ fs-setup-prompt() { add-zsh-hook preexec fs-prompt-preexec add-zsh-hook precmd fs-prompt-precmd - PS1='$(fs-prompt-render)' + autoload -Uz add-zle-hook-widget + # add-zle-hook-widget line-init fs-prompt-zle-line-init + add-zle-hook-widget line-finish fs-prompt-zle-line-finish } fs-setup-prompt