fix(zsh): make prompt a sourced script

This commit is contained in:
Oscar Wallberg
2024-07-29 04:37:48 +02:00
parent 02216e8a3e
commit 2a708e72df
2 changed files with 22 additions and 25 deletions
+21 -21
View File
@@ -1,19 +1,13 @@
# vim: set ft=zsh: # vim: set ft=zsh:
# For help with expansion codes, see: function _precmd_hook() {
# - https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
# For help with parameters, see:
# - https://zsh.sourceforge.io/Doc/Release/Parameters.html
# shellcheck disable=SC2034
function prompt_warg_precmd() {
local -a _status=("${pipestatus[@]}") local -a _status=("${pipestatus[@]}")
RPS1="" RPROMPT=""
# Status code # Status code
if [[ ${#${_status//0/}} -gt 0 ]]; then if [[ ${#${_status//0/}} -gt 0 ]]; then
# shellcheck disable=SC2296 # shellcheck disable=SC2296
RPS1="$RPS1 %F{red}${(j:|:)_status}%f" RPROMPT="$RPROMPT %F{red}${(j:|:)_status}%f"
fi fi
# Python virtualenv # Python virtualenv
@@ -37,23 +31,29 @@ function prompt_warg_precmd() {
_venv_name="$_venv_parent" _venv_name="$_venv_parent"
fi fi
RPS1="$RPS1 %F{yellow}$_venv_name%f" RPROMPT="$RPROMPT %F{yellow}$_venv_name%f"
fi fi
# Timestamp # Timestamp
RPS1="$RPS1 %8F%D{%H:%M:%S}%f" RPROMPT="$RPROMPT %8F%D{%H:%M:%S}%f"
export RPROMPT
} }
# shellcheck disable=SC2034 export VIRTUAL_ENV_DISABLE_PROMPT=1
function prompt_warg_setup() {
VIRTUAL_ENV_DISABLE_PROMPT=1
prompt_opts=(bang cr sp percent subst)
# PS1="%n@%m %~ $ "
PS1='%(#.%F{red}.%12F)%n@%m%f %1~ %(#.#.$) '
PS2="> "
add-zsh-hook precmd prompt_warg_precmd # https://zsh.sourceforge.io/Doc/Release/Options.html
} setopt PROMPT_BANG
setopt PROMPT_CR
setopt PROMPT_SP
setopt PROMPT_PERCENT
setopt PROMPT_SUBST
# https://zsh.sourceforge.io/Doc/Release/Parameters.html
# https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
export PROMPT='%(#.%F{red}.%12F)%n@%m%f %1~ %(#.#.$) '
export PROMPT2="> "
prompt_warg_setup "$@" # https://zsh.sourceforge.io/Doc/Release/Functions.html#Hook-Functions
typeset -a precmd_functions
precmd_functions+=(_precmd_hook)
+1 -4
View File
@@ -28,7 +28,6 @@ setopt INC_APPEND_HISTORY_TIME
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html # Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
path=("${HOME}/.local/bin" "${path[@]}") path=("${HOME}/.local/bin" "${path[@]}")
fpath=("${_here}/functions" "${fpath[@]}")
export PATH export PATH
export MAIL="/var/spool/mail/$USER" export MAIL="/var/spool/mail/$USER"
export MAILCHECK=60 export MAILCHECK=60
@@ -144,9 +143,7 @@ alias ssh='ssh_with_title'
# Prompt # # Prompt #
########## ##########
autoload -Uz promptinit source "${_here}/prompt"
promptinit
prompt warg
######## ########
# Misc # # Misc #