-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzshrc
executable file
·451 lines (378 loc) · 15 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# Source common definitions
__zshrc_main() {
local SH_SOURCE_FILE SH_SOURCE_DIR SH_SOURCE_FILE_ESCAPED
if [ -n "$ZSH_VERSION" ]; then
SH_SOURCE_FILE=${(%):-%x}
elif [ -n "$BASH_VERSION" ]; then
SH_SOURCE_FILE=${BASH_SOURCE[0]}
fi
while [[ -L "$SH_SOURCE_FILE" ]]; do
SH_SOURCE_FILE=$(readlink "$SH_SOURCE_FILE")
done
SH_SOURCE_DIR=$(dirname "$SH_SOURCE_FILE")
SH_SOURCE_DIR=`cd "$SH_SOURCE_DIR" >/dev/null; pwd`
SH_SOURCE_FILE=$(basename "$SH_SOURCE_FILE")
SH_SOURCE_FILE_ESCAPED=${SH_SOURCE_FILE// /_}
# SH_SOURCE_DIR is a full path to the location of this script
eval "$(cat <<EOF
__get_${SH_SOURCE_FILE_ESCAPED}_dir() {
echo $SH_SOURCE_DIR
}
__get_${SH_SOURCE_FILE_ESCAPED}_file() {
echo $SH_SOURCE_FILE
}
__get_sh_scripts_dir() {
echo "$SH_SOURCE_DIR"
}
__get_sh_scripts_file() {
echo "$SH_SOURCE_FILE"
}
EOF
)"
local SH_COLOR_DEFS
if [[ -e "$SH_SOURCE_DIR/configure_colors" ]]; then
SH_COLOR_DEFS=`cat "$SH_SOURCE_DIR/configure_colors"`
fi
local SH_OS_DEFS
if [[ -e "$SH_SOURCE_DIR/configure_os" ]]; then
SH_OS_DEFS=`cat "$SH_SOURCE_DIR/configure_os"`
fi
eval "$(cat <<EOF
__sh_color_definitions() {
echo "$SH_COLOR_DEFS"
}
__sh_os_definitions() {
echo "$SH_OS_DEFS"
}
EOF
)"
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
local SH_INTERACTIVE
case $- in
*i*)
# interactive shell
SH_INTERACTIVE=1
;;
esac
. "${SH_SOURCE_DIR}/shrc_helpers"
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Configuring environment for '$COLOR_GREEN_BOLD'Zsh '${ZSH_VERSION}$COLOR_NONE' on '$COLOR_GREEN_BOLD$SH_OS_DISTRO$COLOR_NONE' '$COLOR_GREEN_BOLD$SH_OS_RELEASE$COLOR_NONE' ('$COLOR_GREEN_BOLD$SH_OS_TYPE$COLOR_NONE')'
# SSH configuration
if [[ $SH_OS_TYPE == Windows ]]; then
export SSH_AUTH_SOCK=/tmp/.ssh-socket
ssh-add -l >/dev/null 2>&1
if [[ $? = 2 ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Creating new ssh-agent'
rm -f /tmp/.ssh-script /tmp/.ssh-agent-pid /tmp/.ssh-socket
ssh-agent -a $SSH_AUTH_SOCK > /tmp/.ssh-script
. /tmp/.ssh-script
[[ $SH_INTERACTIVE ]] && echo $SSH_AGENT_PID > /tmp/.ssh-agent-pid
fi
fi
if [[ $SH_OS_TYPE == Linux ]]; then
if [[ -z "$(pgrep -u $USER ssh-agent)" ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'SSH agent '$COLOR_YELLOW_BOLD'not running'$COLOR_NONE'. Starting new one...'
rm -rf /tmp/ssh-* 2>/dev/null
eval $(ssh-agent -s) >/dev/null
else
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'SSH agent '$COLOR_GREEN_BOLD'running'$COLOR_NONE'. Connecting...'
export SSH_AGENT_PID=$(pgrep -u $USER ssh-agent)
export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name agent.\* 2>/dev/null)
fi
fi
# Only add keys in interactive shell
if [[ $SH_INTERACTIVE ]]; then
ssh-add >/dev/null 2>&1
if [[ -f "${HOME}/.ssh/id_rsa_personal" ]]; then
if [[ `ssh-add -l | grep -i id_rsa_personal | wc -l` -lt 1 ]]; then
if [[ $SH_OS_TYPE == OSX ]]; then
ssh-add -K ${HOME}/.ssh/id_rsa_personal >/dev/null 2>&1
else
ssh-add ${HOME}/.ssh/id_rsa_personal >/dev/null 2>&1
fi
fi
fi
fi
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Homebrew
if [[ $SH_OS_TYPE == OSX ]]; then
if [[ -f /opt/homebrew/bin/brew ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Configuring '$COLOR_GREEN_BOLD'Homebrew'$COLOR_NONE
export HOMEBREW_NO_ENV_HINTS=1
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
elif [[ $SH_OS_TYPE == Linux ]]; then
if [[ -f /home/linuxbrew/.linuxbrew/bin/brew ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Configuring '$COLOR_GREEN_BOLD'Linuxbrew'$COLOR_NONE
export HOMEBREW_NO_ENV_HINTS=1
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
fi
# Source additional global, local, and personal definitions
[[ $SH_INTERACTIVE ]] && echo
__include_files "${HOME}/.zshrc_local" "${SH_SOURCE_DIR}/aliases" "${HOME}/.aliases_local"
# Set up default prompt (will be overridden by oh-my-zsh if installed)
autoload -Uz promptinit
promptinit
prompt adam1
setopt histignorealldups sharehistory auto_cd
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history
# Color directories
if [[ $SH_OS_TYPE == OSX ]]; then
# Mac OS X settings
export LSCOLORS=GxFxCxDxBxegedabagaced
fi
if [[ $SH_OS_TYPE == Linux ]]; then
# Linux settings
export LS_COLORS='di=01;36'
fi
# Use modern completion system
# Set ZSH_DISABLE_COMPFIX at global scope to ensure it works in nested zsh sessions
export ZSH_DISABLE_COMPFIX=true
autoload -Uz compinit
compinit -u # Use -u flag to skip the insecure directories check
setopt autocd
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
# eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:(cd|pushd):*' tag-order local-directories path-directories
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
if [[ ! -d $HOME/.oh-my-zsh ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Installing '$COLOR_GREEN_BOLD'oh-my-zsh'$COLOR_NONE
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --keep-zshrc --unattended"
fi
if [[ -d $HOME/.oh-my-zsh ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_GREEN_BOLD$ZSH'/oh-my-zsh.sh'$COLOR_NONE
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="amuse"
COMPLETION_WAITING_DOTS="true"
DISABLE_UNTRACKED_FILES_DIRTY="true"
HIST_STAMPS="yyyy-mm-dd"
plugins=(git mercurial nvm node npm python pip macos iterm2 macports)
source $ZSH/oh-my-zsh.sh
fi
# ITerm2 integration
local ITERM2_INTEGRATION
if [[ $SH_OS_TYPE == OSX ]]; then
ITERM2_INTEGRATION=$HOME/.iterm2_shell_integration.zsh
if [[ -f "$ITERM2_INTEGRATION" ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_GREEN_BOLD$ITERM2_INTEGRATION$COLOR_NONE
. "$ITERM2_INTEGRATION"
fi
fi
# Zsh completion
local ZSH_COMPLETION_INSTALLED
if [[ $SH_OS_TYPE == OSX ]]; then
if [[ -f /opt/homebrew/bin/brew ]]; then
if [[ -d /opt/homebrew/share/zsh-completions ]]; then
ZSH_COMPLETION_INSTALLED=/opt/homebrew/share/zsh-completions
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_GREEN_BOLD'/opt/homebrew/share/zsh-completions'$COLOR_NONE
FPATH=/opt/homebrew/share/zsh-completions:$FPATH
# Already called compinit at the top level, just update FPATH
fi
fi
fi
local PATH_DIRS=( "${HOME}/bin" "${HOME}/.local/bin" )
if [[ $SH_OS_TYPE == OSX ]]; then
# Mac OS X paths, including Homebrew and MacPorts
PATH_DIRS=( "${PATH_DIRS[@]}" "/usr/local/bin" "/usr/local/sbin" "/opt/local/bin" "/opt/local/sbin" "/opt/homebrew/bin" )
fi
if [[ $SH_OS_DISTRO == Ubuntu ]]; then
PATH_DIRS=( "${PATH_DIRS[@]}" "/usr/local/cuda/bin" "/snap/bin" )
fi
__add_to_path "${PATH_DIRS[@]}"
# Affects cd behavior - CDPATH needs to always be set for the cd function in aliases to work properly
__add_to_cd_path "." "${HOME}" "${HOME}/src"
# Convert CDPATH (colon separated string) to cdpath (array) - zsh requires this conversion
# Unlike bash which just uses CDPATH, zsh needs the cdpath array to be properly set
cdpath=(${(s.:.)CDPATH})
# SSH client
if [[ -n $SSH_CLIENT ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Connected from '$COLOR_CYAN_BOLD$(get_ssh_client_ip)$COLOR_NONE
fi
# Git completion - only load if not using oh-my-zsh
if [[ ! -d $HOME/.oh-my-zsh ]] && [[ -n $(which git 2>/dev/null) ]]; then
# Load custom git completions if available
local GIT_COMPLETION
GIT_COMPLETION=$HOME/bin/git-completion.zsh
if [[ -f "$GIT_COMPLETION" ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_GREEN_BOLD$GIT_COMPLETION$COLOR_NONE
. "$GIT_COMPLETION"
fi
fi
# Misc declarations
if [[ $SH_OS_TYPE == Linux ]]; then
if [[ $SH_OS_DISTRO == Ubuntu ]]; then
if [[ -z $SHELL ]]; then
# Ubuntu does not always define it for some reason
export SHELL=/usr/bin/env zsh
fi
fi
fi
export EDITOR=vim
export GNUTERM=x11
# WSL X configuration
if [[ $SH_OS_FLAVOR == WSL ]]; then
export GDK_DPI_SCALE=2
fi
# Dev declarations
# Windsurf
if [[ -d $HOME/.codeium/windsurf/bin ]]; then
__add_to_path "${HOME}/.codeium/windsurf/bin"
fi
# Android SDK
if [[ -d $HOME/android-sdk ]]; then
export ANDROID_HOME=$HOME/android-sdk
__add_to_path "${HOME}/android-sdk/build-tools/$([[ -d "${HOME}/android-sdk/build-tools/" ]] && ls -1 "${HOME}/android-sdk/build-tools/" | tr -d '/' | sort | tail -n 1)" "${HOME}/android-sdk/platform-tools" "${HOME}/android-sdk/tools" "${HOME}/android-ndk" "${HOME}/android-ndk/android-ndk-r10e"
fi
if [[ -d $HOME/android-ndk ]]; then
if [[ -d $HOME/android-ndk/android-ndk-r10e ]]; then
export ANDROID_NDK=$HOME/android-ndk/android-ndk-r10e
else
export ANDROID_NDK=$HOME/android-ndk
fi
export ANDROID_NDK_REPOSITORY=$HOME/android-ndk
export ANDROID_NDK_ROOT=$ANDROID_NDK
export NDKROOT=$ANDROID_NDK
export NDK_MODULE_PATH=$ANDROID_NDK
fi
# Node
if [[ -d $HOME/.nvm ]]; then
export NVM_DIR="$HOME/.nvm"
fi
if [[ -d $NVM_DIR ]]; then
if [[ -s "$NVM_DIR/nvm.sh" ]]; then
. "$NVM_DIR/nvm.sh"
fi
if [[ -s "$NVM_DIR/bash_completion" ]]; then
. "$NVM_DIR/bash_completion"
fi
fi
# Bun
if [[ -d $HOME/.bun ]]; then
export BUN_INSTALL="$HOME/.bun"
fi
if [[ -d $BUN_INSTALL ]]; then
[ -s "$BUN_INSTALL/_bun" ] && source "$BUN_INSTALL/_bun"
__add_to_path "${BUN_INSTALL}/bin"
fi
if [[ -d $HOME/.deno ]]; then
export DENO_DIR="$HOME/.deno"
fi
if [[ -d $DENO_DIR ]]; then
. "$DENO_DIR/env"
# Use $HOME instead of hardcoded user path
if [[ ":$FPATH:" != *":$HOME/.zsh/completions:"* ]]; then export FPATH="$HOME/.zsh/completions:$FPATH"; fi
fi
# Ruby
if [[ $SH_OS_TYPE == OSX ]]; then
if [[ -d /opt/homebrew/opt/ruby/bin ]]; then
__add_to_path "/opt/homebrew/opt/ruby/bin" "/opt/homebrew/lib/ruby/gems/3.4.0/bin"
fi
fi
if [[ -z $GEM_HOME ]]; then
if [[ -d $HOME/.gem ]]; then
export GEM_HOME="$HOME/.gem"
elif [[ -d $HOME/gems ]]; then
export GEM_HOME="$HOME/gems"
elif [[ $SH_OS_TYPE == OSX ]]; then
if [[ -d /opt/homebrew/opt/ruby/lib/ruby/gems/3.4.0/gems ]]; then
export GEM_HOME="/opt/homebrew/opt/ruby/lib/ruby/gems/3.4.0/gems"
fi
fi
fi
if [[ -n $GEM_HOME ]]; then
__add_to_path "${GEM_HOME}/bin"
fi
# Go
if [[ $SH_OS_TYPE == OSX ]]; then
if [[ -d $HOME/go ]]; then
export GOPATH=$HOME/go
fi
fi
# Conda
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
. "$HOME/miniconda3/etc/profile.d/conda.sh"
else
__add_to_path "${HOME}/miniconda3/bin"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# Next.js
export NEXT_TELEMETRY_DEBUG=1
# Python
export PYTHONPATH=./
# Llama.cpp
if [[ $SH_OS_DISTRO == Ubuntu ]]; then
export GGML_CUDA_ENABLE_UNIFIED_MEMORY=1
elif [[ $SH_OS_TYPE == OSX ]]; then
export OpenMP_ROOT=$(brew --prefix)/opt/libomp
fi
# Local declarations
if [[ -n `whence __zshrc_local_run` ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Executing '$COLOR_GREEN_BOLD$(__zshrc_local)$COLOR_NONE
__zshrc_local_run "$@"
fi
# Global aliases deferred load
if [[ -n `whence __aliases_load` ]]; then
__aliases_load "$@"
fi
# Local aliases deferred load
if [[ -n `whence __aliases_local_load` ]]; then
__aliases_local_load "$@"
fi
# Global dotrc deferred load
# Node
# After local dotrc to ensure we don't pick accidentally local dotrc node version
if [[ -d $NVM_DIR ]]; then
if [[ $(nvm current) == system ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Switching node from '$COLOR_GREEN_YELLOW'system'$COLOR_YELLOW' to '$COLOR_GREEN_BOLD'nvm default'$COLOR_NONE
nvm use default
fi
fi
# Free space
local FREE_SPACE FREE_SPACE_READABLE
FREE_SPACE=`df -k / | tail -n 1 | awk '{printf $4}'`
FREE_SPACE_READABLE=`df -h / | tail -n 1 | awk '{printf $4}' | tr -d i`
FREE_SPACE_READABLE=$COLOR_YELLOW_BOLD$FREE_SPACE_READABLE$COLOR_NONE
if (( $FREE_SPACE <= 5000000 )); then
FREE_SPACE_READABLE=$FREE_SPACE_READABLE' '$COLOR_RED_BOLD'WARNING: Low free disk space!!!'$COLOR_NONE
fi
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Free space: '$FREE_SPACE_READABLE
[[ $SH_INTERACTIVE ]] && echo
}
__zshrc_main "$@"
unset -f __zshrc_main