-
Notifications
You must be signed in to change notification settings - Fork 8
/
zsh_prompt
70 lines (56 loc) · 1.92 KB
/
zsh_prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# heavily inspired by the wonderful pure theme
# https://github.com/sindresorhus/pure
# needed to get things like current git branch
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git # You can add hg too if needed: `git hg`
zstyle ':vcs_info:git*' use-simple true
zstyle ':vcs_info:git*' max-exports 2
zstyle ':vcs_info:git*' formats ' %b' 'x%R'
zstyle ':vcs_info:git*' actionformats ' %b|%a' 'x%R'
autoload colors && colors
git_dirty() {
# check if we're in a git repo
command git rev-parse --is-inside-work-tree &>/dev/null || return
# check if it's dirty
command git diff --quiet --ignore-submodules HEAD &>/dev/null;
if [[ $? -eq 1 ]]; then
echo "%F{red}✗%f"
else
echo "%F{green}✔%f"
fi
}
# get the status of the current branch and it's remote
# If there are changes upstream, display a ⇣
# If there are changes that have been committed but not yet pushed, display a ⇡
git_arrows() {
# do nothing if there is no upstream configured
command git rev-parse --abbrev-ref @'{u}' &>/dev/null || return
local arrows=""
local status
arrow_status="$(command git rev-list --left-right --count HEAD...@'{u}' 2>/dev/null)"
# do nothing if the command failed
(( !$? )) || return
# split on tabs
arrow_status=(${(ps:\t:)arrow_status})
local left=${arrow_status[1]} right=${arrow_status[2]}
(( ${right:-0} > 0 )) && arrows+="%F{011}⇣%f"
(( ${left:-0} > 0 )) && arrows+="%F{012}⇡%f"
echo $arrows
}
# indicate a job (for example, vim) has been backgrounded
# If there is a job in the background, display a ✱
suspended_jobs() {
local sj
sj=$(jobs 2>/dev/null | tail -n 1)
if [[ $sj == "" ]]; then
echo ""
else
echo "%{$FG[208]%}✱%f"
fi
}
precmd() {
vcs_info
print -P '\n%F{51}%~'
}
export PROMPT='%(?.%F{205}.%F{red})❯%f '
export RPROMPT='`git_dirty`%F{241}$vcs_info_msg_0_%f `git_arrows``suspended_jobs`'