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)
4 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}"
5 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
7 # Text to display if the branch is dirty
8 ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
10 # Text to display if the branch is clean
11 ZSH_THEME_GIT_PROMPT_CLEAN=""
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]%}"
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%})"
28 echo "$(git_prompt_info)"
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%}|"
42 # Determine the time since last commit. If branch is clean,
43 # use a neutral color, otherwise colors will vary according to time.
44 function git_time_since_commit() {
45 if git rev-parse --git-dir > /dev/null 2>&1; then
46 # Only proceed if there is actually a commit.
47 if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
48 # Get the last commit.
49 last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
51 seconds_since_last_commit=$((now-last_commit))
54 MINUTES=$((seconds_since_last_commit / 60))
55 HOURS=$((seconds_since_last_commit/3600))
57 # Sub-hours and sub-minutes
58 DAYS=$((seconds_since_last_commit / 86400))
59 SUB_HOURS=$((HOURS % 24))
60 SUB_MINUTES=$((MINUTES % 60))
62 if [[ -n $(git status -s 2> /dev/null) ]]; then
63 if [ "$MINUTES" -gt 30 ]; then
64 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
65 elif [ "$MINUTES" -gt 10 ]; then
66 COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
68 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
71 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
74 if [ "$HOURS" -gt 24 ]; then
75 echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
76 elif [ "$MINUTES" -gt 60 ]; then
77 echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
79 echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|"
82 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
83 echo "($(rvm_gemset)$COLOR~|"