-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathme.zsh-theme
74 lines (73 loc) · 2.87 KB
/
me.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
# the idea of this theme is to contain a lot of info in a small string, by
# compressing some parts and colorcoding, which bring useful visual cues,
# while limiting the amount of colors and such to keep it easy on the eyes.
# When a command exited >0, the timestamp will be in red and the exit code
# will be on the right edge.
# The exit code visual cues will only display once.
# (i.e. they will be reset, even if you hit enter a few times on empty command prompts)
typeset -A host_repr
# translate hostnames into shortened, colorcoded strings
host_repr=('dieter-ws-a7n8x-arch' "%{$fg_bold[green]%}ws" 'dieter-p4sci-arch' "%{$fg_bold[blue]%}p4")
# local time, color coded by last return code
time_enabled="%(?.%{$fg[red]%}.%{$fg[red]%})%*%{$reset_color%}"
time_disabled="%{$fg[red]%}%*%{$reset_color%}"
time=$time_enabled
# user part, color coded by privileges
local user="%(!.%{$fg[blue]%}.%{$fg[blue]%})%n%{$reset_color%}"
# Hostname part. compressed and colorcoded per host_repr array
# if not found, regular hostname in default color
local host="@${host_repr[$HOST]:-$HOST}%{$reset_color%}"
# Compacted $PWD
local pwd="%{$fg[yellow]%}%c%{$reset_color%}"
function cmtUp() {
[ ! -d .git ] && return
up="$( git log --oneline `git rev-parse --abbrev-ref --symbolic-full-name @{u}` ^HEAD | wc -l | sed -e 's/[[:space:]]//g')"
if [ $up -gt 0 ]; then
echo -n "%{$fg[red]%}"
echo -n '↓'
echo -n $up
echo -n "%{$reset_color%} "
fi
}
function cmtDwn() {
[ ! -d .git ] && return
local dwn="$( git log --oneline ^`git rev-parse --abbrev-ref --symbolic-full-name @{u}` HEAD | wc -l | sed -e 's/[[:space:]]//g')"
if [ $dwn -gt 0 ]; then
echo -n "%{$fg[red]%}"
echo -n '↑'
echo -n $dwn
echo -n "%{$reset_color%} "
fi
}
function gitModified() {
[ ! -d .git ] && return
if [ $( git status -s | wc -l ) -gt 0 ]; then
echo -n "%{$fg[green]%}"
echo -n '*'
echo -n "%{$reset_color%} "
fi
}
PROMPT='${time} ${pwd} $(git_prompt_info)$(gitModified)$(cmtDwn)$(cmtUp)$ '
# i would prefer 1 icon that shows the "most drastic" deviation from HEAD,
# but lets see how this works out
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}] %{$fg[yellow]%}%{$fg[green]%}%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="] %{$fg[green]%}"
# elaborate exitcode on the right when >0
return_code_enabled="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
return_code_disabled=
return_code=$return_code_enabled
RPS1='${return_code}'
function accept-line-or-clear-warning () {
if [[ -z $BUFFER ]]; then
time=$time_disabled
return_code=$return_code_disabled
else
time=$time_enabled
return_code=$return_code_enabled
fi
zle accept-line
}
zle -N accept-line-or-clear-warning
bindkey '^M' accept-line-or-clear-warning