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 local branch ahead behind
38 local added deleted modified renamed unmerged untracked dirty
39 # Use porcelain status for easy parsing.
40 local status_cmd
="git status --porcelain -b"
43 while IFS
=$
'\n' read line
; do
44 if [[ "$line" == \
#\#\ * ]]; then
45 [[ "$line" =~
'## (.*?)(\.\.\.|$)' ]] && branch
=$match[1]
46 [[ "$line" =~
'ahead ([0-9]+)' ]] && ahead
=$match[1]
47 [[ "$line" =~
'behind ([0-9]+)' ]] && behind
=$match[1]
49 # Count added, deleted, modified, renamed, unmerged, untracked, dirty.
50 # T (type change) is undocumented, see http://git.io/FnpMGw.
52 [[ "$line" == M
[\ MTD
]\
* ]] && (( updated
++ ))
53 [[ "$line" == [AC
][\ MTD
]\
* ]] && (( added
++ ))
54 [[ "$line" == D
[\ MT
]\
* ]] && (( deleted
++ ))
55 [[ "$line" == R
[\ MTD
]\
* ]] && (( renamed
++ ))
58 [[ "$line" == [\ MARCT
]M\
* ]] && (( modified
++ ))
59 [[ "$line" == [\ MARCT
]D\
* ]] && (( deleted_wt
++ ))
60 [[ "$line" == \?\?\
* ]] && (( untracked
++ ))
63 [[ "$line" == (AA
|DD
|U?
|?U
)\
* ]] && (( unmerged
++ ))
65 done < <(${(z)status_cmd} 2> /dev
/null
)
67 local git_status
=" %{$fg[yellow]%}"
70 if [[ -n $branch ]]; then
73 git_status
+="$(git rev-parse --short HEAD 2> /dev/null)"
74 [[ $?
-ne 0 ]] && return
79 (( ahead
> 0 )) && upstream_str
+="%{$fg[blue]%} >$ahead"
80 (( behind
> 0 )) && upstream_str
+="%{$fg[blue]%} <$behind"
81 git_status
+="$upstream_str"
84 stashed
=$(git stash list | wc -l)
85 if (( stashed
> 0 )) then
86 stashed_str
+="%{$fg_bold[cyan]%} ⋎$stashed%{$reset_color%}"
88 git_status
+="$stashed_str"
92 (( updated
> 0 )) && index_str
+="%{$fg[green]%} *$updated"
93 (( added
> 0 )) && index_str
+="%{$fg[green]%} +$added"
94 (( deleted
> 0 )) && index_str
+="%{$fg[green]%} -$deleted"
95 (( renamed
> 0 )) && index_str
+="%{$fg[green]%} ≈$renamed"
96 git_status
+="$index_str"
100 (( modified
> 0 )) && wt_str
+="%{$fg[red]%} *$modified"
101 (( deleted_wt
> 0 )) && wt_str
+="%{$fg[red]%} -$deleted_wt"
102 (( untracked
> 0 )) && wt_str
+="%{$fg[red]%} +$untracked"
103 (( unmerged
> 0 )) && wt_str
+="%{$fg[magenta]%} ♒$unmerged"
104 git_status
+="$wt_str"
106 git_status
+="%{$reset_color%}"
111 function virtualenv_prompt
() {
112 if [[ -z $VIRTUAL_ENV ]] then
115 echo "(${VIRTUAL_ENV##*/}) "
119 function print_if_fits
() {
122 zero
='%([BSUbfksu]|([FB]|){*})'
123 length
=${#${(S%%)1//$~zero/}}
124 echo "%-$length(l.$1.)"