106 lines
3.3 KiB
Bash
106 lines
3.3 KiB
Bash
autoload -Uz vcs_info
|
||
|
||
# Show active python virtualenv in prompt
|
||
precmd_pyenv_info() {
|
||
# use nerd fonts for icons
|
||
_pyenv_icon=""
|
||
# Only update if we've changed directory, since pyenv can be slow
|
||
if [[ "$PWD" == "$_pyenv_old_pwd" ]]; then
|
||
return
|
||
else
|
||
_pyenv_old_pwd="$PWD"
|
||
fi
|
||
_pyenv_version=$(pyenv version-name 2>/dev/null)
|
||
if [[ $? -eq 0 ]] && [[ ${_pyenv_version} != "system" ]] && [[ ${_pyenv_version} != "personal" ]]; then
|
||
pyenv_info_msg_0_="%F{yellow} ${_pyenv_icon} ${_pyenv_version}%f"
|
||
elif [[ ${_pyenv_version} == "system" ]]; then
|
||
pyenv_info_msg_0_="%F{red} ${_pyenv_icon} ${_pyenv_version}%f"
|
||
else
|
||
pyenv_info_msg_0_=""
|
||
fi
|
||
}
|
||
|
||
precmd_kernel_info() {
|
||
# check to see if a kernel update has been installed
|
||
# since we need to reboot to use it
|
||
|
||
# if message has been set, don't check again, since a reboot
|
||
# is required to clear the message
|
||
if [[ -n ${kernel_info_msg_0_} ]]; then
|
||
return
|
||
fi
|
||
if [[ ${OS_RELEASE[Id]} == "arch" ]] || [[ ${OS_RELEASE[IdLike]} == "arch" ]]; then
|
||
# Arch Linux removes the old kernel when updating, so we can
|
||
# just check to see if /usr/lib/modules/$(uname -r)/vmlinuz exists
|
||
if ! [[ -f /usr/lib/modules/$(uname -r)/vmlinuz ]]; then
|
||
# kernel update available
|
||
kernel_info_msg_0_="%F{red} reboot required %f"
|
||
fi
|
||
fi
|
||
}
|
||
|
||
precmd_vcs_info() {
|
||
vcs_info
|
||
}
|
||
|
||
if [[ ${TERM} == "alacritty" ]]; then
|
||
precmd_functions+=(precmd_vcs_info precmd_pyenv_info _reset_window_name)
|
||
elif ! [[ ${TERM} == "dumb" ]]; then
|
||
precmd_functions+=(precmd_vcs_info precmd_pyenv_info)
|
||
fi
|
||
|
||
if [[ ${SYSTEM_INFO[Chassis]} != "container" ]] && [[ ${OS_RELEASE[IdLike]:-${OS_RELEASE[Id]}} == "arch" ]]; then
|
||
# Only check if a reboot is necessary if we're not in a container, and we're arch-based (the check we're using only works for arch-based distros)
|
||
precmd_functions+=(precmd_kernel_info)
|
||
fi
|
||
|
||
prompt_list=(
|
||
'$kernel_info_msg_0_' $'\n'
|
||
"%F{cyan}[%f " ${prompt_elements[deployment]} ${prompt_elements[host]} ${prompt_elements[privilege]} " %F{cyan}]%f" ${prompt_elements[console]} ${prompt_elements[pyenv]} ' ' ${prompt_elements[pwd]} ${prompt_elements[groups]}
|
||
" " ${prompt_elements[prompt]}
|
||
)
|
||
rprompt_list=(
|
||
${prompt_elements[vcs]} ${prompt_elements[retcode]}
|
||
)
|
||
history_prompt=(
|
||
"%F{cyan}[%f " ${prompt_elements[host]} ${prompt_elements[privilege]} " %F{cyan}]%f" ${prompt_elements[console]} ' ' ${prompt_elements[clock]} ' ' ${prompt_elements[pwd]} ' ' ${prompt_elements[prompt]}
|
||
)
|
||
|
||
set-prompt() {
|
||
if [[ ${TERM} == "dumb" ]]; then
|
||
# Dumb terminal needs a dumb prompt, otherwise things like
|
||
# emacs TRAMP break
|
||
PROMPT='[%~] $ '
|
||
PROMPT2='> '
|
||
else
|
||
_build-prompt
|
||
PROMPT2=" %F{yellow}%_ ❯%f "
|
||
fi
|
||
|
||
}
|
||
set-prompt
|
||
|
||
rewrite-prompt-and-accept() {
|
||
local oldprompt
|
||
if [[ ${TERM} == "dumb" ]]; then
|
||
return
|
||
fi
|
||
oldprompt="${PROMPT}"
|
||
PROMPT="${HISTORY_UNPROMPT}"
|
||
|
||
# Clear any suggestions; we've committed to this command
|
||
zle autosuggest-clear
|
||
zle reset-prompt
|
||
PROMPT="${oldprompt}"
|
||
zle accept-line
|
||
}
|
||
|
||
zle -N rewrite-prompt-and-accept
|
||
bindkey '^M' rewrite-prompt-and-accept
|
||
|
||
zstyle ':vcs_info:git:*' formats '%c %F{magenta} %B%r%%b %F{cyan} %b%f'
|
||
zstyle ':vcs_info:git:*' actionformats '%c%F{magenta} %B%r%%b %F{cyan} %b %F{red} %a%f'
|
||
zstyle ':vcs_info:git:*' stagedstr "%F{green}%f"
|
||
zstyle ':vcs_info:git:*' check-for-staged-changes true
|
||
zstyle ':vcs_info:*' enable git
|