1 # Setup the prompt with pretty colors
3 autoload colors
; colors
;
6 [[ $(hostname) == "tardis" ]] && hostcolor
=red
8 if (( ! $
+functions
[task_today_list
] )) then
9 function task_today_list
{}
13 PROMPT
=$
'%T $(task_today_list)%n@%{$fg[$hostcolor]%}%m$(jobs_prompt)%-0>..>$(git_prompt_status)%>>\n'
14 PROMPT
+=$
'$(virtualenv_prompt)%(?..%{$fg_bold[white]%}%?)%{$reset_color%}$(vi_prompt_info)%{%(!.$fg[red]❰.$fg[green]❱)%1G%} '
15 RPROMPT
='%{$fg[green]%}%~%{$reset_color%}'
19 printf '%s' "%(1j. $fg_bold[white]↵%{$fg_bold[red]%}%j.)%{$reset_color%}"
23 local vicmd
="$fg_bold[green]❰$reset_color%1G"
24 local viins
="$fg_bold[blue]❱$reset_color%1G"
25 local map
=${KEYMAP:-viins}
26 printf '%s' "%{${${map/vicmd/$vicmd}/(main|viins)/$viins}%}"
29 function zle
-line-init zle
-line-finish zle
-keymap-select {
34 # zle -N zle-line-init
35 # zle -N zle-line-finish
36 zle
-N zle
-keymap-select
40 zle
&& { zle
reset-prompt; zle
-R }
43 # Get the status of the working tree
45 if ! git
rev-parse --is-inside-work-tree &>/dev
/null
; then
48 local oid
head ahead behind
49 local added deleted modified renamed unmerged untracked dirty
50 # Use porcelain status for easy parsing.
51 local status_cmd
="git status --porcelain=v2 -b"
54 while IFS
=$
'\n' read line
; do
55 if [[ "$line" == \
#\ * ]]; then
56 [[ "$line" =~
'# branch.oid ([0-9a-f]+)' ]] && oid
=$match[1]
57 [[ "$line" =~
'# branch.head (.*)' ]] && head=$match[1]
58 [[ "$line" =~
'# branch.upstream (.*)' ]] && upstream
=$match[1]
59 [[ "$line" =~
'# branch.ab \+([0-9]+) -([0-9]+)' ]] && ahead
=$match[1] && behind
=$match[2]
61 # Count added, deleted, modified, renamed, unmerged, untracked, dirty.
62 # T (type change) is undocumented, see http://git.io/FnpMGw.
64 [[ "$line" == 1\ M
[.MTD
]\
* ]] && (( updated
++ ))
65 [[ "$line" == 1\
[AC
][.MTD
]\
* ]] && (( added
++ ))
66 [[ "$line" == 1\ D
[.MT
]\
* ]] && (( deleted
++ ))
67 [[ "$line" == 2\ R
[.MTD
]\
* ]] && (( renamed
++ ))
70 [[ "$line" == 1\
[.MARCT
]A\
* ]] && (( added
++ , modified
++ )) # intend-to-add
71 [[ "$line" == 1\
[.MARCT
]M\
* ]] && (( modified
++ ))
72 [[ "$line" == 1\
[.MARCT
]D\
* ]] && (( deleted_wt
++ ))
73 [[ "$line" == \?\
* ]] && (( untracked
++ ))
76 [[ "$line" == u\
(AA
|DD
|U?
|?U
)\
* ]] && (( unmerged
++ ))
78 #TODO more info for submodules?
80 done < <(${(z)status_cmd} 2> /dev
/null
)
84 # Format branch and commit
85 git_status
+="%{$fg_bold[green]%}$head"
86 git_status
+="%{$fg_no_bold[yellow]%}(${oid[1,8]})"
89 git_status
+="%{$fg[blue]%}"
90 [[ -z "$upstream" ]] && git_status
+=" Ɇ"
91 (( ahead
> 0 )) && git_status
+=" >$ahead"
92 (( behind
> 0 )) && git_status
+=" <$behind"
95 git_status
+="%{$fg_bold[blue]%}"
96 push_ab
=( $(git rev-list --left-right --count @...@{push} 2>/dev/null) )
97 if (( $?
== 0 )); then
98 (( push_ab
[1] > 0 )) && git_status
+=" ⮝$push_ab[1]"
99 (( push_ab
[2] > 0 )) && git_status
+=" ⮟$push_ab[2]"
103 git_status
+="%{$fg_bold[cyan]%}"
104 stashed
=$(git stash list | wc -l)
105 (( stashed
> 0 )) && git_status
+=" ⋎$stashed"
108 git_status
+="%{$fg_no_bold[green]%}"
109 (( updated
> 0 )) && git_status
+=" *$updated"
110 (( added
> 0 )) && git_status
+=" +$added"
111 (( deleted
> 0 )) && git_status
+=" -$deleted"
112 (( renamed
> 0 )) && git_status
+=" ≈$renamed"
114 # Format working tree
115 git_status
+="%{$fg_no_bold[red]%}"
116 (( modified
> 0 )) && git_status
+=" *$modified"
117 (( deleted_wt
> 0 )) && git_status
+=" -$deleted_wt"
118 (( untracked
> 0 )) && git_status
+=" +$untracked"
119 git_status
+="%{$fg_no_bold[magenta]%}"
120 (( unmerged
> 0 )) && git_status
+=" ♒$unmerged"
122 git_status
+="%{$reset_color%}"
127 function virtualenv_prompt
() {
128 if [[ -z $VIRTUAL_ENV ]] then
131 echo "(${VIRTUAL_ENV##*/}) "
135 function print_if_fits
() {
138 zero
='%([BSUbfksu]|([FB]|){*})'
139 length
=${#${(S%%)1//$~zero/}}
140 echo "%-$length(l.$1.)"