Browse code

Added time since last commit to Soliah theme and changed some colours.

Christopher Chow authored on 03/02/2011 at 14:37:39
Showing 1 changed files
... ...
@@ -1,6 +1,63 @@
1
-PROMPT='%{$fg[blue]%}%B%20~%b%{$reset_color%}%{$(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)$(git_prompt_info)
2
+$ '
2 3
 
3
-ZSH_THEME_GIT_PROMPT_PREFIX="(%{$fg[green]%}"
4
+ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}"
4 5
 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
5
-ZSH_THEME_GIT_PROMPT_DIRTY="*%{$reset_color%}"
6 6
 
7
+# Text to display if the branch is dirty
8
+ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}" 
9
+
10
+# Text to display if the branch is clean
11
+ZSH_THEME_GIT_PROMPT_CLEAN="" 
12
+
13
+# Colors vary depending on time lapsed.
14
+ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
15
+ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
16
+ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
17
+ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
18
+
19
+# Determine the time since last commit. If branch is clean,
20
+# use a neutral color, otherwise colors will vary according to time.
21
+function git_time_since_commit() {
22
+    if git rev-parse --git-dir > /dev/null 2>&1; then
23
+        # Only proceed if there is actually a commit.
24
+        if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
25
+            # Get the last commit.
26
+            last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
27
+            now=`date +%s`
28
+            seconds_since_last_commit=$((now-last_commit))
29
+
30
+            # Totals
31
+            MINUTES=$((seconds_since_last_commit / 60))
32
+            HOURS=$((seconds_since_last_commit/3600))
33
+           
34
+            # Sub-hours and sub-minutes
35
+            DAYS=$((seconds_since_last_commit / 86400))
36
+            SUB_HOURS=$((HOURS % 24))
37
+            SUB_MINUTES=$((MINUTES % 60))
38
+            
39
+            if [[ -n $(git status -s 2> /dev/null) ]]; then
40
+                if [ "$MINUTES" -gt 30 ]; then
41
+                    COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
42
+                elif [ "$MINUTES" -gt 10 ]; then
43
+                    COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
44
+                else
45
+                    COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
46
+                fi
47
+            else
48
+                COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
49
+            fi
50
+
51
+            if [ "$HOURS" -gt 24 ]; then
52
+                echo "($COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
53
+            elif [ "$MINUTES" -gt 60 ]; then
54
+                echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
55
+            else
56
+                echo "($COLOR${MINUTES}m%{$reset_color%}|"
57
+            fi
58
+        else
59
+            COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
60
+            echo "($COLOR~|"
61
+        fi
62
+    fi
63
+}