-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathomz-git.plugin.zsh
46 lines (39 loc) · 1.63 KB
/
omz-git.plugin.zsh
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
function git_prompt_info() {
if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
ref="$(command echo ${ref#refs/heads/})"
length=${#ref}
maxLength=$(command git config --get oh-my-zsh.max-branch-length 2>/dev/null)
if [[ -z ${maxLength} ]]; then
maxLength=20
fi
if [[ ${length} -gt ${maxLength} ]]; then
regex=$(command git config --get oh-my-zsh.prefix-regex 2>/dev/null)
if [[ -n ${regex} ]]; then
ref=$(command echo ${ref} | sed "s/${regex}//1" ) #${regex})
fi
prefixLength=$(command git config --get oh-my-zsh.prefix-length 2>/dev/null)
if [[ -z ${prefixLength} ]]; then
prefixLength=0
fi
if [[ ${prefixLength} -gt 0 ]]; then
prefix=$(command echo ${ref} | cut -c ${prefixLength})
ref=$(command echo ${ref} | cut -c `expr ${prefixLength} + 1`-)
length=${#ref}
fi
fi
if [[ ${length} -gt ${maxLength} ]]; then
suffixLength=$(command git config --get oh-my-zsh.suffix-length 2>/dev/null)
if [[ -z ${suffixLength} ]]; then
suffixLength=0
fi
length=${#ref}
suffixStart=`expr ${length} - ${suffixLength} + 1`
separatorLength=3 #3 dots...
nameEnd=`expr ${maxLength} - ${suffixLength} - ${separatorLength}`
ref="$(command echo ${ref} | cut -c 1-${nameEnd})...$(command echo ${ref} | cut -c ${suffixStart}-)"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
fi
}