zsh: add transient prompt
This commit is contained in:
parent
baa9b5a2e1
commit
aa6cf52d63
1 changed files with 19 additions and 8 deletions
|
@ -27,7 +27,7 @@ typeset -gA icons=(
|
||||||
[clock]=" "
|
[clock]=" "
|
||||||
)
|
)
|
||||||
|
|
||||||
fs-prompt-render() {
|
fs-prompt-render-full() {
|
||||||
setopt localoptions shortloops
|
setopt localoptions shortloops
|
||||||
|
|
||||||
local separator="${zfg[faded]} ❯ "
|
local separator="${zfg[faded]} ❯ "
|
||||||
|
@ -40,21 +40,23 @@ fs-prompt-render() {
|
||||||
"$(fs-prompt-jobs)"
|
"$(fs-prompt-jobs)"
|
||||||
"$(fs-prompt-exec-time)"
|
"$(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
|
if ((PROMPT_EXIT_CODE == 0)); then
|
||||||
prompt_color="${zfg[faded]}"
|
echo -n "${zfg[faded]}"
|
||||||
elif ((PROMPT_EXIT_CODE > 128 && PROMPT_EXIT_CODE < 160)); then
|
elif ((PROMPT_EXIT_CODE > 128 && PROMPT_EXIT_CODE < 160)); then
|
||||||
prompt_color="${zfg[white]}"
|
echo -n "${zfg[white]}"
|
||||||
else
|
else
|
||||||
prompt_color="${zfg[red]}"
|
echo -n "${zfg[red]}"
|
||||||
fi
|
fi
|
||||||
echo -n "$prompt_color"
|
|
||||||
(($SHLVL > 1)) && printf '%.0s' {2..$SHLVL}
|
(($SHLVL > 1)) && printf '%.0s' {2..$SHLVL}
|
||||||
echo -n "❯ ${zfg[rst]}"
|
echo -n "❯ ${zfg[rst]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs-prompt-render-compact() {
|
||||||
|
echo -n "${zfg[magenta]}❯ ${zfg[rst]}"
|
||||||
|
}
|
||||||
|
|
||||||
fs-prompt-exit-code() {
|
fs-prompt-exit-code() {
|
||||||
((PROMPT_EXIT_CODE == 0)) && return
|
((PROMPT_EXIT_CODE == 0)) && return
|
||||||
|
|
||||||
|
@ -203,6 +205,13 @@ fs-prompt-precmd() {
|
||||||
unset PROMPT_EXEC_START # needed because preexec is not always called
|
unset PROMPT_EXEC_START # needed because preexec is not always called
|
||||||
|
|
||||||
local job_count='%j'; PROMPT_JOB_COUNT=${(%)job_count}
|
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() {
|
fs-setup-prompt() {
|
||||||
|
@ -216,7 +225,9 @@ fs-setup-prompt() {
|
||||||
add-zsh-hook preexec fs-prompt-preexec
|
add-zsh-hook preexec fs-prompt-preexec
|
||||||
add-zsh-hook precmd fs-prompt-precmd
|
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
|
fs-setup-prompt
|
||||||
|
|
Loading…
Add table
Reference in a new issue