Convert Zsh prompt into a proper theme
Also make inactive colour a tiny bit brighter.
This commit is contained in:
parent
0eb8bd335a
commit
d82a8135de
|
@ -48,7 +48,7 @@ add-zsh-hook zshaddhistory _my_import_history_zshaddhistory
|
||||||
|
|
||||||
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
|
# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
|
||||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
|
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)
|
||||||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=236"
|
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=237"
|
||||||
|
|
||||||
for plugin in "${(@s/ /)ZSH_PLUGIN_DIST}"; do
|
for plugin in "${(@s/ /)ZSH_PLUGIN_DIST}"; do
|
||||||
[[ -n "${plugin}" ]] && source "${plugin}"
|
[[ -n "${plugin}" ]] && source "${plugin}"
|
||||||
|
@ -95,6 +95,7 @@ zstyle ':fzf-tab:complete:man:*' fzf-preview 'whatis -l $word | cut -d- -f2,3,4,
|
||||||
setopt AUTO_CD AUTO_PUSHD PUSHD_IGNORE_DUPS PUSHD_MINUS
|
setopt AUTO_CD AUTO_PUSHD PUSHD_IGNORE_DUPS PUSHD_MINUS
|
||||||
# Various options
|
# Various options
|
||||||
setopt CORRECT_ALL FLOW_CONTROL INTERACTIVE_COMMENTS LONG_LIST_JOBS REMATCH_PCRE
|
setopt CORRECT_ALL FLOW_CONTROL INTERACTIVE_COMMENTS LONG_LIST_JOBS REMATCH_PCRE
|
||||||
|
setopt PROMPT_SUBST
|
||||||
|
|
||||||
zmodload zsh/terminfo
|
zmodload zsh/terminfo
|
||||||
|
|
||||||
|
@ -147,18 +148,19 @@ case $(hostname) in
|
||||||
function sudo() {
|
function sudo() {
|
||||||
su -c "${*}"
|
su -c "${*}"
|
||||||
}
|
}
|
||||||
local DEFAULT_USER="u0_a197"
|
DEFAULT_USER="u0_a197"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ -f "${ZDOTDIR}"/keys.zsh ]] && source "${ZDOTDIR}"/keys.zsh
|
[[ -f "${ZDOTDIR}"/keys.zsh ]] && source "${ZDOTDIR}"/keys.zsh
|
||||||
[[ -f "${ZDOTDIR}"/aliases.zsh ]] && source "${ZDOTDIR}"/aliases.zsh
|
[[ -f "${ZDOTDIR}"/aliases.zsh ]] && source "${ZDOTDIR}"/aliases.zsh
|
||||||
[[ -d "${ZDOTDIR}"/functions ]] && autoload -Uz "${ZDOTDIR}"/functions/*
|
[[ -d "${ZDOTDIR}"/functions ]] && autoload -Uz "${ZDOTDIR}"/functions/*
|
||||||
|
|
||||||
local DEFAULT_USER="${DEFAULT_USER:-tastytea}"
|
|
||||||
[[ -f "${ZDOTDIR}"/themes/prompt.zsh ]] && source "${ZDOTDIR}"/themes/prompt.zsh
|
|
||||||
[[ -f "${ZDOTDIR}"/themes/syntax-unikitty-reversible.zsh ]] && source "${ZDOTDIR}"/themes/syntax-unikitty-reversible.zsh
|
[[ -f "${ZDOTDIR}"/themes/syntax-unikitty-reversible.zsh ]] && source "${ZDOTDIR}"/themes/syntax-unikitty-reversible.zsh
|
||||||
|
|
||||||
|
DEFAULT_USER="${DEFAULT_USER:-tastytea}"
|
||||||
|
autoload -U promptinit && promptinit
|
||||||
|
prompt tastytea
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ fi
|
||||||
|
|
||||||
if [[ -v 1 ]]; then
|
if [[ -v 1 ]]; then
|
||||||
local colour="201"
|
local colour="201"
|
||||||
[[ -v zsh_theme_colours ]] && colour=${zsh_theme_colours[highlight]}
|
|
||||||
print -Pnu2 "%B%F{${colour}}"
|
print -Pnu2 "%B%F{${colour}}"
|
||||||
print -u2 "${@}"
|
print -u2 "${@}"
|
||||||
print -Pnu2 "%f%b"
|
print -Pnu2 "%f%b"
|
||||||
|
|
157
.config/zsh/functions/prompt_tastytea_setup
Normal file
157
.config/zsh/functions/prompt_tastytea_setup
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
# tastytea prompt theme
|
||||||
|
# Asynchronous VCS info if zsh-async is detected.
|
||||||
|
|
||||||
|
prompt_tastytea_help () {
|
||||||
|
cat <<'EOF'
|
||||||
|
This prompt is colour-scheme-able. You can invoke it thus:
|
||||||
|
|
||||||
|
prompt tastytea [user [root [remote [vcs [path [highlight [inactive]]]]]]]
|
||||||
|
|
||||||
|
Set DEFAULT_USER to only show non-default users in prompt.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Reduce directory elements to first letter until directory path is reasonably
|
||||||
|
# short. Never shrink first element. Don't shrink relatively short elements. Try
|
||||||
|
# to not shrink last element.
|
||||||
|
function prompt_tastytea_shrunkpwd() {
|
||||||
|
local dir=${(D)PWD}
|
||||||
|
local -i max_width=$(( ${COLUMNS} / 3 ))
|
||||||
|
if [[ ${#dir} -le ${max_width} ]]; then
|
||||||
|
print -n ${dir}
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Maybe shorten all elements but the first and last
|
||||||
|
local -a short_dir=(${(s:/:)dir})
|
||||||
|
local -i allowed_element_width=$(( ${max_width} / ${#short_dir} - 1 ))
|
||||||
|
for index in {2..$(( ${#short_dir} - 1 ))}; do
|
||||||
|
if [[ ${#short_dir[index]} -gt ${allowed_element_width} ]]; then
|
||||||
|
[[ ${#${(j:/:)short_dir}} -le ${max_width} ]] && break
|
||||||
|
short_dir[index]=${short_dir[index][1]}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If the last element is too long, replace the mid-section with …
|
||||||
|
if [[ ${#short_dir[-1]} -gt ${allowed_element_width} ]]; then
|
||||||
|
local -i current_width=${#${(j:/:)short_dir}}
|
||||||
|
if [[ ${current_width} -gt ${max_width} ]]; then
|
||||||
|
local -i half_length=$(( ( ${max_width} - ( ${current_width} - ${#short_dir[-1]} ) ) / 2 - 1 ))
|
||||||
|
short_dir[-1]=${short_dir[-1][1,${half_length}]}"…"${short_dir[-1][$(( ${half_length} * -1 )),-1]}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
local out=${(j:/:)short_dir}
|
||||||
|
[[ ${out[1]} != '~' ]] && out[1]="/${out[1]}"
|
||||||
|
print -n ${out}
|
||||||
|
}
|
||||||
|
|
||||||
|
function prompt_tastytea_vcs() {
|
||||||
|
autoload -U vcs_info
|
||||||
|
zmodload zsh/zutil
|
||||||
|
|
||||||
|
zstyle ':vcs_info:*' enable git svn hg # vcs_info_printsys
|
||||||
|
zstyle ':vcs_info:*' formats "%F{${prompt_tastytea_colours[vcs]}}(%b)%u%c%f "
|
||||||
|
zstyle ':vcs_info:*' actionformats "%F{${prompt_tastytea_colours[vcs]}}(%b|%F{${prompt_tastytea_colours[highlight]}}%a%F{${prompt_tastytea_colours[vcs]}})%u%c%f "
|
||||||
|
zstyle ':vcs_info:*' stagedstr "%F{${prompt_tastytea_colours[highlight]}}●"
|
||||||
|
zstyle ':vcs_info:*' unstagedstr "%F{${prompt_tastytea_colours[highlight]}}○"
|
||||||
|
zstyle ':vcs_info:*' check-for-changes true
|
||||||
|
|
||||||
|
# Use asynchronous VCS prompt if zsh-async is available
|
||||||
|
if [[ -v ASYNC_VERSION ]]; then
|
||||||
|
[[ ${ASYNC_INIT_DONE} -eq 0 ]] && async_init
|
||||||
|
prompt_tastytea_vcs_async
|
||||||
|
else
|
||||||
|
add-zsh-hook precmd vcs_info
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Needs <https://github.com/mafredri/zsh-async>
|
||||||
|
function prompt_tastytea_vcs_async() {
|
||||||
|
# From https://vincent.bernat.ch/en/blog/2019-zsh-async-vcs-info
|
||||||
|
function prompt_tastytea_vcs_async_start() {
|
||||||
|
async_start_worker vcs_info
|
||||||
|
async_register_callback vcs_info prompt_tastytea_vcs_info_done
|
||||||
|
}
|
||||||
|
function prompt_tastytea_vcs_info() {
|
||||||
|
cd -q ${1}
|
||||||
|
vcs_info
|
||||||
|
print "${vcs_info_msg_0_}"
|
||||||
|
}
|
||||||
|
function prompt_tastytea_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
|
||||||
|
prompt_tastytea_vcs_async_start
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
vcs_info_msg_0_="${stdout}"
|
||||||
|
(( ${more} )) || zle reset-prompt
|
||||||
|
}
|
||||||
|
function prompt_tastytea_vcs_chpwd() {
|
||||||
|
# Change colour of old value
|
||||||
|
vcs_info_msg_0_="${vcs_info_msg_0_//\%F\{${prompt_tastytea_colours[vcs]}/%F{${prompt_tastytea_colours[inactive]}}"
|
||||||
|
vcs_info_msg_0_="${vcs_info_msg_0_//\%F\{${prompt_tastytea_colours[highlight]}/%F{${prompt_tastytea_colours[inactive]}}"
|
||||||
|
}
|
||||||
|
function prompt_tastytea_vcs_precmd() {
|
||||||
|
async_flush_jobs vcs_info
|
||||||
|
async_job vcs_info prompt_tastytea_vcs_info $PWD
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt_tastytea_vcs_async_start
|
||||||
|
autoload -U add-zsh-hook
|
||||||
|
add-zsh-hook precmd prompt_tastytea_vcs_precmd
|
||||||
|
add-zsh-hook chpwd prompt_tastytea_vcs_chpwd
|
||||||
|
}
|
||||||
|
|
||||||
|
function prompt_tastytea_setup() {
|
||||||
|
if [[ ${ZSH_VERSION[1]} -lt 5 ]]; then
|
||||||
|
print -u2 "This theme needs Zsh >= 5"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Needs to be global for async functions
|
||||||
|
typeset -gA prompt_tastytea_colours
|
||||||
|
prompt_tastytea_colours[user]="${1:-207}" # bright pink
|
||||||
|
prompt_tastytea_colours[root]="${2:-196}" # bright red
|
||||||
|
prompt_tastytea_colours[remote]="${3:-226}" # bright yellow
|
||||||
|
prompt_tastytea_colours[vcs]="${4:-97}" # dark pink
|
||||||
|
prompt_tastytea_colours[path]="${5:-61}" # dark violet
|
||||||
|
prompt_tastytea_colours[highlight]="${6:-201}" # pink
|
||||||
|
prompt_tastytea_colours[inactive]="${7:-237}" # grey
|
||||||
|
|
||||||
|
prompt_tastytea_colours[prompt]=${prompt_tastytea_colours[user]}
|
||||||
|
if [[ -v SSH_CONNECTION ]]; then
|
||||||
|
prompt_tastytea_colours[prompt]=${prompt_tastytea_colours[remote]}
|
||||||
|
fi
|
||||||
|
if [[ ${EUID} -eq 0 ]]; then
|
||||||
|
prompt_tastytea_colours[prompt]=${prompt_tastytea_colours[root]}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show username if it is not the default user
|
||||||
|
local showuser=""
|
||||||
|
if [[ "${USERNAME}" != "${DEFAULT_USER}" ]] && [[ -n "${USERNAME}" ]]; then
|
||||||
|
showuser="%B%F{${prompt_tastytea_colours[prompt]}}%n%f%b "
|
||||||
|
fi
|
||||||
|
|
||||||
|
prompt_tastytea_vcs
|
||||||
|
|
||||||
|
prompt_opts=(cr percent sp subst)
|
||||||
|
unset PROMPT RPROMPT RPROMPT2 RPS2
|
||||||
|
PS1="${showuser}"'${vcs_info_msg_0_}'"%B%F{${prompt_tastytea_colours[prompt]}}%#%f%b "
|
||||||
|
RPS1="%F{${prompt_tastytea_colours[path]}}%(?..[%B%F{${prompt_tastytea_colours[highlight]}}%?%b%F{${prompt_tastytea_colours[path]}}] )"'$(prompt_tastytea_shrunkpwd)'"%f"
|
||||||
|
PS2='%_> '
|
||||||
|
PS3='?# '
|
||||||
|
PS4='+%N:%i> '
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt_tastytea_setup "$@"
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: shell-script
|
||||||
|
# End:
|
|
@ -1,133 +0,0 @@
|
||||||
# Zsh prompt theme, needs Zsh >= 5.0.0. Asynchronous prompt if zsh-async is
|
|
||||||
# detected. Requires 256 colours.
|
|
||||||
|
|
||||||
function() # Keep local variables in here
|
|
||||||
{
|
|
||||||
|
|
||||||
# Make theme variables global for later use
|
|
||||||
typeset -gA zsh_theme_colours
|
|
||||||
zsh_theme_colours[prompt]="207" # bright pink
|
|
||||||
zsh_theme_colours[vcs]="97" # dark pink
|
|
||||||
zsh_theme_colours[highlight]="201" # pink
|
|
||||||
zsh_theme_colours[minor]="61" # dark violet
|
|
||||||
zsh_theme_colours[inactive]="236" # grey
|
|
||||||
|
|
||||||
# This will use potentially user defined colours
|
|
||||||
[[ -n "${SSH_CONNECTION}" ]] && zsh_theme_colours[prompt]="11" # bright yellow
|
|
||||||
[[ ${EUID} -eq 0 ]] && zsh_theme_colours[prompt]="9" # bright red
|
|
||||||
|
|
||||||
# Show username if it is not the default user
|
|
||||||
local showuser=""
|
|
||||||
if [[ "${USERNAME}" != "${DEFAULT_USER}" ]] && [[ -n "${USERNAME}" ]]; then
|
|
||||||
showuser="%B%F{${zsh_theme_colours[prompt]}}%n%f%b "
|
|
||||||
fi
|
|
||||||
|
|
||||||
autoload -Uz vcs_info
|
|
||||||
zmodload zsh/zutil
|
|
||||||
|
|
||||||
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 <https://github.com/mafredri/zsh-async>
|
|
||||||
function _async_vcs_prompt()
|
|
||||||
{
|
|
||||||
# From https://vincent.bernat.ch/en/blog/2019-zsh-async-vcs-info
|
|
||||||
function _my_vcs_async_start()
|
|
||||||
{
|
|
||||||
async_start_worker vcs_info
|
|
||||||
async_register_callback vcs_info _my_vcs_info_done
|
|
||||||
}
|
|
||||||
function _my_vcs_info()
|
|
||||||
{
|
|
||||||
cd -q ${1}
|
|
||||||
vcs_info
|
|
||||||
print "${vcs_info_msg_0_}"
|
|
||||||
}
|
|
||||||
function _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
|
|
||||||
}
|
|
||||||
function _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]}}"
|
|
||||||
}
|
|
||||||
function _my_vcs_precmd()
|
|
||||||
{
|
|
||||||
async_flush_jobs vcs_info
|
|
||||||
async_job vcs_info _my_vcs_info $PWD
|
|
||||||
}
|
|
||||||
|
|
||||||
_my_vcs_async_start
|
|
||||||
autoload -Uz add-zsh-hook
|
|
||||||
add-zsh-hook precmd _my_vcs_precmd
|
|
||||||
add-zsh-hook chpwd _my_vcs_chpwd
|
|
||||||
}
|
|
||||||
|
|
||||||
# Use asynchronous VCS prompt if zsh-async is available
|
|
||||||
if [[ -v ASYNC_VERSION ]]; then
|
|
||||||
[[ ${ASYNC_INIT_DONE} -eq 0 ]] && async_init
|
|
||||||
_async_vcs_prompt
|
|
||||||
else
|
|
||||||
add-zsh-hook precmd vcs_info
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Reduce directory elements to first letter until directory path is reasonably
|
|
||||||
# short. Never shrink first element. Don't shrink relatively short elements. Try
|
|
||||||
# to not shrink last element.
|
|
||||||
function _shrunkpwd()
|
|
||||||
{
|
|
||||||
local dir=${(D)PWD}
|
|
||||||
local -i max_width=$(( ${COLUMNS} / 3 ))
|
|
||||||
if [[ ${#dir} -le ${max_width} ]]; then
|
|
||||||
print -n ${dir}
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Maybe shorten all elements but the first and last
|
|
||||||
local -a short_dir=(${(s:/:)dir})
|
|
||||||
local -i allowed_element_width=$(( ${max_width} / ${#short_dir} - 1 ))
|
|
||||||
for index in {2..$(( ${#short_dir} - 1 ))}; do
|
|
||||||
if [[ ${#short_dir[index]} -gt ${allowed_element_width} ]]; then
|
|
||||||
[[ ${#${(j:/:)short_dir}} -le ${max_width} ]] && break
|
|
||||||
short_dir[index]=${short_dir[index][1]}
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# If the last element is too long, replace the mid-section with …
|
|
||||||
if [[ ${#short_dir[-1]} -gt ${allowed_element_width} ]]; then
|
|
||||||
local -i current_width=${#${(j:/:)short_dir}}
|
|
||||||
if [[ ${current_width} -gt ${max_width} ]]; then
|
|
||||||
local -i half_length=$(( ( ${max_width} - ( ${current_width} - ${#short_dir[-1]} ) ) / 2 - 1 ))
|
|
||||||
short_dir[-1]=${short_dir[-1][1,${half_length}]}"…"${short_dir[-1][$(( ${half_length} * -1 )),-1]}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
local out=${(j:/:)short_dir}
|
|
||||||
[[ ${out[1]} != '~' ]] && out[1]="/${out[1]}"
|
|
||||||
print -n ${out}
|
|
||||||
}
|
|
||||||
|
|
||||||
setopt PROMPT_SUBST
|
|
||||||
|
|
||||||
PROMPT="${showuser}"'${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]}}] )"'$(_shrunkpwd)'"%f"
|
|
||||||
|
|
||||||
}
|
|
|
@ -38,7 +38,7 @@ set -g mouse off
|
||||||
# THEME
|
# THEME
|
||||||
colour_status1="colour61" # violet
|
colour_status1="colour61" # violet
|
||||||
colour_status2="colour97" # dark pink
|
colour_status2="colour97" # dark pink
|
||||||
colour_inactive="colour236" # dark grey
|
colour_inactive="colour237" # dark grey
|
||||||
|
|
||||||
# Status line
|
# Status line
|
||||||
set -g status-style fg=${colour_status1}
|
set -g status-style fg=${colour_status1}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user