Browse code

Merged pull request #297 from Soliah/master.

Updated my theme.

Robby Russell authored on 26/04/2011 at 16:45:48
Showing 1 changed files
... ...
@@ -1,4 +1,4 @@
1
-PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(git_prompt_info)
1
+PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(check_git_prompt_info)
2 2
 $ '
3 3
 
4 4
 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}"
... ...
@@ -16,6 +16,29 @@ ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
16 16
 ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
17 17
 ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
18 18
 
19
+
20
+# Git sometimes goes into a detached head state. git_prompt_info doesn't
21
+# return anything in this case. So wrap it in another function and check
22
+# for an empty string.
23
+function check_git_prompt_info() {
24
+    if git rev-parse --git-dir > /dev/null 2>&1; then
25
+        if [[ -z $(git_prompt_info) ]]; then
26
+            echo "%{$fg[magenta]%}detached-head%{$reset_color%})"
27
+        else
28
+            echo "$(git_prompt_info)"
29
+        fi
30
+    fi
31
+}
32
+
33
+# Determine if we are using a gemset.
34
+function rvm_gemset() {
35
+    GEMSET=`rvm gemset list | grep '=>' | cut -b4-`
36
+    if [[ -n $GEMSET ]]; then
37
+        echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|"
38
+    fi 
39
+
40
+}
41
+
19 42
 # Determine the time since last commit. If branch is clean,
20 43
 # use a neutral color, otherwise colors will vary according to time.
21 44
 function git_time_since_commit() {
... ...
@@ -49,15 +72,15 @@ function git_time_since_commit() {
49 49
             fi
50 50
 
51 51
             if [ "$HOURS" -gt 24 ]; then
52
-                echo "($COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
52
+                echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
53 53
             elif [ "$MINUTES" -gt 60 ]; then
54
-                echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
54
+                echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
55 55
             else
56
-                echo "($COLOR${MINUTES}m%{$reset_color%}|"
56
+                echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|"
57 57
             fi
58 58
         else
59 59
             COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
60
-            echo "($COLOR~|"
60
+            echo "($(rvm_gemset)$COLOR~|"
61 61
         fi
62 62
     fi
63 63
 }