-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zsh_prompt
117 lines (101 loc) · 3.51 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function precmd {
# let's get the current get branch that we are under
# ripped from /etc/bash_completion.d/git from the git devs
git_ps1 () {
if which git &> /dev/null; then
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
if [ -d "$g/rebase-apply" ]; then
if test -f "$g/rebase-apply/rebasing"; then
r="|REBASE"
elif test -f "$g/rebase-apply/applying"; then
r="|AM"
else
r="|AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
elif [ -d "$g/rebase-merge" ]; then
r="|REBASE-m"
b="$(cat "$g/rebase-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"; then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"; then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
if [ -n "$1" ]; then
printf "$1" "${b##refs/heads/}$r"
else
printf "%s" " ${b##refs/heads/}$r"
fi
fi
else
printf ""
fi
}
PR_GIT="$(git_ps1)"
# The following 9 lines of code comes directly from Phil!'s ZSH prompt
# http://aperiodic.net/phil/prompt/
local TERMWIDTH
(( TERMWIDTH = ${COLUMNS} - 1 ))
local PROMPTSIZE=${#${(%):--- %D{%R.%S %a %b %d %Y}\! }}
local PWDSIZE=${#${(%):-%~}}
if [[ "$PROMPTSIZE + $PWDSIZE" -gt $TERMWIDTH ]]; then
(( PR_PWDLEN = $TERMWIDTH - $PROMPTSIZE ))
fi
# set a simple variable to show when in screen
if [[ -n "${WINDOW}" ]]; then
PR_SCREEN=" S:${WINDOW}"
else
PR_SCREEN=""
fi
# check if jobs are executing
if [[ $(jobs | wc -l) -gt 0 ]]; then
PR_JOBS=" J:%j"
else
PR_JOBS=""
fi
}
# If I am using vi keys, I want to know what mode I'm currently using.
# zle-keymap-select is executed every time KEYMAP changes.
# From http://zshwiki.org/home/examples/zlewidgets
function zle-keymap-select {
VIMODE="${${KEYMAP/vicmd/ M:command}/(main|viins)/}"
zle reset-prompt
}
zle -N zle-keymap-select
setprompt () {
# Need this, so the prompt will work
setopt prompt_subst
# let's load colors into our environment, then set them
autoload colors
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
# The variables are wrapped in %{%}. This should be the case for every
# variable that does not contain space.
for COLOR in RED GREEN YELLOW BLUE WHITE BLACK MAGENTA GREY; do
eval PR_$COLOR='%{$fg_no_bold[${(L)COLOR}]%}'
eval PR_BOLD_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
done
# Finally, let's set the prompt
PROMPT='
${PR_MAGENTA}%~\
${PR_BOLD_BLUE}${PR_SCREEN}${PR_JOBS}${PR_GIT}\
${PR_BOLD_GREY} →\
%{${reset_color}%} '
}
RPROMPT=""
setprompt