From 90da31c7958a79ea338730aca0dfdd4ec10cf547 Mon Sep 17 00:00:00 2001
From: Ayaz Badouraly <ayaz.badouraly@via.ecp.fr>
Date: Wed, 14 Dec 2016 00:02:56 +0100
Subject: [PATCH] Using vcs_info to gather info from vcs

---
 README.md     | 10 ++++++++++
 via.zsh-theme | 40 ++++++++++++++++++++++++----------------
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md
index b6982d5..52e0b74 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,16 @@ This is a theme for ZSH which mainly forks the historical theme used on
 ZSH frameworks such as [Oh-My-ZSH](https://github.com/robbyrussell/oh-my-zsh).
 
 
+Info
+----
+
+### VCS caption
+
+| Color | State |
+|:-----:|:-----:|
+| green | any   |
+
+
 Usage
 -----
 
diff --git a/via.zsh-theme b/via.zsh-theme
index 14c7ca5..df7c172 100644
--- a/via.zsh-theme
+++ b/via.zsh-theme
@@ -22,22 +22,30 @@ local current_dir="%{$fg_bold[green]%}%~%{$reset_color%}"
 
 PROMPT='${clock} ${user_host} ${current_dir}${eol} '
 
-# Display git info
-ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[magenta]%}(%{$fg[white]%}git%{$fg[magenta]%})%{$fg[yellow]%}-%{$fg[magenta]%}[%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[magenta]%}]%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}"
-ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
-
-custom_git_prompt_info () {
-	local ref
-	if [[ "$(command git config --get oh-my-zsh.hide-status 2> /dev/null)" != "1" ]]
-	then
-		ref=$(command git symbolic-ref HEAD 2> /dev/null)  || ref=$(command git rev-parse --short HEAD 2> /dev/null)  || return 0
-		echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(parse_git_dirty)${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_SUFFIX"
-	fi
-}
-
-RPROMPT='$(custom_git_prompt_info)'
+# Display vcs info
+autoload -Uz vcs_info
+
+zstyle ':vcs_info:*' enable git
+zstyle ':vcs_info:*' check-for-changes true
+
+# In normal formats and actionformats the following replacements are done:
+#	%s : The VCS in use (git, hg, svn, etc.).
+#	%b : Information about the current branch.
+#	%a : An identifier that describes the action. Only makes sense in actionformats.
+#	%i : The current revision number or identifier. For hg the hgrevformat style may be used to customize the output.
+#	%c : The string from the stagedstr style if there are staged changes in the repository.
+#	%u : The string from the unstagedstr style if there are unstaged changes in the repository.
+#	%R : The base directory of the repository.
+#	%r : The repository name. If %R is /foo/bar/repoXY, %r is repoXY.
+#	%S : A subdirectory within a repository. If $PWD is /foo/bar/repoXY/beer/tasty, %S is beer/tasty.
+#	%m : A "misc" replacement. It is at the discretion of the backend to decide what this replacement expands to.
+zstyle ':vcs_info:*' formats \
+	"%{$fg[magenta]%}(%{$fg[white]%}%s%{$fg[magenta]%})%{$fg[yellow]%}-%{$fg[magenta]%}[%{$fg[green]%}%b%{$fg[magenta]%}]%{$reset_color%}"
+zstyle ':vcs_info:*' actionformats \
+	"%{$fg[magenta]%}(%{$fg[white]%}%s%{$fg[magenta]%})%{$fg[yellow]%}-%{$fg[magenta]%}[%{$fg[green]%}%b%{$fg[yellow]%}:%{$fg[red]%}%a%{$fg[magenta]%}]%{$reset_color%}"
+
+precmd () { vcs_info }
+RPROMPT='${vcs_info_msg_0_}'
 
 # vim: ft=zsh fenc=utf-8
 
-- 
GitLab