-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzsh.zshrc
224 lines (168 loc) · 5.12 KB
/
zsh.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
#============================================================================#
# zsh confuguration
# Created by Konstantin Shulgin <[email protected]>
#============================================================================#
#----------------------------------------------------------------------------#
# utily functions
#----------------------------------------------------------------------------#
# check is application exists via 'witch' utility
function provided_in_env()
{
local bin=$1
if which $bin > /dev/null 2>&1; then
return 0
fi
return 1
}
#----------------------------------------------------------------------------#
# User enviroment settings
#----------------------------------------------------------------------------#
# zsh home directory
export ZSH_HOME=$HOME/.zsh
# Editor
export EDITOR=vim
# Path (add macports)
export PATH=$PATH:/opt/local/bin:/opt/local/sbin
# Man path (add macports)
export MANPATH=/opt/local/share/man:$MANPATH
# Set terminal type
export TERM=xterm-color
# Enable color in the terminal
export CLICOLOR=1
#-----------------------------------------------------------------------------#
# zsh mudules
#-----------------------------------------------------------------------------#
# Initialize colors
autoload -U colors; colors
# Initialize compinit
autoload -U compinit; compinit
#----------------------------------------------------------------------------#
# include completion
#----------------------------------------------------------------------------#
. ~/.zsh/completion
#-----------------------------------------------------------------------------#
# Load plugins and settings
#-----------------------------------------------------------------------------#
#
# Plugins loader
#
# load plugin from directory
function zsh_plugin_load()
{
local plugin_dir=$1
if [ ! -d $plugin_dir ];
then
return 1
fi
for ext in 'zsh' 'bash' 'sh'
do
local plugin_source=$plugin_dir/$(basename $plugin_dir).$ext
if [ -e $plugin_source ]
then
source $plugin_source
return 0
fi
done
echo "$plugin_dir's soruce not found"
return 1
}
# load all plugins from directory
function zsh_plugin_dir_load()
{
local plugins_dir=$1
if [ ! -d $plugins_dir ]; then
echo "'$plugins_dir' isn't directory";
return 1
fi
if [ ! "$(ls -A $plugins_dir)" ];
then
echo "'$plugins_dir' is empty"
return 1
fi
for plugin in $plugins_dir/*
do
zsh_plugin_load $plugin
done
}
# load all plugins
zsh_plugin_dir_load $ZSH_HOME/plugins
#
# Git plugin settings
#
# show dirty state in the branch
export GIT_PS1_SHOWDIRTYSTATE=true
#----------------------------------------------------------------------------#
# prompt settings
#----------------------------------------------------------------------------#
# Allow for functions in the prompt.
setopt PROMPT_SUBST
# Promt settings
PROMPT='%F{yellow}%n@%m%f:%F{cyan}%~%F{magenta}$(__git_ps1 "(%s)")%F{green}$%f '
#----------------------------------------------------------------------------#
# Colors
#----------------------------------------------------------------------------#
local dircolors_bin=""
for itr in 'dircolors' 'gdircolors'
do
if (provided_in_env $itr); then
dircolors_bin=$itr
break
fi
done
if [[ "$dircolors_bin" != "" ]]; then
eval $($dircolors_bin ~/.zsh/dir_colors)
fi
#----------------------------------------------------------------------------#
# Aliases
#----------------------------------------------------------------------------#
local platform=`uname`
if [[ "$platform" == "Linux" ]]; then
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ls='ls --color=auto'
alias dir='dir --color=auto'
else if [[ "$platform" == "Darwin" ]]
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
if (provided_in_env 'gls'); then
# gls provids by coreutils from macports
alias ls='gls --color=auto'
else
# gls doesn't exists, use BSD version
alias ls='ls -G'
fi
if (provided_in_env 'gdir'); then
# gls provids by coreutils from macports
alias dir='gdir --color=auto'
fi
fi
# lists
alias l='ls -CF'
alias la='ls -AL'
alias ll='ls -lF'
alias lla='ls -lsa'
# move-rename w/o correction and always in interactive mode
alias mv='nocorrect mv -i'
# recursize copy w/o correction and always in interactive mode
alias cp='nocorrect cp -iR'
# remove w/o correction and always in interactive mode
alias rm='nocorrect rm -i'
# create direcotory w/o correction
alias mkdir='nocorrect mkdir'
#----------------------------------------------------------------------------#
# History
#----------------------------------------------------------------------------#
# History file
HISTFILE=$ZSH_HOME/zsh_history
# Commands count histroy in history file
SAVEHIST=5000
# Commands count histroy in one seance
HISTSIZE=5000
# Append history list to the history file (important for multiple parallel zsh sessions!)
setopt APPEND_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_REDUCE_BLANKS
# zsh.zshrc is end here