-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
97 lines (77 loc) · 2.73 KB
/
zshrc
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
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt nomatch
unsetopt autocd beep
bindkey -e
autoload -U compinit && compinit
autoload -U colors && colors
setopt promptsubst
git_untracked_count() {
count=`echo $(git ls-files --other --exclude-standard | wc -l)`
if [ $count -eq 0 ]; then return; fi
echo " %{$fg_bold[yellow]%}?%{$fg_no_bold[white]%}:%{$reset_color$fg[yellow]%}$count%{$reset_color%}"
}
git_modified_count() {
count=`echo $(git ls-files -md | wc -l)`
if [ $count -eq 0 ]; then return; fi
echo " %{$fg_bold[red]%}M%{$fg_no_bold[white]%}:%{$reset_color$fg[red]%}$count%{$reset_color%}"
}
git_staged_count() {
count=`echo $(git diff-index --cached --name-only HEAD 2>/dev/null | wc -l)`
if [ $count -eq 0 ]; then return; fi
echo " %{$fg_bold[green]%}S%{$fg_no_bold[white]%}:%{$reset_color$fg[green]%}$count%{$reset_color%}"
}
git_branch() {
branch=$(git symbolic-ref HEAD --quiet 2> /dev/null)
if [ -z $branch ]; then
echo "%{$fg[yellow]%}$(git rev-parse --short HEAD)%{$reset_color%}"
else
echo "%{$fg[green]%}${branch#refs/heads/}%{$reset_color%}"
fi
}
git_remote_difference() {
branch=$(git symbolic-ref HEAD --quiet)
if [ -z $branch ]; then return; fi
remote=$(git remote show)
ahead_by=`echo $(git log --oneline $remote/${branch#refs/heads/}..HEAD 2> /dev/null | wc -l)`
behind_by=`echo $(git log --oneline HEAD..$remote/${branch#refs/heads/} 2> /dev/null | wc -l)`
output=""
if [ $ahead_by -gt 0 ]; then output="$output%{$fg_bold[white]%}↑%{$reset_color%}$ahead_by"; fi
if [ $behind_by -gt 0 ]; then output="$output%{$fg_bold[white]%}↓%{$reset_color%}$behind_by"; fi
echo $output
}
git_user() {
user=$(git config user.name)
if [ -z $user ]; then
echo "%{$fg_bold[red]%}no user%{$fg[white]%}@%{$reset_color%}"
else
echo "$user%{$fg[white]%}@%{$reset_color%}"
fi
}
in_git_repo() {
if [[ -d .git ]]; then
echo 0
else
echo $(git rev-parse --git-dir > /dev/null 2>&1; echo $?)
fi
}
git_prompt_info() {
if [[ $(in_git_repo) -gt 0 ]]; then return; fi
print " $(git_user)$(git_branch)$(git_remote_difference)$(git_staged_count)$(git_modified_count)$(git_untracked_count) "
}
simple_git_prompt_info() {
ref=$($(which git) symbolic-ref HEAD 2> /dev/null) || return
user=$($(which git) config user.name 2> /dev/null)
echo " (${user}@${ref#refs/heads/})"
}
export PROMPT='%{$fg_bold[blue]%}%n%{$reset_color%}@%{$fg[blue]%}%M %{$fg[green]%}%~%{$fg_bold[green]%}%% %{$reset_color%}'
export RPROMPT='$(git_prompt_info)%{$reset_color%}'
export CLICOLOR=1
export LSCOLORS=Gxfxbxdxcxegedabagacad
alias ls="ls -alh"
export VISUAL=vim
export EDITOR=vim
bindkey '^R' history-incremental-pattern-search-backward
bindkey '^N' vi-up-line-or-history
bindkey '^P' vi-down-line-or-history