zsh: prefix my prompt-related functions with fs-

This commit is contained in:
Fernando Schauenburg 2024-07-29 00:47:10 +02:00
parent 7464e383e3
commit baa9b5a2e1

View file

@ -27,18 +27,18 @@ typeset -gA icons=(
[clock]=" "
)
render_prompt() {
fs-prompt-render() {
setopt localoptions shortloops
local separator="${zfg[faded]} "
local sections=(
"$(render_exit_code)"
"$(render_user_host)"
"$(render_pwd)"
"$(render_git)"
"$(render_venv)"
"$(render_jobs)"
"$(render_exec_time)"
"$(fs-prompt-exit-code)"
"$(fs-prompt-user-and-hostname)"
"$(fs-prompt-pwd)"
"$(fs-prompt-git)"
"$(fs-prompt-virtualenv)"
"$(fs-prompt-jobs)"
"$(fs-prompt-exec-time)"
)
echo "${(@pj.$separator.)sections:#}${zfg[rst]}"
@ -55,7 +55,7 @@ render_prompt() {
echo -n " ${zfg[rst]}"
}
render_exit_code() {
fs-prompt-exit-code() {
((PROMPT_EXIT_CODE == 0)) && return
if ((PROMPT_EXIT_CODE > 128 && PROMPT_EXIT_CODE < 160)); then
@ -65,7 +65,7 @@ render_exit_code() {
fi
}
render_user_host() {
fs-prompt-user-and-hostname() {
local parts=()
# username in red if root, yellow if otherwise relevant
@ -84,11 +84,11 @@ render_user_host() {
}
}
render_pwd() {
fs-prompt-pwd() {
print "${zfg[cyan]}${icons[folder]}%~"
}
render_git() {
fs-prompt-git() {
local gitstatus # local swallows git's exit code if not on its own line
gitstatus=$(command git status --porcelain -b 2>/dev/null) || return
@ -168,15 +168,15 @@ render_git() {
print "${(j: :)gitinfo}"
}
render_venv() {
fs-prompt-virtualenv() {
[[ -n "$VIRTUAL_ENV" ]] && print "${zfg[green]}${icons[python]}${VIRTUAL_ENV:t}"
}
render_jobs() {
fs-prompt-jobs() {
(($PROMPT_JOB_COUNT > 0)) && print "${zfg[magenta]}${icons[background]}%j"
}
render_exec_time() {
fs-prompt-exec-time() {
(($PROMPT_EXEC_TIME <= 3)) && return # don't print time if under 3s
local parts=(
@ -189,12 +189,12 @@ render_exec_time() {
}
# Hook triggered when a command is about to be executed.
prompt_preexec_hook() {
fs-prompt-preexec() {
PROMPT_EXEC_START=$EPOCHSECONDS
}
# Hook triggered right before the prompt is drawn.
prompt_precmd_hook() {
fs-prompt-precmd() {
PROMPT_EXIT_CODE=$? # this needs to be captured before anything else runs
local stop=$EPOCHSECONDS
@ -205,7 +205,7 @@ prompt_precmd_hook() {
local job_count='%j'; PROMPT_JOB_COUNT=${(%)job_count}
}
prompt_setup() {
fs-setup-prompt() {
setopt NO_PROMPT_BANG PROMPT_CR PROMPT_PERCENT PROMPT_SP PROMPT_SUBST
export PROMPT_EOL_MARK='' # don't show % when a partial line is preserved
export VIRTUAL_ENV_DISABLE_PROMPT=1 # we're doing it ourselves
@ -213,10 +213,10 @@ prompt_setup() {
zmodload zsh/datetime # so that $EPOCHSECONDS is available
autoload -Uz add-zsh-hook
add-zsh-hook precmd prompt_precmd_hook
add-zsh-hook preexec prompt_preexec_hook
add-zsh-hook preexec fs-prompt-preexec
add-zsh-hook precmd fs-prompt-precmd
PS1='$(render_prompt)'
PS1='$(fs-prompt-render)'
}
prompt_setup
fs-setup-prompt