1 # Setup the prompt with pretty colors
3 autoload colors
; colors
;
6 [[ $(hostname) == "tardis" ]] && hostcolor
=red
9 PROMPT
='%T $(virtualenv_prompt)%n@%{$fg[$hostcolor]%}%m%(1j. $fg_bold[white]↵%{$fg_bold[red]%}%j.)%{$reset_color%}%-0>..>$(git_prompt_status)%>>
10 %(?..%{$fg_bold[white]%}%?)%{$reset_color%}$(vi_prompt_info)%{%(!.$fg[red]❰.$fg[green]❱)%1G%} '
11 RPROMPT
='%{$fg[green]%}%~%{$reset_color%}'
15 local vicmd
="$fg_bold[green]❰$reset_color%1G"
16 local viins
="$fg_bold[blue]❱$reset_color%1G"
17 local map
=${KEYMAP:-viins}
18 printf '%s' "%{${${map/vicmd/$vicmd}/(main|viins)/$viins}%}"
21 function zle
-line-init zle
-line-finish zle
-keymap-select {
26 # zle -N zle-line-init
27 # zle -N zle-line-finish
28 zle
-N zle
-keymap-select
32 zle
&& { zle
reset-prompt; zle
-R }
35 # Get the status of the working tree
37 if ! git
rev-parse --is-inside-work-tree &>/dev
/null
; then
40 local oid
head ahead behind
41 local added deleted modified renamed unmerged untracked dirty
42 # Use porcelain status for easy parsing.
43 local status_cmd
="git status --porcelain=v2 -b"
46 while IFS
=$
'\n' read line
; do
47 if [[ "$line" == \
#\ * ]]; then
48 [[ "$line" =~
'# branch.oid ([0-9a-f]+)' ]] && oid
=$match[1]
49 [[ "$line" =~
'# branch.head (.*)' ]] && head=$match[1]
50 [[ "$line" =~
'# branch.ab \+([0-9]+) -([0-9]+)' ]] && ahead
=$match[1] && behind
=$match[2]
52 # Count added, deleted, modified, renamed, unmerged, untracked, dirty.
53 # T (type change) is undocumented, see http://git.io/FnpMGw.
55 [[ "$line" == 1\ M
[.MTD
]\
* ]] && (( updated
++ ))
56 [[ "$line" == 1\
[AC
][.MTD
]\
* ]] && (( added
++ ))
57 [[ "$line" == 1\ D
[.MT
]\
* ]] && (( deleted
++ ))
58 [[ "$line" == 2\ R
[.MTD
]\
* ]] && (( renamed
++ ))
61 [[ "$line" == 1\
[.MARCT
]M\
* ]] && (( modified
++ ))
62 [[ "$line" == 1\
[.MARCT
]D\
* ]] && (( deleted_wt
++ ))
63 [[ "$line" == \?\
* ]] && (( untracked
++ ))
66 [[ "$line" == u\
(AA
|DD
|U?
|?U
)\
* ]] && (( unmerged
++ ))
68 done < <(${(z)status_cmd} 2> /dev
/null
)
70 local git_status
=" %{$fg_bold[green]%}"
72 # Format branch and commit
73 git_status
+="$head%{$fg_no_bold[yellow]%}(${oid[1,8]})"
77 (( ahead
> 0 )) && upstream_str
+="%{$fg[blue]%} >$ahead"
78 (( behind
> 0 )) && upstream_str
+="%{$fg[blue]%} <$behind"
79 git_status
+="$upstream_str"
82 push_ab
=( $(git rev-list --left-right --count @...@{push} 2>/dev/null) )
83 if (( $?
== 0 )); then
84 (( push_ab
[1] > 0 )) && git_status
+="%{$fg_bold[blue]%} ⮝$push_ab[1]"
85 (( push_ab
[2] > 0 )) && git_status
+="%{$fg_bold[blue]%} ⮟$push_ab[2]"
89 stashed
=$(git stash list | wc -l)
90 if (( stashed
> 0 )) then
91 stashed_str
+="%{$fg_bold[cyan]%} ⋎$stashed%{$reset_color%}"
93 git_status
+="$stashed_str"
97 (( updated
> 0 )) && index_str
+="%{$fg[green]%} *$updated"
98 (( added
> 0 )) && index_str
+="%{$fg[green]%} +$added"
99 (( deleted
> 0 )) && index_str
+="%{$fg[green]%} -$deleted"
100 (( renamed
> 0 )) && index_str
+="%{$fg[green]%} ≈$renamed"
101 git_status
+="$index_str"
103 # Format working tree
105 (( modified
> 0 )) && wt_str
+="%{$fg[red]%} *$modified"
106 (( deleted_wt
> 0 )) && wt_str
+="%{$fg[red]%} -$deleted_wt"
107 (( untracked
> 0 )) && wt_str
+="%{$fg[red]%} +$untracked"
108 (( unmerged
> 0 )) && wt_str
+="%{$fg[magenta]%} ♒$unmerged"
109 git_status
+="$wt_str"
111 git_status
+="%{$reset_color%}"
116 function virtualenv_prompt
() {
117 if [[ -z $VIRTUAL_ENV ]] then
120 echo "(${VIRTUAL_ENV##*/}) "
124 function print_if_fits
() {
127 zero
='%([BSUbfksu]|([FB]|){*})'
128 length
=${#${(S%%)1//$~zero/}}
129 echo "%-$length(l.$1.)"