-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
356 lines (296 loc) · 12.4 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
# ****************************************************************************************************
# Attempt to handle errors during .zshrc via exit 0
# ****************************************************************************************************
error_handler() {
echo "An error occurred in .zshrc"
exit 0
}
trap error_handler ERR
# ****************************************************************************************************
# Setup environment
# ****************************************************************************************************
# NOTE: We export all of our variables due to the WSL workaround of `exec zsh` from bash.exe
export CC=gcc
export LANG=en_US.UTF-8
export TERMINAL='xterm-256color'
export GPG_TTY=$TTY
export HISTSIZE=1000000000
export SAVEHIST=1000000000
export HISTFILE=$HOME/.zsh_history
export XDG_CONFIG_HOME="$HOME/.config"
export XAUTHORITY="$HOME/.Xauthority"
export TZ='America/Los_Angeles'
# Don't mess with DISPLAY on macOS so we don't break XQuartz
if [[ "$OSTYPE" != "darwin"* ]]; then
export DISPLAY=localhost:10.0
fi
# ****************************************************************************************************
# Set telemetry opt-outs
# ****************************************************************************************************
export HOMEBREW_NO_ANALYTICS=1
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export POWERSHELL_TELEMETRY_OPTOUT=1
export NPM_CONFIG_TELEMETRY=0
export DISABLE_NPM_USAGE_METRICS=1
export VSCODE_TELEMETRY_OPTOUT=true
export GOOGLE_ANALYTICS_DISABLED=true
export SENTRY_DISABLED=true
export AWS_TELEMETRY_OPT_OUT=true
export JEKYLL_NO_USAGE=true
export SKIP_TELEMETRY=true
export NO_UPDATE_NOTIFIER=true
export TELEMETRY_DISABLED=true
# ****************************************************************************************************
# Set zsh options
# ****************************************************************************************************
setopt extended_history # save timestamp
setopt inc_append_history # add history immediately after typing a command
setopt autopushd
# ****************************************************************************************************
# Load zsh functions (e.g., cached_source)
# ****************************************************************************************************
if [ -e $HOME/.zfunc ]; then
source $HOME/.zfunc
fi
# ****************************************************************************************************
# Configure temporary directory
# ****************************************************************************************************
# Optimize for $HOME/.tmp already exists
if [[ -d "$HOME/.tmp/" ]]; then
export TMPDIR=$HOME/.tmp/
export TEMP=$HOME/.tmp/
export TEMPDIR=$HOME/.tmp/
export TMP=$HOME/.tmp/
else
if mkdir -p -m 600 $HOME/.tmp/; then
export TMPDIR=$HOME/.tmp/
export TEMP=$HOME/.tmp/
export TEMPDIR=$HOME/.tmp/
export TMP=$HOME/.tmp/
fi
fi
export XDG_RUNTIME_DIR=${TMPDIR}users/$UID/
# ****************************************************************************************************
# Configure terminal keys
# ****************************************************************************************************
bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
bindkey '^R' history-incremental-search-backward
# ****************************************************************************************************
# Setup for directory stack aliases (pushd/popd/cd/back/flip)
# ****************************************************************************************************
pushd()
{
if [ $# -eq 0 ]; then
DIR="${HOME}"
else
DIR="$1"
fi
builtin pushd "${DIR}" > /dev/null
echo -n "DIRSTACK: "
dirs
}
pushd_builtin()
{
builtin pushd > /dev/null
echo -n "DIRSTACK: "
dirs
}
popd()
{
builtin popd > /dev/null
echo -n "DIRSTACK: "
dirs
}
alias cd='pushd'
alias back='popd'
alias flip='pushd_builtin'
alias cleard='pushd -0 && dirs -c'
# ****************************************************************************************************
# Setup prompt / PS1
# ****************************************************************************************************
# Use cached_source function to cache machine type flags for prompt / PS1
cached_source 'machine' "echo export MACHINE=\$(uname -m)"
cached_source 'system' "echo export SYSTEM=\$(uname -s)"
cached_source 'wsl' "echo export WSL_FLAG=\$(grep -q -s -i microsoft /proc/version && echo 1 || echo 0)"
if [[ "$OSTYPE" == "darwin"* ]]; then
# Make macOS prompt blue
OS_COLOR='%F{33}'
OS_ICON=$'\uF8FF'
elif [[ "$WSL_FLAG" == "1" ]]; then
# Make WSL prompt fuchsia
OS_COLOR='%F{13}'
export SYSTEM='Linux/WSL'
OS_ICON=''
else
# Make Ubuntu prompt green
OS_COLOR='%F{82}'
OS_ICON=''
fi
export PS1="${OS_COLOR}%n%F{255}@${OS_COLOR}%m (%F{226}${MACHINE}%F{255}/%F{226}${OS_ICON}${SYSTEM}${OS_COLOR}) %1~ %f %# "
# ****************************************************************************************************
# Setup Homebrew and GNU utilities
# ****************************************************************************************************
# If using Homebrew, setup Homebrew aliases
if [[ "$HOMEBREW_PREFIX" != "" && -e "$HOMEBREW_PREFIX" ]]; then
# Homebrew setup
export HOMEBREW_NO_ANALYTICS=1
# Ensure that Homebrew uses the selected TMPDIR
export HOMEBREW_TEMP=$TMPDIR
# Ensure that Homebrew Cask apps are not quarantined
export HOMEBREW_CASK_OPTS=--no-quarantine
# Use Homebrew lsd or GNU ls if it exists
if [ -e $HOMEBREW_PREFIX/bin/lsd ] ; then
alias ls="$HOMEBREW_PREFIX/bin/lsd -lFG --color=auto"
else
if [ -e $HOMEBREW_PREFIX/bin/gls ] ; then
alias ls="$HOMEBREW_PREFIX/bin/gls -lFG --color=auto"
else
if [[ "$OSTYPE" == "darwin"* ]]; then
# Darwin's built in BSD ls
alias ls="ls -lFG"
else
# Linux built in gnuls
alias ls="ls -lFG --color=auto"
fi
fi
fi
# All GNU utilities get prepended to the path
cached_source "gnubins" "RESULT=''; for p in \$(find ${HOMEBREW_PREFIX}/Cellar/*/*/libexec -maxdepth 1 -type d -name gnubin); do RESULT=\"\${p}:\${RESULT}\"; done; echo export GNUBINS=\$RESULT"
# GNUBINS has a trailing colon
export PATH="$GNUBINS$PATH"
# If using Homebrew asdf, install bash completion via zsh compatibility
if [ -e $HOMEBREW_PREFIX/opt/asdf/libexec/asdf.sh ]; then
source $HOMEBREW_PREFIX/opt/asdf/libexec/asdf.sh
#if [ -e $HOMEBREW_PREFIX/opt/asdf/etc/bash_completion.d/asdf.bash ]; then
# autoload -U +X compinit && compinit
# autoload bashcompinit
# bashcompinit
# source $HOMEBREW_PREFIX/opt/asdf/etc/bash_completion.d/asdf.bash
#fi
fi
# Add Homebrew MySQL client to the PATH (prepended to prefer)
if [[ -d $HOMEBREW_PREFIX/opt/mysql-client/bin ]]; then
export PATH="$HOMEBREW_PREFIX/opt/mysql-client/bin:$PATH"
fi
# Add Homebrew OpenJDK to the PATH
if [[ -d $HOMEBREW_PREFIX/opt/openjdk/bin ]]; then
export PATH="$HOMEBREW_PREFIX/opt/openjdk/bin:$PATH"
fi
# Configure fzf's zsh autocomplete and hotkeys (using cached_source)
if [ -e $HOMEBREW_PREFIX/opt/fzf/bin/fzf ]; then
cached_source "fzf-zsh" "fzf --zsh"
fi
# If we have trash-cli installed, alias trash-put over rm
if [ -e $HOMEBREW_PREFIX/opt/trash-cli/bin/trash-put ]; then
alias rm="$HOMEBREW_PREFIX/opt/trash-cli/bin/trash-put"
fi
fi
# ****************************************************************************************************
# Setup EDITOR
# ****************************************************************************************************
# Optimize for neovim Homebrew existing
if [ -e $HOMEBREW_PREFIX/bin/nvim ]; then
export EDITOR="$HOMEBREW_PREFIX/bin/nvim"
else
# Prefer neovim if it exists
nvim_path=$(command -v nvim 2>/dev/null)
if [ -n "$nvim_path" ]; then
export EDITOR="$nvim_path"
else
# Prefer vim if it exists
vim_path=$(command -v vim 2>/dev/null)
if [ -n "$vim_path" ]; then
export EDITOR="$vim_path"
else
# Default to vi if nothing else exists
export EDITOR="vi"
fi
fi
fi
alias vim="$EDITOR"
alias nvim="$EDITOR"
alias neovim="$EDITOR"
alias nano="$EDITOR"
export GIT_EDITOR="$EDITOR"
# ****************************************************************************************************
# Setup Go
# ****************************************************************************************************
# Add Go binaries to the PATH
if [[ -d $HOME/go/bin ]]; then
export PATH="$HOME/go/bin:$PATH"
fi
# ****************************************************************************************************
# Setup Ruby GEM_HOME and PATH for gems
# ****************************************************************************************************
if [[ -d $HOME/.gems ]]; then
export GEM_HOME="$HOME/.gems"
export PATH="$HOME/.gems/bin:$PATH"
fi
# Load iTerm2 shell integration if installed
#if [ -e "${HOME}/.iterm2_shell_integration.zsh" ]; then
# source "${HOME}/.iterm2_shell_integration.zsh"
#fi
# ****************************************************************************************************
# Setup Python pyenv
# ****************************************************************************************************
# Load pyenv if it is installed
if [[ -d $HOME/.pyenv ]]; then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
cached_source "pyenv" "pyenv init --path"
fi
# ****************************************************************************************************
# Setup Rust env
# ****************************************************************************************************
if [ -e "$HOME/.cargo/env" ]; then
source "$HOME/.cargo/env"
fi
# ****************************************************************************************************
# Add custom scripts to the PATH
# ****************************************************************************************************
export PATH="$HOME/.scripts:$PATH"
# ****************************************************************************************************
# Custom aliases / helpers (use alias to show list of aliases)
# ****************************************************************************************************
if [[ "$OSTYPE" != "darwin"* ]]; then
# Use doas rather than sudo on Linux
alias sudo='doas'
alias update='doas apt update && doas apt upgrade -y && brew update && brew upgrade'
else
# Use xman on MacOS
function xman() {
open x-man-page://$1
}
alias man='xman'
alias update='brew update && brew upgrade'
fi
# Always use neomutt
alias mutt='neomutt'
alias path="echo \$PATH | cut -f 2 -d '=' | sed 's/:/\n/g'"
alias dns='doggo'
# Flatten a git repo
alias git-flatten='git reset $(git commit-tree HEAD^{tree} -m "Flatten")'
# Ping rapidly
alias fastping="ping -i 0.2"
# Show all open ports that aren't localhost
alias ports="sudo lsof -iTCP -sTCP:LISTEN -nP -b -M 2>/dev/null | grep -v -e 127.0.0 -e ::1]"
# Get current IPv4 address
alias checkip="curl https://checkip.amazonaws.com"
# Deal with gpg-agent being unreliable
alias reset-gpg='gpgconf --kill gpg-agent'
alias test-gpg='echo “Test” | gpg --clearsign -v'
if [[ -d $HOME/.aws ]]; then
alias aws-logout='aws sso logout ; rm -f $HOME/.aws/boto/*.json $HOME/.aws/boto/cache/*.json ; unset AWS_ACCESS_KEY_ID ; unset AWS_SECRET_ACCESS_KEY ; unset AWS_SESSION_TOKEN'
fi
# ****************************************************************************************************
# Neofetch
# ****************************************************************************************************
# If we have a neofetch output to display, display it
if [ -e "$HOME/.config/neofetch.txt" ]; then
echo "$( <$HOME/.config/neofetch.txt)"
fi
# ****************************************************************************************************
# Disable error handling so it doesn't apply to scripts run in the shell
# ****************************************************************************************************
trap - ERR