1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-21 11:01:31 +01:00

zsh: theme: avoid using functions where possible

includes fix for ohmyzsh's breaking change in ec1afe9d (async prompt)
This commit is contained in:
bretello 2024-04-05 13:08:21 +02:00
parent 56b8f1d05f
commit 7312c868b3
Signed by: brethil
GPG Key ID: 876AAC6290170FE7
2 changed files with 18 additions and 35 deletions

View File

@ -1,3 +1,5 @@
# vim:ft=zsh ts=2 sw=2 sts=2
local ret_status="%(?:%{$fg_bold[green]%}➜%{$reset_color%}:%{$fg[red]%}➜%{$reset_color%})"
local user="%(#:root@:)"
PROMPT='[%{$fg[red]%}${user}%M%{$reset_color%}][:%{$fg[green]%}%c%{$reset_color%}]$(git_prompt_info) ${ret_status} '

View File

@ -18,10 +18,7 @@ function user_prompt(){
fi
}
function job_prompt() {
# Shows jobs number on an orange background if there are background jobs
echo "%(1j.%B%K{202}%F{220} %j %k%b.)"
}
local job_prompt="%(1j.%B%K{202}%F{220} %j %k%b.)"
function shlvl_prompt() {
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
@ -32,14 +29,13 @@ function shlvl_prompt() {
fi
}
function path_prompt(){
# Shows last 3 items in path if there are more than 4
echo "[%F{green}%(4~:…/%3~:%~)%f]"
}
# TODO: add truncation using
# Shows last 3 items in path if there are more than 4
local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]'
# PREFIX/SUFFIX are added before/after `git_prompt_info`
ZSH_THEME_GIT_PROMPT_PREFIX="%f%{$fg[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_PREFIX=" %f%{$fg[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} |"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}%{$fg[red]%}x%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}%{$fg[green]%}√%{$reset_color%}"
@ -75,39 +71,24 @@ function virtualenv_info {
echo -n " $BOLD_PURPLE<$venv>$CLEAR "
}
function git_prompt() {
# prints git info if in a git repo
if ! git rev-parse --git-dir &>/dev/null; then
return
fi
echo " $(git_prompt_info) |$(git_prompt_status)$(git_remote_status)"
}
local git_prompt='$(git_prompt_info)$(git_prompt_status)$(git_remote_status)'
local return_code_RPS1='%(?..%B%F{88}-$?-%f%b)'
function return_code_RPS1() {
# red status code if last exit code is non-zero
echo "%(?..%B%F{88}-$?-%f%b)"
}
local success="%B%F{28} →%f%b"
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
local prompt_with_previous_return_status="%(?:$success:$failure) "
function prompt_with_previous_return_status() {
local success="%B%F{28} →%f%b"
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
echo "%(?:$success:$failure)"
}
function prompt_too_long(){
# prints a newline if more than $COLUMNS/2 characters have been printed
local newline=$'\n'
echo "%-$((COLUMNS/2))(l..${newline})"
}
# prints a newline if more than $COLUMNS/2 characters have been printed, see end of `man zshmisc`
local prompt_too_long='%-$((COLUMNS/2))(l..'$'\n'')'
## oh-my-zsh vi-mode plugins indicators:
export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background
export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green background
PROMPT='$(virtualenv_info)$(user_prompt)$(path_prompt)$(git_prompt)$(job_prompt)$(shlvl_prompt)$(prompt_too_long)$(prompt_with_previous_return_status) '
# put it all together
PROMPT='$(virtualenv_info)$(user_prompt)'"${path_prompt}${git_prompt}${job_prompt}"'$(shlvl_prompt)'"${prompt_too_long}${prompt_with_previous_return_status}"
# Right prompt is just return code and time
RPS1='$(return_code_RPS1)$(vi_mode_prompt_info)[%*]'
RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]'