-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
170 lines (125 loc) · 3.96 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
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
################
# EXPORTS #
################
export PATH="/Users/USERNAME/homebrew/bin:$PATH"
################
# NVM #
################
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
################
# AUTOCOMPLETE #
################
# enable autocomplete
autoload -U compinit && compinit
# case-insensitive (all),partial-word and then substring completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
################
# COLORS #
################
# enable colors
autoload -U colors && colors
# colors used in `ls`
export LSCOLORS="Gxfxcxdxbxegedabagacad"
################
# HISTORY #
################
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
################
# EDITOR #
################
# set editor
export EDITOR='vim'
################
# PROMPT #
################
setopt prompt_subst
#
# git
#
GIT_PROMPT_PREFIX="%{$fg[white]%}[%{$reset_color%}"
GIT_PROMPT_SUFFIX="%{$fg[white]%}]%{$reset_color%}"
GIT_PROMPT_AHEAD="%{$fg[cyan]%}↑NUM%{$reset_color%}"
GIT_PROMPT_BEHIND="%{$fg[cyan]%}↓NUM%{$reset_color%}"
GIT_PROMPT_MERGING="%{$fg[magenta]%}⚡︎%{$reset_color%}"
GIT_PROMPT_UNTRACKED="%{$fg[red]%}●%{$reset_color%}"
GIT_PROMPT_MODIFIED="%{$fg[yellow]%}●%{$reset_color%}"
GIT_PROMPT_STAGED="%{$fg[green]%}●%{$reset_color%}"
# show branch/tag or name-rev if on detached head
parse_git_branch() {
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
}
# show different symbols as appropriate for various repository states
parse_git_state() {
# compose value via multiple conditional appends
local GIT_STATE=""
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_AHEAD" -gt 0 ]; then
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
fi
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_BEHIND" -gt 0 ]; then
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
fi
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
fi
if ! git diff --cached --quiet 2> /dev/null; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
fi
if ! git diff --quiet 2> /dev/null; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
fi
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
fi
if [[ -n $GIT_STATE ]]; then
echo "$GIT_STATE"
fi
}
# prints branch and state if in git repository
git_prompt_string() {
local git_where="$(parse_git_branch)"
[ -n "$git_where" ] && echo "$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[cyan]%}${git_where#(refs/heads/|tags/)}%{$reset_color%}$GIT_PROMPT_SUFFIX"
}
# set left-hand prompt
PS1='%{$fg[cyan]%}%~ %{$fg[green]%}%#%{$reset_color%} '
# set right-hand prompt
RPS1='$(git_prompt_string)'
################
# FUNCTIONS #
################
# create directory and change to it
md() {
mkdir -p "$@" && cd "$@"
}
################
# ALIASES #
################
# use color in `grep`, add line numbers, search directories recursively, ignore vim binary files
alias grep='grep --binary-file=without-match --color --directories=recurse --line-number'
# always use color in `ls`
alias ls='ls -G'
alias la='ls -la'
# git
alias ga='git add'
alias gb='git branch'
alias gc='git commit'
alias gco='git checkout'
alias gd='git diff'
alias gdw='git diff --word-diff=color'
alias gl='git llog'
alias gm='git merge'
alias gr='git rm'
alias grb='git rebase'
alias grbc='git add . && git rebase --continue'
alias grbs='git rebase --skip'
alias gst='git status -s'
# do not allow scripts to automatically delete things for you
alias rm='rm -i'
# tmux
alias tmuxinit='~/.tmux/environments/default'