17eba9e46c3478d1f5840a477228216bd2844fbc

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merged pull request #308 from juanghurtado/master.

New prompt methods on Git lib file

Diff

 1diff --git a/lib/git.zsh b/lib/git.zsh
 2index 8512de8a40ba542e24d86be6e5c83c7245623875..e96f075beeb7efcfc23c6b7520bf7bc46e1e9430 100644
 3--- a/lib/git.zsh
 4+++ b/lib/git.zsh
 5@@ -4,7 +4,8 @@ function git_prompt_info() {
 6   echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
 7 }
 8 
 9-parse_git_dirty () {
10+# Checks if working tree is dirty
11+parse_git_dirty() {
12   if [[ -n $(git status -s 2> /dev/null) ]]; then
13     echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
14   else
15@@ -12,7 +13,24 @@ parse_git_dirty () {
16   fi
17 }
18 
19-# get the status of the working tree
20+# Checks if there are commits ahead from remote
21+function git_prompt_ahead() {
22+  if $(echo "$(git log origin/master..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
23+    echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
24+  fi
25+}
26+
27+# Formats prompt string for current git commit short SHA
28+function git_prompt_short_sha() {
29+  SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
30+}
31+
32+# Formats prompt string for current git commit long SHA
33+function git_prompt_long_sha() {
34+  SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
35+}
36+
37+# Get the status of the working tree
38 git_prompt_status() {
39   INDEX=$(git status --porcelain 2> /dev/null)
40   STATUS=""
41@@ -41,4 +59,4 @@ git_prompt_status() {
42     STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
43   fi
44   echo $STATUS
45-}
46+}