153 lines
4.4 KiB
Plaintext
153 lines
4.4 KiB
Plaintext
autoload -Uz vcs_info
|
|
|
|
pwd="%B%F{blue}%3~%f%b"
|
|
|
|
# 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
|
|
}
|
|
|
|
_kernel_pkg=$(pacman -Qqo /usr/lib/modules/$(uname -r)/vmlinuz 2>/dev/null)
|
|
|
|
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 [[ -z ${_kernel_pkg} ]]; then
|
|
# no kernel package found, so we can't check for updates
|
|
return
|
|
fi
|
|
case ${_kernel_pkg} in
|
|
"linux")
|
|
# mainline kernel
|
|
diff <(uname -r | sed 's/-/./;s/\.0\././') <(pacman -Q linux | cut -d' ' -f2) >/dev/null
|
|
_ret=$?
|
|
;;
|
|
"linux-lts")
|
|
# lts kernel
|
|
diff <(uname -r | sed 's/-lts//') <(pacman -Q linux-lts | cut -d' ' -f2) >/dev/null
|
|
_ret=$?
|
|
;;
|
|
esac
|
|
diff <(uname -r | sed 's/-/./;s/\.0\././') <(pacman -Q linux | cut -d' ' -f2) >/dev/null
|
|
if [[ $? -eq 1 ]]; then
|
|
# kernel update available
|
|
kernel_info_msg_0_="%F{red} reboot required %f"
|
|
fi
|
|
}
|
|
|
|
precmd_vcs_info() {
|
|
vcs_info
|
|
}
|
|
# Reset precmd_functions, then add our functions. This way, regardless of
|
|
# whether this file is sourced multiple times, we don't end up with duplicate
|
|
# entries which will slow down the prompt.
|
|
precmd_functions=()
|
|
precmd_functions+=(precmd_vcs_info precmd_pyenv_info _reset_window_name)
|
|
setopt prompt_subst
|
|
|
|
eval $(awk '{print "OS_" $0}' /etc/os-release)
|
|
eval $(awk '{print "MACHINE_" $0}' /etc/machine-info)
|
|
eval $(awk '{print "PERSONAL_" $0}' ${HOME}/.personal-info 2>/dev/null)
|
|
|
|
if [[ -z ${MACHINE_CHASSIS} ]]; then MACHINE_CHASSIS=$(hostnamectl chassis); fi
|
|
|
|
if [[ ${MACHINE_CHASSIS} != "container" ]]; then
|
|
# Only check if a reboot is necessary if we're not in a container
|
|
precmd_functions+=(precmd_kernel_info)
|
|
fi
|
|
|
|
hostname=$PERSONAL_HOSTNAME
|
|
if [[ -z ${hostname} ]]; then # No personal hostname set
|
|
if [[ -n ${MACHINE_PRETTY_HOSTNAME} ]]; then
|
|
# Use MACHINE_PRETTY_HOSTNAME if set
|
|
hostname=${MACHINE_PRETTY_HOSTNAME}
|
|
elif [[ -f /etc/hostname ]]; then
|
|
# Fall back to system hostname
|
|
hostname=$(</etc/hostname)
|
|
else
|
|
# Ask the kernel for the hostname
|
|
hostname=$(uname -n)
|
|
fi
|
|
fi
|
|
|
|
show_os_icon=1
|
|
# use nerd fonts for icons
|
|
case $OS_ID in
|
|
"arch")
|
|
show_os_icon=0 # Arch is my default, no need to show icon
|
|
;;
|
|
"debian")
|
|
os_icon=""
|
|
;;
|
|
"ubuntu")
|
|
os_icon=""
|
|
;;
|
|
*)
|
|
show_os_icon=0
|
|
;;
|
|
esac
|
|
prompt="▶"
|
|
host="%F{cyan}[ %F{green}${hostname}%(!.%F{red} as root.) %F{cyan}]%f"
|
|
localhost="%F{cyan}[ %F{magenta}%B${hostname}%(!.%F{red} as root.)%b %F{cyan}]%f"
|
|
serial_host="%F{cyan}[ %F{magenta}${hostname}%(!.%F{red} as root.) %F{cyan}] %F{red}%y%f"
|
|
container_host="%F{cyan}[ %F{blue}%B${hostname}%(!.%F{red} as root.)%b %F{cyan}]%f"
|
|
returncode="%(?..%F{red} %?%f)"
|
|
|
|
prompt_line1='$kernel_info_msg_0_'
|
|
prompt_line3=$prompt
|
|
|
|
# Create conditional prompt line 2
|
|
if [[ -v SSH_CLIENT ]]; then
|
|
prompt_line2='${host}$pyenv_info_msg_0_ ${pwd}'
|
|
elif [[ ${TTY} =~ "tty" ]]; then
|
|
prompt_line2='${serial_host}$pyenv_info_msg_0_ ${pwd}'
|
|
elif [[ ${MACHINE_CHASSIS} == "container" ]]; then
|
|
prompt_line2='${container_host}$pyenv_info_msg_0_ ${pwd}'
|
|
else
|
|
prompt_line2='${localhost}$pyenv_info_msg_0_ ${pwd}'
|
|
fi
|
|
|
|
# Inject icon if available, with ANSI color code stored in $OS_ANSI_COLOR
|
|
if [[ ${show_os_icon} -eq 1 ]]; then
|
|
prompt_line2=$'%{\x1b[${OS_ANSI_COLOR}m${os_icon}\x1b[0m%}'" ${prompt_line2}"
|
|
fi
|
|
|
|
if [[ ${TERM} == "dumb" ]]; then
|
|
# Dumb terminal needs a dumb prompt, otherwise things like
|
|
# emacs TRAMP break
|
|
PROMPT='$ '
|
|
else
|
|
PROMPT="${prompt_line1}
|
|
${prompt_line2}
|
|
${prompt_line3} "
|
|
fi
|
|
|
|
RPROMPT='$vcs_info_msg_0_$returncode'
|
|
|
|
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
|