-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc
322 lines (266 loc) · 6.6 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
OS=`uname`
HOST=`hostname`
# SSH check
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]
then
SSH=1
fi
source_envrc() {
rcfile=$HOME/.${ENV}rc
if [ -f $rcfile ]
then
source $rcfile
git config --global user.name $NAME
git config --global user.email $MAIL
git config --global user.signingkey $PGP_KEY
fi
}
# load environment
export ENV=`sh $HOME/.env.sh`
function chpwd {
prev_env=$ENV
export ENV=`sh $HOME/.env.sh | tr '[:upper:]' '[:lower:]'`
if [ $ENV != $prev_env ]
then
source_envrc
fi
}
# source it now
source_envrc
# locale
export LC_ALL=en_US.UTF-8
export LANG="$LC_ALL"
# misc options
unsetopt AUTO_CD
# allow colors
autoload -U colors && colors
# allow hooks
autoload -Uz add-zsh-hook
# vcs prompt (options must be set to empty to disable)
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:git*' formats ' (%b)'
add-zsh-hook -Uz precmd vcs_info
# history
HISTFILE=$HOME/.bash_history
HISTSIZE=5000
SAVEHIST=9001
setopt extended_history
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt hist_verify
setopt inc_append_history
setopt share_history
setopt extended_glob
# autocomplete
autoload -Uz compinit
compinit
compdef _gnu_generic cat
compdef _gnu_generic gcc
compdef _gnu_generic gdb
compdef _git git
setopt complete_in_word
# report cpu usage and time for long commands (seconds)
REPORTTIME=10
if [ $OS = "Linux" ]
then
compdef _pacman yay=pacman
fi
zstyle ':completion:*' completer _complete _ignored _approximate
zstyle ':completion:*' menu select
zstyle ':completion:*' group-name ''
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path $HOME/.cache/zsh
# delete key
bindkey "^[[3~" delete-char
# variables
if [ $OS = "Linux" ]
then
export XDG_CONFIG_HOME=$HOME/.config
# android
export ANDROID_HOME=/opt/android-sdk
ANDROID_PATH="$ANDROID_HOME/tools"
ANDROID_PATH="$ANDROID_HOME/tools/bin:$ANDROID_PATH"
ANDROID_PATH="$ANDROID_HOME/platform-tools:$ANDROID_PATH"
export PATH="$ANDROID_PATH:$PATH"
elif [ $OS = "Darwin" ]; then
# brew
export PATH="$HOME/.brew/bin:$PATH"
fi
# rust
export PATH="$HOME/.cargo/bin:$PATH"
# yarn
export PATH="$HOME/.yarn/bin:$PATH"
# global bin
export PATH="$HOME/bin:$PATH"
export EDITOR="nvim"
export GPG_TTY=$(tty)
export CLICOLOR=1
# prompt
P_EXIT='%(?..%F{red} [%?]%f)'
P_ENV='%F{blue} [${ENV}]%f'
P_TIME='%F{blue}%B%D{%L:%M %p}%b%f'
P_SSH=''
if [ "$SSH" = "1" ]
then
P_SSH=' > %F{cyan}ssh%f'
fi
P_USER='%F{red}%B%n%b%f'
P_HOST='%F{green}%B%U%m%u%b%f'
P_DIR='%F{magenta}%S%c%s%f'
P_GIT='%F{yellow}%B${vcs_info_msg_0_}%b%f'
export PROMPT="$P_EXIT$P_ENV $P_TIME$P_SSH > ${P_USER} $P_HOST > $P_DIR$P_GIT %# "
# window titles
if [ $OS = "Linux" ]
then
function xterm_precmd() {
print -Pn "\e]0;[%n@%M]%# \a"
}
function xterm_preexec() {
print -Pn "\e]0;[%n@%M]%# $1\a"
}
case $TERM in
*xterm*|rxvt*|(dt|k|E)term)
add-zsh-hook -Uz precmd xterm_precmd
add-zsh-hook -Uz preexec xterm_preexec
;;
esac
fi
# fortune
fortune $HOME/fortune
echo ""
# use proper terminal when on SSH
if [ "$SSH" = "1" ]
then
export TERM=xterm
fi
# show usage bar
if [ -f $HOME/.usage.sh ]
then
sh $HOME/.usage.sh
echo ""
fi
# weather (cached for 2 hours)
wttr=$HOME/.cache/weather
if [[ ! -f $wttr || -n `find $wttr -mmin +120` || `du -k $wttr | cut -f1` == 0 ]]
then
tput sc # save cursor
tput setaf 8 # gray
# placeholder while loaidng...
if [[ -f $wttr && `du -k $wttr | cut -f1` != 0 ]]
then
cat $wttr | sed 's/\x1b\[[0-9;]*m//g'
else
echo " ......... ------- "
echo " ......... --- °C "
echo " ......... - -- km/h "
echo " ......... -- km "
echo " ......... -.- mm "
fi
curl -s "wttr.in/Paris?0Q" --max-time 1 > $wttr
tput rc # reset cursor
tput ed # clear everything
fi
# if exists and > 0
if [[ -s $wttr ]]
then
cat $wttr
echo ""
fi
# reminders
if [ -f $HOME/.reminders ]
then
reminder_lines=`wc -l < $HOME/.reminders | tr -d ' \t\n\r\f'`
tput setaf 8 # gray
echo "--- You have [$reminder_lines] reminders"
tput setaf 7 # white
while read line; do
echo "*" $line
done < $HOME/.reminders
echo ""
fi
# aliases
alias dc="docker-compose"
alias fig="docker-compose"
alias vim="nvim"
alias k="kubectl"
alias size="du -ch -d 1 2>/dev/null | sort -h"
if [ $OS = "Linux" ]
then
alias make="make -j 8"
alias ff="firefox-developer-edition"
alias firefox-developer="firefox-developer-edition"
alias feh="feh -d" # Draw filename at the top of the feh window
alias ls="ls --color"
alias grep="grep --color"
alias eth="sudo ip link set enp0s31f6 up && sudo dhcpcd"
elif [ $OS = "Darwin" ]
then
alias sort="gsort"
alias make="gmake -j 8"
alias gpg="gpg2"
alias love="$HOME/bin/love.app/Contents/MacOS/love"
fi
# use the syntax highlight script
if [ $OS = "Linux" ]
then
# yay -S zsh-syntax-highlighting
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# yay -S zsh-autosuggestions
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
elif [ $OS = "Darwin" ]
then
# brew install zsh-syntax-highlighting
source /Users/$USER/.brew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# brew install zsh-autosuggestions
source /Users/$USER/.brew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
fi
# config for zsh-autosuggestions
ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd history completion)
# ssh-agent
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
ssh-agent > ~/.ssh-agent
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
eval "$(<~/.ssh-agent)" > /dev/null
fi
# NVM
export NVM_DIR="$HOME/.nvm"
if [ $OS = "Linux" ]
then
# commands
nvm_list=('node' 'npm' 'npx' 'yarn')
# global node_modules
nvm_list+=('glow' 'npm-check' 'svgo' 'jest-codemods' 'source-map-explorer')
# this tricks zsh-syntax-highlighting into thinking it exists
for item in $nvm_list
do
alias $item="nvm_init && $item"
done
# preload NVM executable only
source /usr/share/nvm/nvm.sh --no-use
# load NVM dynamically when needed
function nvm_init() {
[[ -n $NVM_BIN ]] && return
tput setaf 3 # yellow
printf "[nvm] Loading... "
t_start=$(date +%s%3N)
# source and perform `nvm use`
source /usr/share/nvm/init-nvm.sh
# removes the hack above, so that `which` gives us the correct output
for item in $nvm_list
do
unalias $item
done
# display the time it took to do all this
t_end=$(date +%s%3N)
t_total=$(($t_end-$t_start))
tput setaf 6 # cyan
printf "${t_total}ms"
echo ""
tput setaf 7 # white
}
fi
# <3 from lemon