-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzshrc
363 lines (301 loc) · 9.9 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# ============================================================================
# Path
# ============================================================================
path=(
"/usr/local/bin"
"/usr/bin"
"/bin"
"/usr/sbin"
"/sbin"
"$HOME/.bin"
"$GOBIN"
)
# ============================================================================
# Global
# ============================================================================
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
# Use emacs mode
bindkey -e
# ============================================================================
# Options
# ============================================================================
setopt no_beep
# Try to correct misspelled commands
setopt CORRECT
# Require exit or logout to exit a shell
setopt IGNORE_EOF
# Treat the ‘#’, ‘~’ and ‘^’ characters as part of patterns for filename
# generation
setopt EXTENDED_GLOB
# ============================================================================
# Completion
# ============================================================================
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH
fi
autoload -U compinit
compinit
# Matches case insensitive for lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# Pasting with tabs doesn't perform completion
zstyle ':completion:*' insert-tab pending
# Hack to get pass-insert-qr and pass-show-qr to use pass' default completions
compdef _pass_complete_entries pass-show-qr
compdef _pass_complete_entries_with_subdirs pass-insert-qr
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# ============================================================================
# Keybindings
# ============================================================================
# From man stty
# Enable (disable) START/STOP output control. Output from the system is
# stopped when the system receives STOP and started when the system
# receives START, or if ixany is set, any character restarts output.
#
# By default START/STOP are bound to ^S and ^Q conflicting with default zsh
# mappings.
stty -ixon
bindkey '\e[A' history-search-backward
bindkey '\e[B' history-search-forward
# ============================================================================
# Navigation
# ============================================================================
setopt auto_cd
cdpath=($HOME $PROJECTS)
# Exporting CDPATH is bad and can cause all sorts of problems so lets set
# CDPATH to something else and export that instead
export JUMP_DIRECTORIES=$CDPATH
# ============================================================================
# Editor
# ============================================================================
export VISUAL="/usr/local/bin/nvim"
export EDITOR="$VISUAL"
# ============================================================================
# History
# ============================================================================
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
setopt append_history
setopt extended_history
setopt hist_ignore_dups
setopt hist_verify
setopt inc_append_history
setopt share_history
setopt no_hist_beep
# ============================================================================
# Aliases
# ============================================================================
# ======
# ZSH
# ======
alias reload="source ~/.zshenv && source ~/.zshrc; echo 'sourced ~/.zshrc'"
# ======
# Editor
# ======
alias e=$VISUAL
alias vim=$EDITOR
# ======
# Git
# ======
alias g="git"
alias gs="git status"
alias gdf="git difftool"
# ======
# Cocoapods
# ======
alias p="pod install"
# ======
# Ruby
# ======
alias be="bundle exec"
alias b="bundle install -j4"
# ======
# Misc
# ======
# Clear the screen in tmux
alias cls=clear;tmux clear-history;
# Kill CoreAudio. Use this when volume controls stop working
alias canuke="sudo kill -9 `ps ax|grep 'coreaudio[a-z]' |awk '{print $1}'`"
alias cask="brew cask"
# ============================================================================
# Appearance
# ============================================================================
export HOMEBREW_NO_COLOR=1
theme() {
usage="theme <light|dark>"
new_style=""
case "$1" in
dark)
new_style="dark"
;;
light)
new_style="light"
;;
--help|-h)
echo "$usage"
return 0
;;
*)
echo "$usage" >&2
return 1
esac
if [ -n "$new_style" ]; then
ln -sf \
"$HOME/.config/kitty/${new_style}.conf" \
"$HOME/.config/kitty/theme.conf"
export THEME="$new_style"
fi
if [ -n "$TMUX" ]; then
kitty @ --to "$LISTEN_TO" \
set-colors --all --configured "$HOME/.config/kitty/theme.conf"
tmux set-environment THEME "$THEME"
tmux source-file "$HOME/.tmux.conf"
else
kitty @ \
set-colors --all --configured "$HOME/.config/kitty/theme.conf"
fi
if [ $(uname -s) = "Darwin" ]; then
if [ "$new_style" = "dark" ]; then
should_enable_darkmode="true"
else
should_enable_darkmode="false"
fi
osascript -e "tell application \"System Events\" \
to tell appearance preferences to set dark mode to \
$should_enable_darkmode"
fi
}
if [ $(uname -s) = "Darwin" ]; then
style=$(defaults read -g AppleInterfaceStyle 2> /dev/null)
if [ "$style" = "Dark" ]; then
export THEME=dark
else
export THEME=light
fi
fi
# ======
# PROMPT
# ======
autoload -U colors && colors
setopt prompt_subst
git_branch_color() {
if [ "$THEME" = "light" ]; then
echo "%{$fg_bold[black]%}"
elif [ "$THEME" = "dark" ]; then
echo "%{$fg_bold[white]%}"
else
echo "%{$fg_bold[black]%}"
fi
}
function git_prompt_info() {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
local DIRTY_COLOR
if parse_git_dirty; then
DIRTY_COLOR="$(git_branch_color)"
else
DIRTY_COLOR="%{$reset_color%}"
fi
echo " ${DIRTY_COLOR}${ref#refs/heads/}$(git_stash_info)"
}
function git_stash_info() {
stash_file="$( git rev-parse --git-dir )/logs/refs/stash"
if [[ -e "${stash_file}" ]]; then
while IFS='' read -r wcline || [[ -n "$wcline" ]]; do
((num_stashed++))
done < ${stash_file}
fi
if (( num_stashed > 0 )); then
printf " ⚑$num_stashed"
fi
}
function parse_git_dirty() {
local STATUS=''
local FLAGS
FLAGS=('--porcelain')
STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1)
if [[ -n $STATUS ]]; then
return 0
else
return 1
fi
}
function xcode_version_prompt_info() {
if [ -n "${XCODE_AUTO_VERSION+x}" ]; then
echo "🔨 $XCODE_AUTO_VERSION"
fi
}
function status_code_prompt_info() {
echo "%(?..%?)"
}
# Shows current working directory (up to 5 levels) in blue
# Git branch in red if dirty, otherwise green.
PROMPT='%(6~|%-1~/.../%2~|%5~)$(git_prompt_info) %{$reset_color%}%'
# Shows last return status in red if not zero
RPROMPT='$(xcode_version_prompt_info) $(status_code_prompt_info)'
# ============================================================================
# ASDF
# ============================================================================
source $HOME/.asdf/asdf.sh
source "$HOME/.asdf/completions/asdf.bash"
# ============================================================================
# bat
# ============================================================================
export BAT_THEME="GitHub"
# ============================================================================
# chxcode
# ============================================================================
source /usr/local/opt/chxcode/share/chxcode/chxcode
source /usr/local/opt/chxcode/share/chxcode/auto
# ============================================================================
# Autojump
# ============================================================================
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
# ============================================================================
# Fastlane
# ============================================================================
export [email protected]
# ============================================================================
# Elixir
# ============================================================================
export ERL_AFLAGS="-kernel shell_history enabled"
# ============================================================================
# Go
# ============================================================================
export GOPATH=$HOME/Developer/golang
export GOBIN=$GOPATH/bin
# ============================================================================
# dotenv
# ============================================================================
source_env() {
if [[ -f .env ]]; then
source .env
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd source_env
# ============================================================================
# GPG
# ============================================================================
GPG_TTY=$(tty)
export GPG_TTY
export GPGKEY=62C3F535
gpgconf --launch gpg-agent
# ============================================================================
# SSH
# ============================================================================
SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
export SSH_AUTH_SOCK
# Ensure SSH using a GPG key knows where to show pinentry
# https://www.gnupg.org/documentation/manuals/gnupg/Common-Problems.html
echo "UPDATESTARTUPTTY" | gpg-connect-agent > /dev/null 2>&1
# ============================================================================
# pass
# ============================================================================
export PASSWORD_STORE_ENABLE_EXTENSIONS=true
export PASSWORD_STORE_EXTENSIONS_DIR=/usr/local/lib/password-store/extensions
# ============================================================================
# Local
# ============================================================================
[ -f ~/.zshrc.local ] && source ~/.zshrc.local