From c26323abd43ff7f4e83dda5e18e91ded5dcf702a Mon Sep 17 00:00:00 2001 From: Godwin Ko Date: Wed, 12 Oct 2011 12:05:33 +0800 Subject: [PATCH] add git stash indicator into git prompt --- lib/git.zsh | 11 ++++++++++- lib/theme-and-appearance.zsh | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index f04343650..c8138a6af 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -1,7 +1,7 @@ # get the name of the branch we are on function git_prompt_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$(parse_git_stash)$ZSH_THEME_GIT_PROMPT_SUFFIX" } # Checks if working tree is dirty @@ -13,6 +13,15 @@ parse_git_dirty() { fi } +# Checks if working tree has stash +parse_git_stash() { + if [[ -n $(git stash list 2> /dev/null) ]]; then + echo "$ZSH_THEME_GIT_PROMPT_STASH" + else + echo "$ZSH_THEME_GIT_PROMPT_NOSTASH" + fi +} + # Checks if there are commits ahead from remote function git_prompt_ahead() { if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index aec67721a..7fb2c01c6 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -30,6 +30,8 @@ ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of th ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean +ZSH_THEME_GIT_PROMPT_STASH="#" # Text to display if stash exists +ZSH_THEME_GIT_PROMPT_NOSTASH="" # Text to display if no stash exists # Setup the prompt with pretty colors setopt prompt_subst