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 branch 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 -b"
46 while IFS
=$
'\n' read line
; do
47 if [[ "$line" == \
#\#\ * ]]; then
48 [[ "$line" =~
'## (.*?)(\.\.\.|$)' ]] && branch
=$match[1]
49 [[ "$line" =~
'ahead ([0-9]+)' ]] && ahead
=$match[1]
50 [[ "$line" =~
'behind ([0-9]+)' ]] && behind
=$match[1]
52 # Count added, deleted, modified, renamed, unmerged, untracked, dirty.
53 # T (type change) is undocumented, see http://git.io/FnpMGw.
55 [[ "$line" == M
[\ MTD
]\
* ]] && (( updated
++ ))
56 [[ "$line" == [AC
][\ MTD
]\
* ]] && (( added
++ ))
57 [[ "$line" == D
[\ MT
]\
* ]] && (( deleted
++ ))
58 [[ "$line" == R
[\ MTD
]\
* ]] && (( renamed
++ ))
61 [[ "$line" == [\ MARCT
]M\
* ]] && (( modified
++ ))
62 [[ "$line" == [\ MARCT
]D\
* ]] && (( deleted_wt
++ ))
63 [[ "$line" == \?\?\
* ]] && (( untracked
++ ))
66 [[ "$line" == (AA
|DD
|U?
|?U
)\
* ]] && (( unmerged
++ ))
68 done < <(${(z)status_cmd} 2> /dev
/null
)
70 local git_status
=" %{$fg[yellow]%}"
73 if [[ -n $branch ]]; then
76 git_status
+="$(git rev-parse --short HEAD 2> /dev/null)"
77 [[ $?
-ne 0 ]] && return
82 (( ahead
> 0 )) && upstream_str
+="%{$fg[blue]%} >$ahead"
83 (( behind
> 0 )) && upstream_str
+="%{$fg[blue]%} <$behind"
84 git_status
+="$upstream_str"
87 stashed
=$(git stash list | wc -l)
88 if (( stashed
> 0 )) then
89 stashed_str
+="%{$fg_bold[cyan]%} ⋎$stashed%{$reset_color%}"
91 git_status
+="$stashed_str"
95 (( updated
> 0 )) && index_str
+="%{$fg[green]%} *$updated"
96 (( added
> 0 )) && index_str
+="%{$fg[green]%} +$added"
97 (( deleted
> 0 )) && index_str
+="%{$fg[green]%} -$deleted"
98 (( renamed
> 0 )) && index_str
+="%{$fg[green]%} ≈$renamed"
99 git_status
+="$index_str"
101 # Format working tree
103 (( modified
> 0 )) && wt_str
+="%{$fg[red]%} *$modified"
104 (( deleted_wt
> 0 )) && wt_str
+="%{$fg[red]%} -$deleted_wt"
105 (( untracked
> 0 )) && wt_str
+="%{$fg[red]%} +$untracked"
106 (( unmerged
> 0 )) && wt_str
+="%{$fg[magenta]%} ♒$unmerged"
107 git_status
+="$wt_str"
109 git_status
+="%{$reset_color%}"
114 function virtualenv_prompt
() {
115 if [[ -z $VIRTUAL_ENV ]] then
118 echo "(${VIRTUAL_ENV##*/}) "
122 function print_if_fits
() {
125 zero
='%([BSUbfksu]|([FB]|){*})'
126 length
=${#${(S%%)1//$~zero/}}
127 echo "%-$length(l.$1.)"