From b20a23a3339a6844f0b9a581c911280d24f59817 Mon Sep 17 00:00:00 2001 From: Ayaz Badouraly <ayaz.badouraly@via.ecp.fr> Date: Wed, 14 Dec 2016 18:44:52 +0100 Subject: [PATCH] Adding coloring for untracked files and stash stack --- README.md | 2 ++ via.zsh-theme | 29 ++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a7aeefa..c26ca1d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Info |:------:|:--------------------------:|:-----------------------------:| | red | there are unstaged files | `OHMYVIA_VCS_UNSTAGED_COLOR` | | yellow | there are staged files | `OHMYVIA_VCS_STAGED_COLOR` | +| blue | stash stack is not empty | `OHMYVIA_VCS_STASH_COLOR` | +| cyan | there are untracked files | `OHMYVIA_VCS_UNTRACKED_COLOR` | | green | working directory is clean | `OHMYVIA_VCS_CLEAN_COLOR` | diff --git a/via.zsh-theme b/via.zsh-theme index 7e2f02d..ece5583 100644 --- a/via.zsh-theme +++ b/via.zsh-theme @@ -32,10 +32,33 @@ zstyle ':vcs_info:*' check-for-changes true local vcs_unstaged_color=${OHMYVIA_VCS_UNSTAGED_COLOR:-"$fg[red]"} local vcs_staged_color=${OHMYVIA_VCS_STAGED_COLOR:-"$fg[yellow]"} +local vcs_stash_color=${OHMYVIA_VCS_STASH_COLOR:-"$fg[blue]"} +local vcs_untracked_color=${OHMYVIA_VCS_UNTRACKED_COLOR:-"$fg[cyan]"} local vcs_clean_color=${OHMYVIA_VCS_CLEAN_COLOR:-"$fg[green]"} -zstyle ':vcs_info:*' stagedstr "%{$vcs_staged_color%}" zstyle ':vcs_info:*' unstagedstr "%{$vcs_unstaged_color%}" +zstyle ':vcs_info:*' stagedstr "%{$vcs_staged_color%}" + +# Thanks to https://github.com/sunaku/home/ +function +vi-git-untracked(){ + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \ + git status --porcelain | fgrep '??' &> /dev/null ; then + # This will show the marker if there are any untracked files in repo. + # If instead you want to show the marker only if there are untracked + # files in $PWD, use: + #[[ -n $(git ls-files --others --exclude-standard) ]] ; then + hook_com[misc]+="%{$vcs_untracked_color%}" + fi +} + +# Thanks to http://eseth.org/2010/git-in-zsh.html +function +vi-git-stash() { + if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then + hook_com[misc]+="%{$vcs_stash_color%}" + fi +} + +zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-stash # In normal formats and actionformats the following replacements are done: # %s : The VCS in use (git, hg, svn, etc.). @@ -50,8 +73,8 @@ zstyle ':vcs_info:*' unstagedstr "%{$vcs_unstaged_color%}" # %m : A "misc" replacement. It is at the discretion of the backend to decide what this replacement expands to. local vcs_formats_prefix=" %{$fg[magenta]%}(%{$fg[white]%}%s%{$fg[magenta]%})%{$reset_color%}" local vcs_formats_hyphen="%{$fg[yellow]%}-%{$reset_color%}" -local vcs_formats_normal="%{$fg[magenta]%}[%{$vcs_clean_color%}%c%u%b%{$fg[magenta]%}]%{$reset_color%}" -local vcs_formats_action="%{$fg[magenta]%}[%{$vcs_clean_color%}%c%u%b%{$fg[yellow]%}:%{$fg[red]%}%a%{$fg[magenta]%}]%{$reset_color%}" +local vcs_formats_normal="%{$fg[magenta]%}[%{$vcs_clean_color%}%m%c%u%b%{$fg[magenta]%}]%{$reset_color%}" +local vcs_formats_action="%{$fg[magenta]%}[%{$vcs_clean_color%}%m%c%u%b%{$fg[yellow]%}:%{$fg[red]%}%a%{$fg[magenta]%}]%{$reset_color%}" zstyle ':vcs_info:*' formats "$vcs_formats_prefix$vcs_formats_hyphen$vcs_formats_normal" zstyle ':vcs_info:*' actionformats "$vcs_formats_prefix$vcs_formats_hyphen$vcs_formats_action" -- GitLab