-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
278 lines (235 loc) · 8.32 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
###################################################
# [BASIC SETTING] http://news.mynavi.jp/column/zsh/index.html
###################################################
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
## auto complete functions
# http://shigeya.org/blog/archives/2008/06/subversion-15-zsh-fix.html
fpath=(${ZDOTDIR}/function $HOME/.zsh/functions $fpath)
fpath=(/usr/local/share/zsh-completions(N-/) $fpath)
## auto complete smartly
autoload -Uz compinit
compinit -u
##################################################
# Version Controll System setting
#
# http://d.hatena.ne.jp/mollifier/20100906/p1
# http://d.hatena.ne.jp/yonchu/20120506/1336335973
##################################################
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn hg bzr
zstyle ':vcs_info:*' formats '%s,%u%c,%b'
zstyle ':vcs_info:*' actionformats '%s,%u%c,%b|%a'
zstyle ':vcs_info:(svn|bzr):*' branchformat '%b:r%r'
zstyle ':vcs_info:bzr:*' use-simple true
## Display git status
autoload -Uz is-at-least
if is-at-least 4.3.10; then
# status formats
zstyle ':vcs_info:git:*' check-for-changes true
zstyle ':vcs_info:(git|git-svn):*' stagedstr "+" # not commited
zstyle ':vcs_info:(git|git-svn):*' unstagedstr "-" # updated
zstyle ':vcs_info:git:*' formats '%s,%u%c,%b'
zstyle ':vcs_info:git:*' actionformats '%s,%u%c,%b|%a'
fi
## How to display on Prompt
function _update_vcs_info_msg() {
psvar=()
LANG=en_US.UTF-8 vcs_info
local _vcs_name _status _branch_action
if [ -n "$vcs_info_msg_0_" ]; then
_vcs_name=$(echo "$vcs_info_msg_0_" | cut -d , -f 1)
_status=$(_git_untracked_or_not_pushed $(echo "$vcs_info_msg_0_" | cut -d , -f 2))
_branch_action=$(echo "$vcs_info_msg_0_" | cut -d , -f 3)
psvar[1]="(${_vcs_name})-[${_status}${_branch_action}]"
fi
}
add-zsh-hook precmd _update_vcs_info_msg
# git status info function
# Untracked: ?
# not PUSHed: *
function _git_untracked_or_not_pushed() {
local git_status head remotes stagedstr
local staged_unstaged=$1 not_pushed="*" untracked="?"
# whether in git repository or not
if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" = "true" ]; then
# git status on simple formats
git_status=$(git status -s 2> /dev/null)
# ^?? line means the exist of untracked file(s)
if ! echo "$git_status" | grep "^??" > /dev/null 2>&1; then
untracked=""
fi
# get stagedstr
zstyle -s ":vcs_info:git:*" stagedstr stagedstr
# ^A line means the exists of staged files(s)
if [ -n "$stagedstr" ] && ! printf "$staged_unstaged" | grep "$stagedstr" > /dev/null 2>&1 \
&& echo "$git_status" | grep "^A" > /dev/null 2>&1; then
staged_unstaged=${staged_unstaged}${stagedstr}
fi
# get local HEAD hash
head=$(git rev-parse --verify -q HEAD 2> /dev/null)
if [ $? -eq 0 ]; then
# get array of remote HEAD hashes
remotes=($(git rev-parse --remotes 2> /dev/null))
if [ "$remotes[*]" ]; then
for x in ${remotes[@]}; do
# Remote hash array contains local hash
if [ "$head" = "$x" ]; then
# already pushed
not_pushed=""
break
fi
done
else
# Remote not exist
not_pushed=""
fi
else
# HEAD not exist (like just after git init)
not_pushed=""
fi
# output symbol(s) when untracked or unpushed file(s)
if [ -n "$staged_unstaged" -o -n "$untracked" -o -n "$not_pushed" ]; then
printf "${staged_unstaged}${untracked}${not_pushed}"
fi
fi
return 0
}
# Display VCS info on the right
RPROMPT="(%D{%Y/%m/%d %T}) %1(v|%F{green}%1v%2v%f|)"
###################################################
# Prompt
###################################################
case ${UID} in
0)
PROMPT="%B%F{red}%/D#%f%b "
PROMPT2="%B%F{red}%_#%f%b "
SPROMPT="%B%F{red}%r is correct? [n,y,a,e]:%f%b "
[ -n "${REMOTEHOST}${SSH_CONNECTION}" ] &&
PROMPT="%F{white}${HOST%%.*} ${PROMPT}"
;;
*)
PROMPT="%F{yellow}%/$%f "
PROMPT2="%F{yellow}%_$%f "
SPROMPT="%F{yellow}%r is correct? [n,y,a,e]:%f "
[ -n "${REMOTEHOST}${SSH_CONNECTION}" ] &&
PROMPT="%F{white}${HOST%%.*} ${PROMPT}"
;;
esac
###################################################
# Terminal
###################################################
case "${TERM}" in
kterm*|xterm)
precmd() {
echo -ne "\033]0;${USER}@${HOST%%.*}:${PWD}\007"
}
;;
esac
###################################################
# History
###################################################
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt hist_ignore_dups # ignore duplication command history list
setopt share_history # share command history data
setopt hist_ignore_space # start [space], no history
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey '^p' history-beginning-search-backward
bindkey '^n' history-beginning-search-forward
# bindkey '^r' history-incremental-search-backward
bindkey '^r' \
history-incremental-pattern-search-backward
bindkey '^s' \
history-incremental-pattern-search-forward
###################################################
# OTHER SETTINGS
###################################################
## vi like
#bindkey -v
## emac like
bindkey -e
## options
setopt auto_cd # auto cd
setopt auto_pushd # $ cd -[TAB]
setopt correct # command correction
setopt list_packed # compact ls
setopt nolistbeep # no beep sound
setopt noautoremoveslash # no omit directory/
## prediction
autoload predict-off
###################################################
# Aliases
###################################################
## enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
plugins=(git osx ruby)
## some more ls aliases
alias ll='ls -alFh'
alias la='ls -A'
alias l='ls -CF'
alias be='bundle exec'
alias k='kubectl'
alias g='git'
###################################################
# own setting
###################################################
[ -f $HOME/.zshrc_mine ] && source $HOME/.zshrc_mine
if [ -d $HOME/.anyenv/bin ]; then
eval "$(anyenv init -)"
for D in `ls $HOME/.anyenv/envs`
do
export PATH="$HOME/.anyenv/envs/$D/shims:$PATH"
done
fi
if [ -d /usr/local/anyenv/envs/rbenv/shims ]; then
export PATH="/usr/local/anyenv/envs/rbenv/shims:$PATH"
fi
alias screen='screen -U'
zstyle ':completion:*:sudo:*' command-path $PATH
umask 0002
##単語の区切り設定
autoload -Uz select-word-style
select-word-style default
zstyle ':zle:*' word-chars " =/;@{},|"
zstyle ':zle:*' word-style unspecified
# ^Dでzshを終了しない
setopt IGNORE_EOF
#^Q/^Sのフローコントロールを無効にする
setopt NO_FLOW_CONTROL
#beep音を鳴らさない
setopt NO_BEEP
zstyle ':completion:*:default' menu select=2
#Go
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
#node
export PATH=$PATH:./node_modules/.bin
#racket(lisp)
export PATH=$PATH:/Applications/Racket\ v6.7/bin
export PATH=$PATH:/usr/local/bin:/usr/bin
setopt EXTENDED_GLOB
#Ruby
# export PATH="$HOME/.rbenv/bin:$PATH"
# eval "$(rbenv init -)"
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/kazushigetominaga/Downloads/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/kazushigetominaga/Downloads/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/kazushigetominaga/Downloads/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/kazushigetominaga/Downloads/google-cloud-sdk/completion.zsh.inc'; fi
# for openapi generator
# export PATH=$PATH:~/bin/openapitools/