3bb5e97762ee764170cffa6cfd1d179a1ba92ff3

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(gentoo)!: use `vcs_info` to support other VCSs (#9440)

* prettify vcs infomation using `vcs_info`

* Show symbol when there are untracked files in git

Co-authored-by: freeyoung <ourbaozi@qq.com>

Diff

 1diff --git a/themes/gentoo.zsh-theme b/themes/gentoo.zsh-theme
 2index 5f2427c7ae736b67e873a02d44379ed5c9523302..ae3274022eb1b865f367490c0df4327a2ec8f901 100644
 3--- a/themes/gentoo.zsh-theme
 4+++ b/themes/gentoo.zsh-theme
 5@@ -1,8 +1,28 @@
 6-function prompt_char {
 7-	if [ $UID -eq 0 ]; then echo "#"; else echo $; fi
 8+autoload -Uz colors && colors
 9+
10+autoload -Uz vcs_info
11+zstyle ':vcs_info:*' check-for-changes true
12+zstyle ':vcs_info:*' unstagedstr '%F{red}*'   # display this when there are unstaged changes
13+zstyle ':vcs_info:*' stagedstr '%F{yellow}+'  # display this when there are staged changes
14+zstyle ':vcs_info:*' actionformats '%F{5}(%F{2}%b%F{3}|%F{1}%a%c%u%m%F{5})%f '
15+zstyle ':vcs_info:*' formats '%F{5}(%F{2}%b%c%u%m%F{5})%f '
16+zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
17+zstyle ':vcs_info:*' enable git cvs svn
18+zstyle ':vcs_info:git*+set-message:*' hooks untracked-git
19+
20++vi-untracked-git() {
21+  if command git status --porcelain 2>/dev/null | command grep -q '??'; then
22+    hook_com[misc]='%F{red}?'
23+  else
24+    hook_com[misc]=''
25+  fi
26+}
27+
28+gentoo_precmd() {
29+  vcs_info
30 }
31 
32-PROMPT='%(!.%{$fg_bold[red]%}.%{$fg_bold[green]%}%n@)%m %{$fg_bold[blue]%}%(!.%1~.%~) $(git_prompt_info)$(prompt_char)%{$reset_color%} '
33+autoload -U add-zsh-hook
34+add-zsh-hook precmd gentoo_precmd
35 
36-ZSH_THEME_GIT_PROMPT_PREFIX="("
37-ZSH_THEME_GIT_PROMPT_SUFFIX=") "
38+PROMPT='%(!.%B%F{red}.%B%F{green}%n@)%m %F{blue}%(!.%1~.%~) ${vcs_info_msg_0_}%(!.#.$)%{$reset_color%} '