2022-03-20 16:41:17 +01:00
|
|
|
# Zsh prompt theme, needs Zsh >= 5.0.0. Asynchronous prompt if zsh-async is
|
2022-03-20 21:57:10 +01:00
|
|
|
# detected. Requires 256 colours.
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
function() # Keep local variables in here
|
|
|
|
{
|
|
|
|
|
|
|
|
# Make theme variables global for later use
|
|
|
|
typeset -gA zsh_theme_colours
|
2022-03-22 01:03:21 +01:00
|
|
|
zsh_theme_colours[prompt]="207" # bright pink
|
2022-03-18 14:34:27 +01:00
|
|
|
zsh_theme_colours[vcs]="97" # dark pink
|
2022-03-22 01:03:21 +01:00
|
|
|
zsh_theme_colours[highlight]="201" # pink
|
2022-03-18 14:34:27 +01:00
|
|
|
zsh_theme_colours[minor]="60" # dark violet
|
|
|
|
zsh_theme_colours[inactive]="236" # grey
|
|
|
|
|
|
|
|
[[ -n "${SSH_CONNECTION}" ]] && zsh_theme_colours[prompt]="yellow"
|
2022-03-23 01:52:26 +01:00
|
|
|
[[ ${EUID} -eq 0 ]] && zsh_theme_colours[prompt]="red"
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
# Show username if it is not the default user
|
|
|
|
local showuser=""
|
|
|
|
if [[ "${USERNAME}" != "${DEFAULT_USER}" ]] && [[ -n "${USERNAME}" ]]; then
|
|
|
|
showuser="%n "
|
|
|
|
fi
|
|
|
|
|
|
|
|
autoload -Uz vcs_info
|
|
|
|
|
|
|
|
zstyle ':vcs_info:*' enable git svn hg # vcs_info_printsys
|
|
|
|
zstyle ':vcs_info:*' formats "%F{${zsh_theme_colours[vcs]}}(%b)%u%c%f "
|
|
|
|
zstyle ':vcs_info:*' actionformats "%F{${zsh_theme_colours[vcs]}}(%b|%F{${zsh_theme_colours[highlight]}}%a%F{${zsh_theme_colours[vcs]}})%u%c%f "
|
2022-03-20 21:57:10 +01:00
|
|
|
zstyle ':vcs_info:*' stagedstr "%F{${zsh_theme_colours[highlight]}}●%f"
|
|
|
|
zstyle ':vcs_info:*' unstagedstr "%F{${zsh_theme_colours[highlight]}}○%f"
|
2022-03-18 14:34:27 +01:00
|
|
|
zstyle ':vcs_info:*' check-for-changes true
|
|
|
|
|
|
|
|
# Needs mafredri/zsh-async, async_init must be called before using
|
|
|
|
function async_vcs_prompt()
|
|
|
|
{
|
|
|
|
# From https://vincent.bernat.ch/en/blog/2019-zsh-async-vcs-info
|
2022-03-20 21:57:10 +01:00
|
|
|
function _my_vcs_async_start() {
|
2022-03-18 14:34:27 +01:00
|
|
|
async_start_worker vcs_info
|
|
|
|
async_register_callback vcs_info _my_vcs_info_done
|
|
|
|
}
|
2022-03-20 21:57:10 +01:00
|
|
|
function _my_vcs_info() {
|
2022-03-18 14:34:27 +01:00
|
|
|
cd -q $1
|
|
|
|
vcs_info
|
|
|
|
print ${vcs_info_msg_0_}
|
|
|
|
}
|
2022-03-20 21:57:10 +01:00
|
|
|
function _my_vcs_info_done() {
|
2022-03-18 14:34:27 +01:00
|
|
|
local job=$1
|
|
|
|
local return_code=$2
|
|
|
|
local stdout=$3
|
|
|
|
local more=$6
|
|
|
|
if [[ $job == '[async]' ]]; then
|
|
|
|
if [[ $return_code -eq 2 ]]; then
|
|
|
|
# Need to restart the worker
|
|
|
|
_my_vcs_async_start
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
vcs_info_msg_0_=$stdout
|
|
|
|
(( $more )) || zle reset-prompt
|
|
|
|
}
|
2022-03-20 21:57:10 +01:00
|
|
|
function _my_vcs_chpwd() {
|
2022-03-18 14:34:27 +01:00
|
|
|
# Change colour of old value
|
|
|
|
vcs_info_msg_0_="${vcs_info_msg_0_//\%F\{${zsh_theme_colours[vcs]}/%F{${zsh_theme_colours[inactive]}}"
|
|
|
|
vcs_info_msg_0_="${vcs_info_msg_0_//\%F\{${zsh_theme_colours[highlight]}/%F{${zsh_theme_colours[inactive]}}"
|
|
|
|
}
|
2022-03-20 21:57:10 +01:00
|
|
|
function _my_vcs_precmd() {
|
2022-03-18 14:34:27 +01:00
|
|
|
async_flush_jobs vcs_info
|
|
|
|
async_job vcs_info _my_vcs_info $PWD
|
|
|
|
}
|
|
|
|
|
|
|
|
_my_vcs_async_start
|
|
|
|
add-zsh-hook precmd _my_vcs_precmd
|
|
|
|
add-zsh-hook chpwd _my_vcs_chpwd
|
|
|
|
}
|
|
|
|
|
|
|
|
# Use asynchronous VCS prompt if zsh-async is installed and initialized
|
|
|
|
if [[ ${ASYNC_INIT_DONE} -eq 1 ]]; then
|
|
|
|
async_vcs_prompt
|
|
|
|
else
|
|
|
|
add-zsh-hook precmd vcs_info
|
|
|
|
fi
|
|
|
|
|
2022-03-23 02:37:02 +01:00
|
|
|
setopt PROMPT_SUBST
|
2022-03-18 14:34:27 +01:00
|
|
|
|
|
|
|
PROMPT="%B%F{${zsh_theme_colours[prompt]}}${showuser}%b"'${vcs_info_msg_0_}'"%B%F{${zsh_theme_colours[prompt]}}%#%f%b "
|
|
|
|
RPROMPT="%F{${zsh_theme_colours[minor]}}%(?..[%B%F{${zsh_theme_colours[highlight]}}%?%b%F{${zsh_theme_colours[minor]}}] )%4~%f"
|
|
|
|
|
|
|
|
}
|