Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 87 lines (73 sloc) 3.245 kb
eb3d157 Made my them display the current rvm gemset and check for detached head
Christopher Chow authored
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)
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
2 $ '
458da58 Added my own theme.
Christopher Chow authored
3
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
4 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[white]%}"
458da58 Added my own theme.
Christopher Chow authored
5 ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
6
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
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
eb3d157 Made my them display the current rvm gemset and check for detached head
Christopher Chow authored
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
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
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`
50 now=`date +%s`
51 seconds_since_last_commit=$((now-last_commit))
52
53 # Totals
54 MINUTES=$((seconds_since_last_commit / 60))
55 HOURS=$((seconds_since_last_commit/3600))
56
57 # Sub-hours and sub-minutes
58 DAYS=$((seconds_since_last_commit / 86400))
59 SUB_HOURS=$((HOURS % 24))
60 SUB_MINUTES=$((MINUTES % 60))
61
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"
67 else
68 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
69 fi
70 else
71 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
72 fi
73
74 if [ "$HOURS" -gt 24 ]; then
eb3d157 Made my them display the current rvm gemset and check for detached head
Christopher Chow authored
75 echo "($(rvm_gemset)$COLOR${DAYS}d${SUB_HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
76 elif [ "$MINUTES" -gt 60 ]; then
eb3d157 Made my them display the current rvm gemset and check for detached head
Christopher Chow authored
77 echo "($(rvm_gemset)$COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
78 else
eb3d157 Made my them display the current rvm gemset and check for detached head
Christopher Chow authored
79 echo "($(rvm_gemset)$COLOR${MINUTES}m%{$reset_color%}|"
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
80 fi
81 else
82 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
eb3d157 Made my them display the current rvm gemset and check for detached head
Christopher Chow authored
83 echo "($(rvm_gemset)$COLOR~|"
051fb5f Added time since last commit to Soliah theme and changed some colours.
Christopher Chow authored
84 fi
85 fi
86 }
Something went wrong with that request. Please try again.