Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 187 lines (163 sloc) 5.701 kb
63705e07 »
2012-04-14 Remove oh-my-zsh
1 autoload colors && colors
2
3 local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
4
5
6 ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[blue]%}[ "
7 ZSH_THEME_GIT_PROMPT_SUFFIX=" %{$fg[blue]%}] "
8 ZSH_THEME_GIT_PROMPT_DIRTY=": %{$fg[red]%}✗"
79dc3f78 »
2012-04-15 Prompt color tweaks
9 ZSH_THEME_GIT_PROMPT_CLEAN=": %{$fg[cyan]%}✔"
63705e07 »
2012-04-14 Remove oh-my-zsh
10
11 # Colors vary depending on time lapsed.
79dc3f78 »
2012-04-15 Prompt color tweaks
12 ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[cyan]%}"
63705e07 »
2012-04-14 Remove oh-my-zsh
13 ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
14 ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
79dc3f78 »
2012-04-15 Prompt color tweaks
15 ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[yellow]%}"
63705e07 »
2012-04-14 Remove oh-my-zsh
16
17 # get the name of the branch we are on
18 function git_prompt_info() {
19 ref=$(git symbolic-ref HEAD 2> /dev/null) || return
20 echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
21 }
22
23 # Checks if working tree is dirty
24 parse_git_dirty() {
25 if [[ -n $(git status -s 2> /dev/null) ]]; then
26 echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
27 else
28 echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
29 fi
30 }
31
32 # Checks if there are commits ahead from remote
33 function git_prompt_ahead() {
34 if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
35 echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
36 fi
37 }
38
39 # Formats prompt string for current git commit short SHA
40 function git_prompt_short_sha() {
41 SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
42 }
43
44 # Formats prompt string for current git commit long SHA
45 function git_prompt_long_sha() {
46 SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
47 }
48
49 # Get the status of the working tree
50 git_prompt_status() {
51 INDEX=$(git status --porcelain 2> /dev/null)
52 STATUS=""
53 if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
54 STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
55 fi
56 if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
57 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
58 elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
59 STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
60 fi
61 if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
62 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
63 elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
64 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
65 elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
66 STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
67 fi
68 if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
69 STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
70 fi
71 if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
72 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
73 elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
74 STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
75 fi
76 if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
77 STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
78 fi
79 echo $STATUS
80 }
81
82 # Determine the time since last commit. If branch is clean,
83 # use a neutral color, otherwise colors will vary according to time.
84 function git_time_since_commit() {
85 if git rev-parse --git-dir > /dev/null 2>&1; then
86 # Only proceed if there is actually a commit.
87 if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then
88 # Get the last commit.
89 last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
90 now=`date +%s`
91 seconds_since_last_commit=$((now-last_commit))
92
93 # Totals
94 MINUTES=$((seconds_since_last_commit / 60))
95 HOURS=$((seconds_since_last_commit/3600))
96
97 # Sub-hours and sub-minutes
98 DAYS=$((seconds_since_last_commit / 86400))
99 SUB_HOURS=$((HOURS % 24))
100 SUB_MINUTES=$((MINUTES % 60))
101
102 if [[ -n $(git status -s 2> /dev/null) ]]; then
103 if [ "$MINUTES" -gt 30 ]; then
104 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
105 elif [ "$MINUTES" -gt 10 ]; then
106 COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
107 else
108 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
109 fi
110 else
111 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
112 fi
113
114 if [ "$HOURS" -gt 24 ]; then
115 echo "$COLOR${DAYS}d"
116 elif [ "$MINUTES" -gt 60 ]; then
117 echo "$COLOR${HOURS}h${SUB_MINUTES}m"
118 else
119 echo "$COLOR${MINUTES}m"
120 fi
121 else
122 COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
123 echo "$COLOR"
124 fi
125 fi
126 }
127
128 # This keeps the number of todos always available the right hand side of my
129 # command line. I filter it to only count those tagged as "+next", so it's more
130 # of a motivation to clear out the list.
b989de9c »
2012-04-15 Adds support for todo-txt
131 todo_count(){
132 if $(which todo &> /dev/null)
63705e07 »
2012-04-14 Remove oh-my-zsh
133 then
07ab2238 »
2012-04-16 Adds notes, todo counts in RPROMPT
134 num=$(echo $(todo ls $1 | wc -l))
63705e07 »
2012-04-14 Remove oh-my-zsh
135 let todos=num-2
136 if [ $todos != 0 ]
137 then
138 echo "$todos"
139 else
140 echo ""
141 fi
142 else
143 echo ""
144 fi
145 }
146
07ab2238 »
2012-04-16 Adds notes, todo counts in RPROMPT
147 function todo_prompt() {
148 local COUNT=$(todo_count $1);
149 if [ $COUNT != 0 ]; then
150 echo "$1: $COUNT";
151 else
152 echo "";
153 fi
154 }
155
156 function notes_count() {
157 if [[ -z $1 ]]; then
158 local NOTES_PATTERN="TODO|FIXME|HACK";
159 else
160 local NOTES_PATTERN=$1;
161 fi
0e45a738 »
2012-04-16 Case insensitive notes lookup
162 grep -ERn "\b($NOTES_PATTERN)\b" {app,config,lib,spec,test} 2>/dev/null | wc -l | sed 's/ //g'
07ab2238 »
2012-04-16 Adds notes, todo counts in RPROMPT
163 }
164
165 function notes_prompt() {
166 local COUNT=$(notes_count $1);
167 if [ $COUNT != 0 ]; then
168 echo "$1: $COUNT";
169 else
170 echo "";
171 fi
172 }
173
174
79dc3f78 »
2012-04-15 Prompt color tweaks
175 export PROMPT='%{$fg[blue]%}%c \
63705e07 »
2012-04-14 Remove oh-my-zsh
176 $(git_prompt_info)\
177 $(git_time_since_commit)%{$reset_color%} \
79dc3f78 »
2012-04-15 Prompt color tweaks
178 %{$fg[white]%}%(!.#.⚡)%{$reset_color%} '
63705e07 »
2012-04-14 Remove oh-my-zsh
179
180 set_prompt () {
07ab2238 »
2012-04-16 Adds notes, todo counts in RPROMPT
181 export RPROMPT="$(notes_prompt TODO) %{$fg_bold[yellow]%}$(notes_prompt HACK)%{$reset_color%} %{$fg_bold[red]%}$(notes_prompt FIXME)%{$reset_color%} %{$fg_bold[white]%}$(todo_prompt +next)%{$reset_color%}"
63705e07 »
2012-04-14 Remove oh-my-zsh
182 }
183
b989de9c »
2012-04-15 Adds support for todo-txt
184 precmd() {
185 set_prompt
186 }
Something went wrong with that request. Please try again.