1 # Setup the prompt with pretty colors
3 autoload colors
; colors
;
6 [[ $(hostname) == "tardis" ]] && hostcolor
=red
9 PROMPT
='%T %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 printf '%s' "%{${${KEYMAP/vicmd/$vicmd}/(main|viins)/$viins}%}"
20 function zle
-line-init zle
-line-finish zle
-keymap-select {
26 zle
-N zle
-line-finish
27 zle
-N zle
-keymap-select
31 zle
&& { zle
reset-prompt; zle
-R }
34 # Get the status of the working tree
36 local branch ahead behind
37 local added deleted modified renamed unmerged untracked dirty
38 # Use porcelain status for easy parsing.
39 local status_cmd
="git status --porcelain -b"
42 while IFS
=$
'\n' read line
; do
43 if [[ "$line" == \
#\#\ * ]]; then
44 [[ "$line" =~
'## ([^.]*)\.\.\.(.*)' ]] && branch
=$match[1]
45 [[ "$line" =~
'ahead ([0-9]+)' ]] && ahead
=$match[1]
46 [[ "$line" =~
'behind ([0-9]+)' ]] && behind
=$match[1]
48 # Count added, deleted, modified, renamed, unmerged, untracked, dirty.
49 # T (type change) is undocumented, see http://git.io/FnpMGw.
51 [[ "$line" == M
[\ MTD
]\
* ]] && (( updated
++ ))
52 [[ "$line" == [AC
][\ MTD
]\
* ]] && (( added
++ ))
53 [[ "$line" == D
[\ MT
]\
* ]] && (( deleted
++ ))
54 [[ "$line" == R
[\ MTD
]\
* ]] && (( renamed
++ ))
57 [[ "$line" == [\ MARCT
]M\
* ]] && (( modified
++ ))
58 [[ "$line" == [\ MARCT
]D\
* ]] && (( deleted_wt
++ ))
59 [[ "$line" == \?\?\
* ]] && (( untracked
++ ))
62 [[ "$line" == (AA
|DD
|U?
|?U
)\
* ]] && (( unmerged
++ ))
64 done < <(${(z)status_cmd} 2> /dev
/null
)
66 local git_status
=" %{$fg[yellow]%}"
69 if [[ -n $branch ]]; then
72 git_status
+="$(git rev-parse --short HEAD 2> /dev/null)"
73 [[ $?
-ne 0 ]] && return
78 (( ahead
> 0 )) && upstream_str
+="%{$fg[blue]%} >$ahead"
79 (( behind
> 0 )) && upstream_str
+="%{$fg[blue]%} <$behind"
80 git_status
+="$upstream_str"
83 stashed
=$(git stash list | wc -l)
84 if (( stashed
> 0 )) then
85 stashed_str
+="%{$fg_bold[cyan]%} ⋎$stashed%{$reset_color%}"
87 git_status
+="$stashed_str"
91 (( updated
> 0 )) && index_str
+="%{$fg[green]%} *$updated"
92 (( added
> 0 )) && index_str
+="%{$fg[green]%} +$added"
93 (( deleted
> 0 )) && index_str
+="%{$fg[green]%} -$deleted"
94 (( renamed
> 0 )) && index_str
+="%{$fg[green]%} ≈$renamed"
95 git_status
+="$index_str"
99 (( modified
> 0 )) && wt_str
+="%{$fg[red]%} *$modified"
100 (( deleted_wt
> 0 )) && wt_str
+="%{$fg[red]%} -$deleted_wt"
101 (( untracked
> 0 )) && wt_str
+="%{$fg[red]%} +$untracked"
102 (( unmerged
> 0 )) && wt_str
+="%{$fg[magenta]%} ♒$unmerged"
103 git_status
+="$wt_str"
105 git_status
+="%{$reset_color%}"
110 function print_if_fits
() {
113 zero
='%([BSUbfksu]|([FB]|){*})'
114 length
=${#${(S%%)1//$~zero/}}
115 echo "%-$length(l.$1.)"