Browse code

Adds new prompt methods on Git lib

Modifies the Git lib file (lib/git.zsh), adding three new prompt
methods:

- git_prompt_ahead(): Shows the content of the custom var
$ZSH_THEME_GIT_PROMPT_AHEAD if the local repository has
commits ahead from the remote origin repository

- git_prompt_short_sha(): Shows last commit SHA hash in short
mode wrapped between the content of the custom vars
$ZSH_THEME_GIT_PROMPT_SHA_BEFORE and
$ZSH_THEME_GIT_PROMPT_SHA_AFTER

- git_prompt_long_sha(): Shows last commit SHA hash in long
mode wrapped between the content of the custom vars
$ZSH_THEME_GIT_PROMPT_SHA_BEFORE and
$ZSH_THEME_GIT_PROMPT_SHA_AFTER

Juan G. Hurtado authored on 29/04/2011 at 07:22:56
Showing 1 changed files
... ...
@@ -4,7 +4,8 @@ function git_prompt_info() {
4 4
   echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
5 5
 }
6 6
 
7
-parse_git_dirty () {
7
+# Checks if working tree is dirty
8
+parse_git_dirty() {
8 9
   if [[ -n $(git status -s 2> /dev/null) ]]; then
9 10
     echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
10 11
   else
... ...
@@ -12,7 +13,24 @@ parse_git_dirty () {
12 12
   fi
13 13
 }
14 14
 
15
-# get the status of the working tree
15
+# Checks if there are commits ahead from remote
16
+function git_prompt_ahead() {
17
+  if $(echo "$(git log origin/master..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
18
+    echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
19
+  fi
20
+}
21
+
22
+# Formats prompt string for current git commit short SHA
23
+function git_prompt_short_sha() {
24
+  SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
25
+}
26
+
27
+# Formats prompt string for current git commit long SHA
28
+function git_prompt_long_sha() {
29
+  SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
30
+}
31
+
32
+# Get the status of the working tree
16 33
 git_prompt_status() {
17 34
   INDEX=$(git status --porcelain 2> /dev/null)
18 35
   STATUS=""
... ...
@@ -41,4 +59,4 @@ git_prompt_status() {
41 41
     STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
42 42
   fi
43 43
   echo $STATUS
44
-}
44
+}
45 45
\ No newline at end of file