mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-21 19:11:30 +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:
parent
56b8f1d05f
commit
7312c868b3
|
@ -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 ret_status="%(?:%{$fg_bold[green]%}➜%{$reset_color%}:%{$fg[red]%}➜%{$reset_color%})"
|
||||||
local user="%(#:root@:)"
|
local user="%(#:root@:)"
|
||||||
PROMPT='[%{$fg[red]%}${user}%M%{$reset_color%}][:%{$fg[green]%}%c%{$reset_color%}]$(git_prompt_info) ${ret_status} '
|
PROMPT='[%{$fg[red]%}${user}%M%{$reset_color%}][:%{$fg[green]%}%c%{$reset_color%}]$(git_prompt_info) ${ret_status} '
|
||||||
|
|
|
@ -18,10 +18,7 @@ function user_prompt(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function job_prompt() {
|
local job_prompt="%(1j.%B%K{202}%F{220} %j %k%b.)"
|
||||||
# Shows jobs number on an orange background if there are background jobs
|
|
||||||
echo "%(1j.%B%K{202}%F{220} %j %k%b.)"
|
|
||||||
}
|
|
||||||
|
|
||||||
function shlvl_prompt() {
|
function shlvl_prompt() {
|
||||||
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
|
# Shows SHLVL on a magenta background if SHLVL > 1 (2 if in a tmux session)
|
||||||
|
@ -32,14 +29,13 @@ function shlvl_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function path_prompt(){
|
# TODO: add truncation using
|
||||||
# Shows last 3 items in path if there are more than 4
|
# Shows last 3 items in path if there are more than 4
|
||||||
echo "[%F{green}%(4~:…/%3~:%~)%f]"
|
local path_prompt='[%F{green}%(4~:…/%3~:%~)%f]'
|
||||||
}
|
|
||||||
|
|
||||||
# PREFIX/SUFFIX are added before/after `git_prompt_info`
|
# PREFIX/SUFFIX are added before/after `git_prompt_info`
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX="%f%{$fg[yellow]%} "
|
ZSH_THEME_GIT_PROMPT_PREFIX=" %f%{$fg[yellow]%} "
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} |"
|
||||||
|
|
||||||
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[white]%}%{$fg[red]%}x%{$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%}"
|
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[white]%}%{$fg[green]%}√%{$reset_color%}"
|
||||||
|
@ -75,39 +71,24 @@ function virtualenv_info {
|
||||||
echo -n " $BOLD_PURPLE<$venv>$CLEAR "
|
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() {
|
local success="%B%F{28} →%f%b"
|
||||||
# red status code if last exit code is non-zero
|
local failure="%B%{$fg[red]%} x%b%{$reset_color%}"
|
||||||
echo "%(?..%B%F{88}-$?-%f%b)"
|
local prompt_with_previous_return_status="%(?:$success:$failure) "
|
||||||
}
|
|
||||||
|
|
||||||
function prompt_with_previous_return_status() {
|
# prints a newline if more than $COLUMNS/2 characters have been printed, see end of `man zshmisc`
|
||||||
local success="%B%F{28} →%f%b"
|
local prompt_too_long='%-$((COLUMNS/2))(l..'$'\n'')'
|
||||||
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})"
|
|
||||||
}
|
|
||||||
|
|
||||||
## oh-my-zsh vi-mode plugins indicators:
|
## oh-my-zsh vi-mode plugins indicators:
|
||||||
export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background
|
export MODE_INDICATOR="[%B%K{red}nav%k%b]" # red background
|
||||||
export INSERT_MODE_INDICATOR="[%B%K{28}ins%k%b]" # green 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
|
# Right prompt is just return code and time
|
||||||
RPS1='$(return_code_RPS1)$(vi_mode_prompt_info)[%*]'
|
RPS1="${return_code_RPS1}"'$(vi_mode_prompt_info)[%*]'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user