Not for normies
| 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 | $ ' |
| 3 | |
| 4 | ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}" |
| 5 | ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})" |
| 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 | |
| 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 | if hash rvm 2>/dev/null; then |
| 36 | GEMSET=`rvm gemset list | grep '=>' | cut -b4-` |
| 37 | if [[ -n $GEMSET ]]; then |
| 38 | echo "%{$fg[yellow]%}$GEMSET%{$reset_color%}|" |
| 39 | fi |
| 40 | fi |
| 41 | } |
| 42 | |
| 43 | # Determine the time since last commit. If branch is clean, |
| 44 | # use a neutral color, otherwise colors will vary according to time. |
| 45 | function git_time_since_commit() { |
| 46 | if git rev-parse --git-dir > /dev/null 2>&1; then |
| 47 | # Only proceed if there is actually a commit. |
| 48 | if last_commit=`git -c log.showSignature=false log --pretty=format:'%at' -1 2> /dev/null`; then |
| 49 | now=`date +%s` |
| 50 | seconds_since_last_commit=$((now-last_commit)) |
| 51 | |
| 52 | # Totals |
| 53 | MINUTES=$((seconds_since_last_commit / 60)) |
| 54 | HOURS=$((seconds_since_last_commit/3600)) |
| 55 | |
| 56 | # Sub-hours and sub-minutes |
| 57 | DAYS=$((seconds_since_last_commit / 86400)) |
| 58 | SUB_HOURS=$((HOURS % 24)) |
| 59 | SUB_MINUTES=$((MINUTES % 60)) |
| 60 | |
| 61 | if [[ -n $(git status -s 2> /dev/null) ]]; then |
| 62 | if [ "$MINUTES" -gt 30 ]; then |
| 63 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG" |
| 64 | elif [ "$MINUTES" -gt 10 ]; then |
| 65 | COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM" |
| 66 | else |
| 67 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT" |
| 68 | fi |
| 69 | else |
| 70 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" |
| 71 | fi |
| 72 | |
| 73 | if [ "$HOURS" -gt 24 ]; then |
| 74 | echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|" |
| 75 | elif [ "$MINUTES" -gt 60 ]; then |
| 76 | echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|" |
| 77 | else |
| 78 | echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|" |
| 79 | fi |
| 80 | else |
| 81 | COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL" |
| 82 | echo "($(rvm_gemset)$COLOR~|" |
| 83 | fi |
| 84 | fi |
| 85 | } |