-
Notifications
You must be signed in to change notification settings - Fork 0
/
aperiodic.zsh-theme
182 lines (140 loc) · 4.95 KB
/
aperiodic.zsh-theme
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function precmd {
local TERMWIDTH
(( TERMWIDTH = ${COLUMNS} - 1 ))
###
# Truncate the path if it's too long.
PR_FILLBAR=""
PR_PWDLEN=""
local promptsize=${#${(%):---(%n@%m:%l)-----()}}
local pwdsize=${#${(%):-%~}}
local git_prompt_info_text=$(git_prompt_info)
local git_prompt_info_size=${#${git_prompt_info_text/git:}}
if [[ "$git_prompt_info_size" -gt 0 ]]; then
git_prompt_info_size=$(( git_prompt_info_size + 6 ))
else
git_prompt_info_size=-1
fi
local virtualenv_prompt_info_size=${#${VIRTUAL_ENV##*/}}
if [[ "$virtualenv_prompt_info_size" -gt 0 ]]; then
virtualenv_prompt_info_size=$(( virtualenv_prompt_info_size + 7 ))
else
virtualenv_prompt_info_size=-1
fi
local ruby_prompt_info_text=$(ruby_prompt_info)
local ruby_prompt_info_size=${#${${ruby_prompt_info_text/\(ruby-}/\)}}
if [[ "$ruby_prompt_info_size" -gt 0 ]]; then
ruby_prompt_info_size=$(( ruby_prompt_info_size + 7 ))
else
ruby_prompt_info_size=-1
fi
if [[ "$promptsize + $pwdsize + $git_prompt_info_size + $virtualenv_prompt_info_size + $ruby_prompt_info_size" -gt $TERMWIDTH ]]; then
((PR_PWDLEN=$TERMWIDTH - $promptsize - $git_prompt_info_size - $virtualenv_prompt_info_size - $ruby_prompt_info_size))
else
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize + $git_prompt_info_size + $virtualenv_prompt_info_size + $ruby_prompt_info_size)))..${PR_HBAR}.)}"
fi
###
# Get APM info.
if which ibam > /dev/null; then
PR_APM_RESULT=`ibam --percentbattery`
elif which apm > /dev/null; then
PR_APM_RESULT=`apm`
elif which pmset > /dev/null; then
PR_APM_RESULT=${$(pmset -g batt)[(w)8,(w)9]/;}
fi
}
setopt extended_glob
preexec () {
if [[ "$TERM" == "screen" ]]; then
local CMD=${1[(wr)^(*=*|sudo|-*)]}
echo -n "\ek$CMD\e\\"
fi
}
setprompt () {
###
# Need this so the prompt will work.
setopt prompt_subst
###
# Disable some already used prefix and suffix
unset ZSH_THEME_GIT_PROMPT_PREFIX
unset ZSH_THEME_GIT_PROMPT_SUFFIX
export VIRTUAL_ENV_DISABLE_PROMPT=1
###
# See if we can use colors.
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
(( count = $count + 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"
###
# Some fancy unicode characters
PR_ARROW=$'\u27A1'
PR_CHECKMARK=$'\u2714'
PR_CROSS=$'\u2718'
PR_VRBAR=$'\u251C'
PR_VLBAR=$'\u2524'
PR_HBAR=$'\u2500'
PR_URCORNER=$'\u256E'
PR_ULCORNER=$'\u256D'
PR_LRCORNER=$'\u256F'
PR_LLCORNER=$'\u2570'
###
# Decide if we need to set titlebar text.
case $TERM in
xterm*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
screen)
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
;;
*)
PR_TITLEBAR=''
;;
esac
###
# Decide whether to set a screen title
if [[ "$TERM" == "screen" ]]; then
PR_STITLE=$'%{\ekzsh\e\\%}'
else
PR_STITLE=''
fi
###
# APM detection
if which ibam > /dev/null; then
PR_APM='$PR_VLBAR$PR_RED${${PR_APM_RESULT[(f)1]}[(w)-2]}%%(${${PR_APM_RESULT[(f)3]}[(w)-1]})$PR_CYAN$PR_VRBAR$PR_HBAR'
elif which apm > /dev/null; then
PR_APM='$PR_VLBAR$PR_RED${PR_APM_RESULT[(w)5,(w)6]/\% /%%}$PR_CYAN$PR_VRBAR$PR_HBAR'
elif which pmset > /dev/null; then
PR_APM='$PR_VLBAR$PR_RED${PR_APM_RESULT/\%/%%}$PR_CYAN$PR_VRBAR$PR_HBAR'
else
PR_APM=''
fi
###
# Finally, the prompt.
PROMPT='$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_CYAN$PR_ULCORNER$PR_VLBAR\
%(!.$PR_RED%SROOT%s.$PR_GREEN%n)@%m:%l$PR_CYAN$PR_VRBAR\
${$(git_prompt_info):+"$PR_HBAR$PR_VLBAR${PR_LIGHT_GREEN}git:${$(git_prompt_info)/git:}$PR_CYAN$PR_VRBAR"}\
${VIRTUAL_ENV:+"$PR_HBAR$PR_VLBAR${PR_LIGHT_GREEN}venv:${VIRTUAL_ENV##*/}$PR_CYAN$PR_VRBAR"}\
${$(ruby_prompt_info):+"$PR_HBAR$PR_VLBAR${PR_LIGHT_GREEN}ruby:${${$(ruby_prompt_info)/\(ruby-/}/\)}$PR_CYAN$PR_VRBAR"}\
$PR_HBAR${(e)PR_FILLBAR}$PR_HBAR$PR_VLBAR\
$PR_LIGHT_GREEN%$PR_PWDLEN<...<%~%<<\
$PR_CYAN$PR_VRBAR$PR_URCORNER\
$PR_CYAN$PR_LLCORNER$PR_VLBAR\
%(?.${PR_LIGHT_GREEN}${PR_CHECKMARK} $PR_ARROW 0.$PR_LIGHT_RED$PR_CROSS $PR_ARROW %?)$PR_CYAN\
$PR_LIGHT_BLUE:%(!.$PR_RED.$PR_WHITE)%#$PR_CYAN$PR_VRBAR\
$PR_CYAN\
$PR_NO_COLOUR '
RPROMPT=' $PR_CYAN\
${(e)PR_APM}\
$PR_VLBAR$PR_YELLOW%D{%H:%M} - %D{%a %b %d}$PR_CYAN$PR_VRBAR$PR_LRCORNER$PR_NO_COLOUR'
PS2='$PR_CYAN$PR_HBAR\
$PR_CYAN$PR_HBAR$PR_VLBAR\
$PR_LIGHT_GREEN%_$PR_CYAN$PR_VRBAR$PR_HBAR\
$PR_CYAN$PR_NO_COLOUR '
}
setprompt