dotfiles/.config/zsh/tastytea.zsh-theme
2022-03-18 15:00:33 +01:00

138 lines
5.8 KiB
Bash

# -*- mode: shell-script; -*-
# Zsh theme. Changes prompt and syntax highlighting. Needs Zsh >= 5.0.0.
# Asynchronous prompt if zsh-async is detected, syntax highlighting if
# zsh-syntax-highlighting is detected.
function() # Keep local variables in here
{
# Make theme variables global for later use
typeset -gA zsh_theme_colours
zsh_theme_colours[prompt]="63" # violet
zsh_theme_colours[vcs]="97" # dark pink
zsh_theme_colours[highlight]="207" # bright pink
zsh_theme_colours[minor]="60" # dark violet
zsh_theme_colours[inactive]="236" # grey
[[ -n "${SSH_CONNECTION}" ]] && zsh_theme_colours[prompt]="yellow"
[[ $(id -u) -eq 0 ]] && zsh_theme_colours[prompt]="red"
# 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 "
zstyle ':vcs_info:*' stagedstr "%F{${zsh_theme_colours[highlight]}}●"
zstyle ':vcs_info:*' unstagedstr "%F{${zsh_theme_colours[highlight]}}○"
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
_my_vcs_async_start() {
async_start_worker vcs_info
async_register_callback vcs_info _my_vcs_info_done
}
_my_vcs_info() {
cd -q $1
vcs_info
print ${vcs_info_msg_0_}
}
_my_vcs_info_done() {
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
}
_my_vcs_chpwd() {
# 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]}}"
}
_my_vcs_precmd() {
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
setopt prompt_subst
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"
# <https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md>
if [[ -n "${ZSH_HIGHLIGHT_VERSION}" ]]; then
zsh_theme_colours[cmd]="213" # light pink
zsh_theme_colours[word]="172" # orange
zsh_theme_colours[misc]="81" # cyan
zsh_theme_colours[variable]="204" # salmon
zsh_theme_colours[quote]="76" # green
zsh_theme_colours[comment]="${zsh_theme_colours[minor]}"
zsh_theme_colours[error]="${zsh_theme_colours[highlight]}"
ZSH_HIGHLIGHT_STYLES[command]="fg=${zsh_theme_colours[cmd]}"
ZSH_HIGHLIGHT_STYLES[function]="fg=${zsh_theme_colours[cmd]}"
ZSH_HIGHLIGHT_STYLES[alias]="fg=${zsh_theme_colours[cmd]}"
ZSH_HIGHLIGHT_STYLES[builtin]="fg=${zsh_theme_colours[cmd]}"
ZSH_HIGHLIGHT_STYLES[precommand]="fg=${zsh_theme_colours[cmd]},underline"
ZSH_HIGHLIGHT_STYLES[arg0]="fg=${zsh_theme_colours[cmd]}"
ZSH_HIGHLIGHT_STYLES[reserved-word]="fg=${zsh_theme_colours[word]}"
ZSH_HIGHLIGHT_STYLES[commandseparator]="fg=${zsh_theme_colours[misc]}"
ZSH_HIGHLIGHT_STYLES[globbing]="fg=${zsh_theme_colours[misc]}"
ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]="fg=${zsh_theme_colours[misc]},bold"
ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]="fg=${zsh_theme_colours[misc]},bold"
ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]="fg=${zsh_theme_colours[misc]},bold"
ZSH_HIGHLIGHT_STYLES[redirection]="fg=${zsh_theme_colours[misc]}"
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=${zsh_theme_colours[misc]}'
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=${zsh_theme_colours[misc]}'
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=${zsh_theme_colours[misc]}'
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=${zsh_theme_colours[misc]}'
ZSH_HIGHLIGHT_STYLES[arithmetic-expansion]="fg=${zsh_theme_colours[variable]}"
ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]="fg=${zsh_theme_colours[variable]}"
ZSH_HIGHLIGHT_STYLES[history-expansion]="fg=${zsh_theme_colours[variable]}"
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=${zsh_theme_colours[variable]}"
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=${zsh_theme_colours[quote]}"
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=${zsh_theme_colours[quote]}"
ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]="fg=${zsh_theme_colours[quote]}"
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=${zsh_theme_colours[quote]}"
ZSH_HIGHLIGHT_STYLES[comment]="fg=${zsh_theme_colours[comment]}"
ZSH_HIGHLIGHT_STYLES[unknown-token]="fg=${zsh_theme_colours[error]},bold,standout"
ZSH_HIGHLIGHT_STYLES[bracket-error]="fg=${zsh_theme_colours[error]},bold,standout"
fi
}