-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_zshrc
321 lines (241 loc) · 10.9 KB
/
dot_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
# zmodload zsh/zprof
# Personal Zsh configuration file. It is strongly recommended to keep all
# shell customization and configuration (including exported environment
# variables such as PATH) in this file or in files sourced from it.
#
# Documentation: https://github.com/romkatv/zsh4humans/blob/v5/README.md.
################################################################################
# zstyle #
################################################################################
# Periodic auto-update on Zsh startup: 'ask' or 'no'.
# You can manually run `z4h update` to update everything.
zstyle ':z4h:' auto-update 'ask'
# Ask whether to auto-update this often; has no effect if auto-update is 'no'.
zstyle ':z4h:' auto-update-days '28'
# Keyboard type: 'mac' or 'pc'.
zstyle ':z4h:bindkey' keyboard 'mac'
# Start tmux if not already in tmux.
# zstyle ':z4h:' start-tmux command tmux -u new -A -D -t z4h
# Commented out per https://github.com/romkatv/zsh4humans/blob/master/tips.md#tmux
# Mark up shell's output with semantic information.
zstyle ':z4h:' term-shell-integration 'yes'
# Right-arrow key accepts one character ('partial-accept') from
# command autosuggestions or the whole thing ('accept')?
zstyle ':z4h:autosuggestions' forward-char 'accept'
# Recursively traverse directories when TAB-completing files.
zstyle ':z4h:fzf-complete' recurse-dirs 'no'
# Enable direnv to automatically source .envrc files.
zstyle ':z4h:direnv' enable 'no'
# Show "loading" and "unloading" notifications from direnv.
zstyle ':z4h:direnv:success' notify 'no'
# Enable ('yes') or disable ('no') automatic teleportation of z4h over
# SSH when connecting to these hosts.
# zstyle ':z4h:ssh:example-hostname1' enable 'yes'
# zstyle ':z4h:ssh:*.example-hostname2' enable 'no'
# The default value if none of the overrides above match the hostname.
zstyle ':z4h:ssh:*' enable 'no'
# Send these files over to the remote host when connecting over SSH to the
# enabled hosts.
zstyle ':z4h:ssh:*' send-extra-files '~/.viminfo' '~/.env.zsh'
################################################################################
# Clone additional Git repositories from GitHub #
################################################################################
# This doesn't do anything apart from cloning the repository and keeping it
# up-to-date. Cloned files can be used after `z4h init`. This is just an
# example. If you don't plan to use Oh My Zsh, delete this line.
# z4h install ohmyzsh/ohmyzsh || return
# Install or update core components (fzf, zsh-autosuggestions, etc.) and
# initialize Zsh. After this point console I/O is unavailable until Zsh
# is fully initialized. Everything that requires user interaction or can
# perform network I/O must be done above. Everything else is best done below.
z4h init || return
################################################################################
# Extend PATH #
################################################################################
# Hatch managed Pythons
# HATCH_DATA_DIR=$(yq '.dirs.data' "$(hatch config find)")
# hatch_py_bin_paths=()
# py_vers=({12..8})
# for v in "${~py_vers[@]}"; do
# hatch_py_bin_paths+="$HATCH_DATA_DIR"/pythons/3.$v/python/bin
# done
# PYPY_VER='7.3.15'
# pypy_vers=('2.7' '3.9' '3.10')
# for v in "${(Oa)pypy_vers[@]}"; do
# hatch_py_bin_paths+=($HATCH_DATA_DIR/pythons/pypy$v/pypy$v-v$PYPY_VER-macos_arm64/bin)
# done
# path=($hatch_py_bin_paths $path)
# rustup
z4h source "$HOME/.cargo/env"
# rbenv
# eval "$(rbenv init - zsh)"
# Google Cloud SDK
# GCLOUD_SDK_INIT_PATH=$HOMEBREW_PREFIX/share/google-cloud-sdk
# z4h source "$GCLOUD_SDK_INIT_PATH/path.zsh.inc"
DEVCONTAINER_CLI_BIN_PATH=$HOME/Library/Application\ Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/cli-bin
# 20240806: Python client needs libmysqlclient.23.dylib.
# mysql-client 9.0.1 includes libmysqlclient.24.dylib.
MYSQL_CLIENT_BIN_PATH=$HOMEBREW_PREFIX/opt/mysql-client@8.0/bin
path+=($DEVCONTAINER_CLI_BIN_PATH $MYSQL_CLIENT_BIN_PATH)
fpath=(~/.zfunc $fpath)
################################################################################
# Export environment variables #
################################################################################
# default editor
# https://stackoverflow.com/a/2596835
export VISUAL=vim
export EDITOR="$VISUAL"
# gpg
export GPG_TTY=$TTY
path=(~/bin $path)
export PATH="$HOME/.cargo/bin:$HOME/Library/Application Support/Coursier/bin:$PATH"
# causes Brewed coreutils to be seen before pre-installed utils
# N.B. THIS BREAKS PYENV see:
# https://github.com/pyenv/pyenv/issues/1768#issuecomment-757435245
# export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
# Java
LATEST_JAVA=23
JAVA_HOME_CMD=/usr/libexec/java_home
export JAVA_LATEST_HOME=$($JAVA_HOME_CMD -v $LATEST_JAVA)
export JAVA_17_HOME=$($JAVA_HOME_CMD -v 17)
export JAVA_11_HOME=$($JAVA_HOME_CMD -v 11)
export JAVA_8_HOME=$($JAVA_HOME_CMD -v 1.8)
# Golang
export GOPATH=$HOME/.go
################################################################################
# Source additional local files if they exist #
################################################################################
z4h source ~/.env.zsh
z4h source ~/.zsh/aliases/ohmyzsh-git-aliases
# Use additional Git repositories pulled in with `z4h install`.
# `z4h source`` individual files
# `z4h load`` plugins
################################################################################
# Define key bindings #
################################################################################
z4h bindkey undo Ctrl+/ Shift+Tab # undo the last command line change
z4h bindkey redo Option+/ # redo the last undone command line change
z4h bindkey z4h-cd-back Shift+Left # cd into the previous directory
z4h bindkey z4h-cd-forward Shift+Right # cd into the next directory
z4h bindkey z4h-cd-up Shift+Up # cd into the parent directory
z4h bindkey z4h-cd-down Shift+Down # cd into a child directory
################################################################################
# Autoload functions #
################################################################################
autoload -Uz zmv
# Make it possible to use completion specifications and functions written for bash.
# Make sure ~/.zfunc is added to fpath before compinit.
autoload -Uz bashcompinit
bashcompinit
# zsh-completions
if type brew &>/dev/null; then
FPATH=$HOMEBREW_PREFIX/share/zsh-completions:$FPATH
fi
autoload -Uz compinit
compinit
################################################################################
# Define functions and completions #
################################################################################
# function md() { [[ $# == 1 ]] && mkdir -p -- "$1" && cd -- "$1" }
# compdef _directories md
# LabLite environment snapshot
function mlss() {
local MAMBALAB_SNAPSHOT_DIR="$HOME/.mambalab/lablite-snapshots"
local SNAPSHOT_PATH="$MAMBALAB_SNAPSHOT_DIR/lablite_$(date +%y%m%d_%H%M)"
local LIST_EXPORT_FILE="$SNAPSHOT_PATH.txt"
local ENV_EXPORT_FILE="$SNAPSHOT_PATH.yml"
if [[ $CONDA_DEFAULT_ENV = 'lablite' ]]; then
mamba list --export > $LIST_EXPORT_FILE &&
echo $LIST_EXPORT_FILE
conda env export -f $ENV_EXPORT_FILE &&
echo $ENV_EXPORT_FILE
else
echo 'lablite not active'
fi
}
# Generate random integer in range
function rand() {
local lower=$1
local upper=$2
echo $(( lower + RANDOM % (upper - lower + 1) ))
}
# Google Cloud SDK completions
# https://github.com/romkatv/zsh4humans/issues/266#issuecomment-1508192847
# z4h source "$GCLOUD_SDK_INIT_PATH/completion.zsh.inc"
eval "$(register-python-argcomplete pipx)" # pipx completions
# https://developer.1password.com/docs/cli/get-started/#shell-completion
eval "$(op completion zsh)"; compdef _op op
# https://github.com/junegunn/fzf?tab=readme-ov-file#setting-up-shell-integration
eval "$(fzf --zsh)"
# https://github.com/ajeetdsouza/zoxide?tab=readme-ov-file#installation
eval "$(zoxide init zsh)"
################################################################################
# Define aliases #
################################################################################
alias path='echo -e ${PATH//:/\\n}' # line separated PATH
# Open configs in Sublime Text
alias zshrc='subl $HOME/.zshrc'
alias uvtoml='subl $HOME/.config/uv/uv.toml'
alias sqlfluff-conf='subl $HOME/.sqlfluff'
# Jupyter Lab
alias jlset='subl /Users/rrosenberg/.jupyter/lab/user-settings/@jupyter-lsp/jupyterlab-lsp/plugin.jupyterlab-settings'
# zsh
alias srczsh='exec zsh' # This is preferred by z4h over 'source $HOME/.zshrc'
alias aws-sso='aws sso login && zsh $HOME/.cron_scripts/codeartifact-pypi-auth.sh'
# Upgrade brew, uv, pipx, hatch-managed python, gcloud, rust, & z4h
alias upgrade='brew update \
&& brew upgrade \
&& uv self update \
&& uv tool upgrade --all \
&& pipx upgrade-all --include-injected \
&& hatch python update all \
&& gcloud components update --quiet \
&& rustup update \
&& z4h update'
# New CDS Copier
alias newcds='copier copy --trust "git@github.com:CadentTech/ds-copier-hatch-base.git"'
# Hatch aliases
alias h='hatch'
alias hr='hatch run'
# Brew: Show dependencies as a tree.
alias brew-tree='brew deps --tree --installed'
# du
alias duh='du -hd 1 | sort -hr'
# Java
alias javalatest="export JAVA_HOME=$JAVA_LATEST_HOME"
alias java17="export JAVA_HOME=$JAVA_17_HOME"
alias java11="export JAVA_HOME=$JAVA_11_HOME"
alias java8="export JAVA_HOME=$JAVA_8_HOME"
#set default to Java 17
java17
#------------------------#
# Shadowing #
#------------------------#
alias cd='z'
alias diff='delta'
alias ls='lsd'
#------------------------#
# ls #
#------------------------#
# lsd
alias l='lsd -lA'
alias ll='l'
alias lt='lsd --tree'
# eza
# alias l='eza'
# alias ll='eza -lah'
# alias lt='eza -h --tree'
# alias lh='eza -lahr --sort newest'
# Define named directories: ~w <=> Windows home directory on WSL.
# [[ -z $z4h_win_home ]] || hash -d w=$z4h_win_home
# Define aliases.
# alias tree='tree -a -I .git'
# Add flags to existing aliases.
# alias ls="${aliases[ls]:-ls} -Alah"
################################################################################
# Set shell options #
################################################################################
# Set shell options: http://zsh.sourceforge.net/Doc/Release/Options.html.
setopt glob_dots # no special treatment for file names with a leading dot
setopt no_auto_menu # require an extra TAB press to open the completion menu
# zprof