ohmyzsh/themes/pygmalion-virtualenv.zsh-theme
Eric Nielsen e8504ac49a Replace %{$fg[color]%} by %F{color} in themes
that only change the foreground color. %F works at least since Zsh 4.3.
2020-06-14 21:02:25 -05:00

49 lines
1.5 KiB
Bash

# Yay! High voltage and arrows!
function _virtualenv_prompt_info {
if [[ -n "$(whence virtualenv_prompt_info)" ]]; then
if [ -n "$(whence pyenv_prompt_info)" ]; then
if [ "$1" = "inline" ]; then
ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX=%F{blue}"::%F{red}"
ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX=""
virtualenv_prompt_info
fi
[ "$(pyenv_prompt_info)" = "${PYENV_PROMPT_DEFAULT_VERSION}" ] && virtualenv_prompt_info
else
virtualenv_prompt_info
fi
fi
}
prompt_setup_pygmalion(){
ZSH_THEME_GIT_PROMPT_PREFIX="%f%F{green}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%f "
ZSH_THEME_GIT_PROMPT_DIRTY="%F{yellow}⚡%f"
ZSH_THEME_GIT_PROMPT_CLEAN=""
base_prompt='$(_virtualenv_prompt_info)%F{magenta}%n%f%F{cyan}@%f%F{yellow}%m%f%F{red}:%f%F{cyan}%0~%f%F{red}|%f'
post_prompt='%F{cyan}⇒%f '
base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
autoload -U add-zsh-hook
add-zsh-hook precmd prompt_pygmalion_precmd
}
prompt_pygmalion_precmd(){
local gitinfo=$(git_prompt_info)
local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g")
local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
local prompt_length=${#exp_nocolor}
local nl=""
if [[ $prompt_length -gt 40 ]]; then
nl=$'\n%{\r%}';
fi
PROMPT="$base_prompt$gitinfo$nl$post_prompt"
}
prompt_setup_pygmalion