-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm.zsh-theme
102 lines (85 loc) · 2.7 KB
/
m.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
# oh-my-zsh m Theme
### Git [master <> ●]
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[white]%}>%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[white]%}<%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg[green]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNSTAGED="%{$fg[red]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[yellow]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STASHED="%{$fg[cyan]%}●%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}]"
m_git_branch () {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
echo "${ref#refs/heads/}"
}
m_git_status1() {
# Show ahead/behind status
_INDEX=$(command git status -uno --porcelain -sb 2> /dev/null)
_STATUS=""
if $(echo "$_INDEX" | grep '^## .*behind' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_BEHIND"
fi
if $(echo "$_INDEX" | grep '^## .*ahead' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
if $(echo "$_INDEX" | grep '^## .*diverged' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_DIVERGED"
fi
# Prepend space if non empty
if [ "${_STATUS}x" != "x" ]; then
_STATUS=" $_STATUS"
fi
echo $_STATUS
}
m_git_status2 () {
# Show working copy/staged changes status
_INDEX=$(command git status -uno --porcelain -sb 2> /dev/null)
_STATUS=""
if $(echo "$_INDEX" | grep '^[AMRD]. ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STAGED"
fi
if $(echo "$_INDEX" | grep '^.[MTD] ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNSTAGED"
fi
if $(echo "$_INDEX" | grep '^UU ' &> /dev/null); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_UNMERGED"
fi
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
_STATUS="$_STATUS$ZSH_THEME_GIT_PROMPT_STASHED"
fi
# Prepend space if non empty
if [ "${_STATUS}x" != "x" ]; then
_STATUS=" $_STATUS"
fi
echo $_STATUS
}
m_git_prompt () {
local _branch=$(m_git_branch)
local _status="$(m_git_status1)$(m_git_status2)"
local _result=""
if [[ "${_branch}x" != "x" ]]; then
_result="[$_branch"
if [[ "${_status}x" != "x" ]]; then
_result="$_result$_status"
fi
_result="$_result$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
echo $_result
}
if [[ $(id -u) == 0 ]]; then
_LIBERTY="%{$fg[red]%}#%{$reset_color%}"
else
_LIBERTY="%{$fg[green]%}$%{$reset_color%}"
fi
# Add 'user@hostname' in ssh session
_USERNAME=""
if [[ -n $SSH_CONNECTION ]]; then
_USERNAME="%{$bg[white]%}%{$fg[black]%}%n@%m%{$reset_color%}:"
fi
_PATH="%{$fg_bold[white]%}%~%{$reset_color%}"
setopt prompt_subst
PROMPT='
$_USERNAME$_PATH
$_LIBERTY '
RPROMPT='$(m_git_prompt)'
autoload -U add-zsh-hook