fix(half-life): fix prompt color bleeding and code clean up (#10085)

Fixes #10085
Closes #10223

Co-authored-by: valdaarhun <icegambit91@gmail.com>
This commit is contained in:
Marc Cornellà 2021-09-30 15:23:11 +02:00
parent 5f99eb5afd
commit 72b8f0b73b
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -7,31 +7,22 @@
# git untracked files modification from Brian Carper: # git untracked files modification from Brian Carper:
# https://briancarper.net/blog/570/git-info-in-your-zsh-prompt # https://briancarper.net/blog/570/git-info-in-your-zsh-prompt
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
}
PR_GIT_UPDATE=1
setopt prompt_subst
autoload -U add-zsh-hook
autoload -Uz vcs_info
#use extended color palette if available #use extended color palette if available
if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then if [[ $TERM = (*256color|*rxvt*) ]]; then
turquoise="%F{81}" turquoise="%{${(%):-"%F{81}"}%}"
orange="%F{166}" orange="%{${(%):-"%F{166}"}%}"
purple="%F{135}" purple="%{${(%):-"%F{135}"}%}"
hotpink="%F{161}" hotpink="%{${(%):-"%F{161}"}%}"
limegreen="%F{118}" limegreen="%{${(%):-"%F{118}"}%}"
else else
turquoise="$fg[cyan]" turquoise="%{${(%):-"%F{cyan}"}%}"
orange="$fg[yellow]" orange="%{${(%):-"%F{yellow}"}%}"
purple="$fg[magenta]" purple="%{${(%):-"%F{magenta}"}%}"
hotpink="$fg[red]" hotpink="%{${(%):-"%F{red}"}%}"
limegreen="$fg[green]" limegreen="%{${(%):-"%F{green}"}%}"
fi fi
autoload -Uz vcs_info
# enable VCS systems you use # enable VCS systems you use
zstyle ':vcs_info:*' enable git svn zstyle ':vcs_info:*' enable git svn
@ -47,10 +38,10 @@ zstyle ':vcs_info:*:prompt:*' check-for-changes true
# %R - repository path # %R - repository path
# %S - path in the repository # %S - path in the repository
PR_RST="%{${reset_color}%}" PR_RST="%{${reset_color}%}"
FMT_BRANCH=" on %{$turquoise%}%b%u%c${PR_RST}" FMT_BRANCH=" on ${turquoise}%b%u%c${PR_RST}"
FMT_ACTION=" performing a %{$limegreen%}%a${PR_RST}" FMT_ACTION=" performing a ${limegreen}%a${PR_RST}"
FMT_UNSTAGED="%{$orange%} ●" FMT_UNSTAGED="${orange} ●"
FMT_STAGED="%{$limegreen%} ●" FMT_STAGED="${limegreen} ●"
zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}" zstyle ':vcs_info:*:prompt:*' unstagedstr "${FMT_UNSTAGED}"
zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}" zstyle ':vcs_info:*:prompt:*' stagedstr "${FMT_STAGED}"
@ -59,38 +50,44 @@ zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}"
zstyle ':vcs_info:*:prompt:*' nvcsformats "" zstyle ':vcs_info:*:prompt:*' nvcsformats ""
function steeef_preexec {
case "$2" in
*git*)
PR_GIT_UPDATE=1
;;
*svn*)
PR_GIT_UPDATE=1
;;
esac
}
add-zsh-hook preexec steeef_preexec
function steeef_chpwd { function steeef_chpwd {
PR_GIT_UPDATE=1 PR_GIT_UPDATE=1
} }
add-zsh-hook chpwd steeef_chpwd
function steeef_preexec {
case "$2" in
*git*|*svn*) PR_GIT_UPDATE=1 ;;
esac
}
function steeef_precmd { function steeef_precmd {
if [[ -n "$PR_GIT_UPDATE" ]] ; then (( PR_GIT_UPDATE )) || return
# check for untracked files or updated submodules, since vcs_info doesn't # check for untracked files or updated submodules, since vcs_info doesn't
if [[ ! -z $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then if [[ -n "$(git ls-files --other --exclude-standard 2>/dev/null)" ]]; then
PR_GIT_UPDATE=1 PR_GIT_UPDATE=1
FMT_BRANCH="${PM_RST} on %{$turquoise%}%b%u%c%{$hotpink%} ●${PR_RST}" FMT_BRANCH="${PM_RST} on ${turquoise}%b%u%c${hotpink} ●${PR_RST}"
else else
FMT_BRANCH="${PM_RST} on %{$turquoise%}%b%u%c${PR_RST}" FMT_BRANCH="${PM_RST} on ${turquoise}%b%u%c${PR_RST}"
fi fi
zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}" zstyle ':vcs_info:*:prompt:*' formats "${FMT_BRANCH}"
vcs_info 'prompt' vcs_info 'prompt'
PR_GIT_UPDATE= PR_GIT_UPDATE=
fi
} }
add-zsh-hook precmd steeef_precmd
PROMPT=$'%{$purple%}%n%{$reset_color%} in %{$limegreen%}%~%{$reset_color%}$(ruby_prompt_info " with%{$fg[red]%} " v g "%{$reset_color%}")$vcs_info_msg_0_%{$orange%} λ%{$reset_color%} ' # vcs_info running hooks
PR_GIT_UPDATE=1
autoload -U add-zsh-hook
add-zsh-hook chpwd steeef_chpwd
add-zsh-hook precmd steeef_precmd
add-zsh-hook preexec steeef_preexec
# ruby prompt settings
ZSH_THEME_RUBY_PROMPT_PREFIX="with%F{red} "
ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_RVM_PROMPT_OPTIONS="v g"
setopt prompt_subst
PROMPT="${purple}%n%{$reset_color%} in ${limegreen}%~%{$reset_color%}\$(ruby_prompt_info)\$vcs_info_msg_0_${orange} λ%{$reset_color%} "