-
Notifications
You must be signed in to change notification settings - Fork 2
/
.zshrc
463 lines (381 loc) · 12.3 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
452
453
454
455
456
457
458
459
460
461
462
463
# todo: modularise this into separate files e.g. prompt, aliases, fzf etc.
# for profiling
# simple profiling of zsh related things
# zmodload zsh/zprof
# complete profiling of everything loaded in new shell
# zmodload zsh/datetime
# setopt promptsubst
# PS4='+$EPOCHREALTIME %N:%i> '
# exec 3>&2 2> startlog.$$
# setopt xtrace prompt_subst
# disable the update prompt
DISABLE_UPDATE_PROMPT=true
DISABLE_AUTO_TITLE=true
# disable update checking entirely
zstyle ':omz:update' mode disabled
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
source $ZSH/oh-my-zsh.sh
# remove the right prompt extra space
ZLE_RPROMPT_INDENT=0
eval "$(starship init zsh)"
# the following is now called from ~/.zshenv
# source ~/.config/zsh/directory_hashes.zsh
# exa colours
source $HOME/Documents/Work/internal/vim/colors/falcon/exa/EXA_COLORS_MODERN
# User configuration.
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH="$PATH:$HOME/.composer/vendor/bin"
# set how long to wait for a sequence
KEYTIMEOUT=1
export EDITOR="nvim"
bindkey -v
# vi style incremental search
bindkey '^P' history-search-backward
bindkey '^N' history-search-forward
# change directory by just typing it's name
setopt AUTO_CD
# use the hash in the prompt
setopt AUTO_NAME_DIRS
# push previous directory on to the stack
setopt AUTO_PUSHD
# don't ignore dups in stack
unsetopt PUSHD_IGNORE_DUPS
# exchage meanings of + and -
setopt PUSHD_MINUS
# completion
setopt AUTO_MENU
setopt ALWAYS_TO_END
setopt COMPLETE_IN_WORD
unsetopt FLOW_CONTROL
unsetopt MENU_COMPLETE
# activate menu (using tab) selection
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path $ZSH_CACHE_DIR
zstyle ':completion:*' list-colors ''
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
# formatting
zstyle ':completion:*:descriptions' format "$fg[yellow]%B--- %d%b"
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format "$fg[red]No matches for:$reset_color %d"
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
# complete the suggestion
bindkey '^E' autosuggest-accept
# run the suggestion now (ctrl-enter)
bindkey '^[[13;5u' autosuggest-execute
# history options
# save timestamp and duration
setopt EXTENDED_HISTORY
# get rid of duplicate items when needed
setopt HIST_EXPIRE_DUPS_FIRST
# ignore putting duplicates in the history
setopt HIST_IGNORE_DUPS
# ignore spaces
setopt HIST_IGNORE_SPACE
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
timezsh() {
shell=${1-$SHELL}
for i in $(seq 1 10); do /usr/bin/time $shell -i -c exit; done
}
alias l='llm -m my-openai'
# alias l='ls -alhF'
# alias lvr='ls -alR > /dev/null'
alias mv='/bin/mv -i'
alias rm='/bin/rm -i'
alias srm='sudo /bin/rm -i'
alias cx='chmod +x'
# this thins local snapshots, 50gb, urgency of 4 (highest)
alias tmthin='tmutil thinlocalsnapshots / $((50 * 1024 * 1024 * 1024)) 4'
# reload
alias reload="source ~/.zshrc"
# eza (was exa)
alias e='eza -algB --group-directories-first'
alias et='eza -algB --tree'
alias es='eza --oneline --group-directories-first'
alias cat='bat'
alias c='bat'
alias ping='prettyping'
alias top='sudo htop'
alias du="ncdu --color off -rr -x --exclude .git --exclude node_modules"
run_vim_leader() {
com="NormLead $1"
nvim -c "$com"
}
# nvim aliases
alias nv='nvim'
alias v='nvim'
alias sv='sudo nvim'
alias vl='run_vim_leader'
edit-latest() {
nvim "$(find . -name '*.*' -print0 -maxdepth 1 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" ")"
}
alias el="edit-latest"
# suffix aliases: typing name of file with suffix will use that program
alias -s php=nvim
alias -s module=nvim
alias -s scss=nvim
alias -s css=nvim
alias -s tpl=nvim
alias -s yml=nvim
#global aliases, substitute anywhere
alias -g L="| less"
alias -g T="| tail"
alias -g TL="| tail -20"
alias -g C="| pbcopy"
alias -g G="| grep"
# Preview via fzf, edit with enter
alias -g P="| fzf --preview 'bat --color=always --line-range :500 {}' --bind 'enter:execute(nvim {})'"
# git aliases
alias gs='git s'
alias gd='git di'
alias gl='git l'
alias gp='git push'
alias gb='git branch'
alias g='_f() { if [[ $# == 0 ]]; then git status --short --branch; else git "$@"; fi }; _f'
# tmux
tmux-new-window() {
tmux new-window -n $1
}
tmux-rename-window() {
tmux rename-window $1
}
alias ms='~/.config/tmux/split.sh'
alias mn='~/.config/tmux/new.sh'
alias mpc='~/.config/tmux/pc.sh'
alias ml='tmux ls'
alias ma='tmux attach-session'
alias mw='tmux-new-window'
alias mr='tmux-rename-window'
# robo
# alias rb='./vendor/bin/robo'
alias rb='~pcp/vendor/bin/robo'
alias rbd='docker exec -it -w /app nginx-pc vendor/bin/robo'
new-fortnightly () {
cd ~pcp/../../video/product_weekly
local YEAR=$(date -u +%Y)
local MONTH=$(date -u +%m)
local DAY=$(date -u +%d)
local FN=fortnightly_"$DAY"_"$MONTH"_"$YEAR".html
cp template.html "$FN"
nvim "$FN"
}
#virtual box
alias vbox='vboxmanage'
alias vboxr='vboxmanage list runningvms'
#docker
alias docker-restart="osascript -e 'quit app \"Docker\"'"
# ssh
alias ventrassh='ssh theoryz4@s03de.syd6.hostingplatform.net.au -p 2683 -i $HOME/.ssh/id_dsa'
#ranger
alias r='ranger'
alias ..='cd ..'
#hugo
hugo-new-post () {
hugo new posts/"$1".md --editor nvim
}
hugo-new-til () {
hugo new til/"$1".md --editor nvim
}
hugo-open-post() {
nvim $(find content -name '*.md' | fzf --no-multi --preview 'bat --color=always --line-range :500 {}')
}
hugo-open-latest() {
nvim $(find content -name '*.md' -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" ")
}
hugo-open-drafts() {
nvim $(hugo list drafts | cut -d"," -f1 | grep content | fzf --no-multi --preview 'bat --color=always --line-range :500 {}')
}
# hugo-migrate-images is in .zshenv so it works in neovim shell command
alias hi="hugo-migrate-images"
alias hd="hugo-open-drafts"
alias hl="hugo-open-latest"
alias ho="hugo-open-post"
alias hn='hugo-new-post'
alias ht='hugo-new-til'
#love framework
alias love="/Applications/love.app/Contents/MacOS/love"
#rando
alias dbd='rb db:dump --path="tmp/dump.sql" --sed=gsed --dirty'
alias dbl='rb db:load --path="tmp/dump.sql"'
alias dbd2='rb db:dump --path="tmp/dump2.sql" --sed=gsed --dirty'
alias dbl2='rb db:load --path="tmp/dump2.sql"'
alias dbd3='rb db:dump --path="tmp/dump3.sql" --sed=gsed --dirty'
alias dbl3='rb db:load --path="tmp/dump3.sql"'
alias pcload='(cd ~pcp && rb db:load)'
alias pcup='docker-compose -f misc/docker/docker-compose.yml -f misc/docker/docker-compose.override.yml up -d'
alias pcdown='docker container stop $(docker container ls -aq)'
alias ytbest="yt-dlp -f bestvideo+bestaudio --merge-output-format=mkv"
alias yt1080='yt-dlp -S "height:1080"'
alias yt720='yt-dlp -S "height:720"'
# yabai
yabai_windows () {
yabai -m query --windows --space "$1" | jq -c -re '.[] | select(."is-visible" == true) | {id, title, app, "is-floating"}'
}
yabai_spaces () {
yabai -m query --spaces --space "$1" | jq -c -re '{id, index, label, type}'
}
alias ys="yabai_spaces"
alias yw="yabai_windows"
# function to toggle fg/bg on control z
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
stty start undef stop undef
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# fzf for checking out a branch
fzf_git_checkout() {
result=$(git branch -a | grep -v '/HEAD\s' | sort |
fzf --ansi --height 50% --border --tac --preview-window right:70% \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$LINES |
sed 's/^..//' | cut -d' ' -f1)
if [[ $result != "" ]]; then
if [[ $result == remotes/* ]]; then
git checkout --track $(echo $result | sed 's#remotes/##')
else
git checkout "$result"
fi
fi
}
# fzf git log
fzf_git_log() {
local commits=$(
git ll --color=always "$@" |
fzf --no-sort --height 100% \
--preview "echo {} | grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I@ sh -c 'git show --color=always @'"
)
if [[ -n $commits ]]; then
local hashes=$(printf "$commits" | cut -d' ' -f2 | tr '\n' ' ')
git show $hashes
fi
}
# fzf find a file by name and edit
fzf_find_edit() {
local file=$(
fzf --no-multi --preview 'bat --color=always --line-range :500 {}'
)
if [[ -n $file ]]; then
$EDITOR $file
fi
}
# fzf find a file with text and edit
fzf_grep_edit(){
if [[ $# == 0 ]]; then
echo 'Error: search term was not provided.'
return
fi
local match=$(
rg --color=never --line-number "$1" |
fzf --no-multi --delimiter : \
--preview "bat --color=always --line-range {2}: {1}"
)
local file=$(echo "$match" | cut -d':' -f1)
if [[ -n $file ]]; then
$EDITOR $file +$(echo "$match" | cut -d':' -f2)
fi
}
# fkill - kill processes - list only the ones you can kill. Modified the earlier script.
fzf_kill_process() {
local pid
if [ "$UID" != "0" ]; then
pid=$(ps -f -u $UID | sed 1d | fzf -m | awk '{print $2}')
else
pid=$(ps -ef | sed 1d | fzf -m | awk '{print $2}')
fi
if [ "x$pid" != "x" ]
then
echo $pid | xargs kill -${1:-9}
fi
}
alias fkill='fzf_kill_process'
alias fge='fzf_grep_edit'
alias ffe='fzf_find_edit'
alias fgl="fzf_git_log"
alias fco="fzf_git_checkout"
export PATH="/usr/local/opt/ncurses/bin:$PATH"
export GOPATH="$HOME/go"
export OCPATH="$HOME/.minishift/cache/oc/v3.9.0/darwin"
export PATH="$GOPATH/bin:$OCPATH:$PATH"
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PATH=/Applications/kitty.app/Contents/MacOS:$PATH
# ripgrep configufation
export RIPGREP_CONFIG_PATH="$HOME/.rgrc"
# all files
alias rga="rg --hidden --no-ignore"
alias fda="fd --hidden --no-ignore"
# kitty
alias ki="kitty +kitten icat --align=left" #view image
alias kiw="kitty +kitten icat --align=left --background=#ffffff" #view image
# generate a clean, up to date kitty config, see https://sw.kovidgoyal.net/kitty/conf/
alias kc="kitty +runpy 'from kitty.config import *; print(commented_out_default_config())'"
# nvm - replaced with volta
lpass_export() {
LPASS=`lpass status`
if [[ "$LPASS" != *"Logged in"* ]]; then
lpass login michael@theoryz.com.au
fi
KEYS=`lpass show --notes keys`
while read -r key; do
export "$key"
done <<< "$KEYS"
}
#load local env keys
local_export() {
KEYS=`cat ~/.env`
while read -r key; do
export "$key"
done <<< "$KEYS"
}
# local_export
# fast antidote loading from the page
# Set the root name of the plugins files (.txt and .zsh) antidote will use.
zsh_plugins=${ZDOTDIR:-~}/.zsh_plugins
# Ensure the .zsh_plugins.txt file exists so you can add plugins.
[[ -f ${zsh_plugins}.txt ]] || touch ${zsh_plugins}.txt
# Lazy-load antidote from its functions directory.
fpath=(~/.antidote/functions $fpath)
autoload -Uz antidote
# Generate a new static file whenever .zsh_plugins.txt is updated.
if [[ ! ${zsh_plugins}.zsh -nt ${zsh_plugins}.txt ]]; then
antidote bundle <${zsh_plugins}.txt >|${zsh_plugins}.zsh
fi
# Source your static plugins file.
source ${zsh_plugins}.zsh
#zsh-history-substring-search key bindings
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
# change these depending on version
export PATH="/usr/local/opt/php@8.1/bin:$PATH"
export PATH="/usr/local/opt/php@8.1/sbin:$PATH"
# export PATH="/usr/local/opt/php@8.0/bin:$PATH"
# export PATH="/usr/local/opt/php@8.0/sbin:$PATH"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-22.jdk/Contents/Home"
export PATH="$JAVA_HOME:$PATH"
export PATH="/Users/mjw/tmp/apache-maven/bin:$PATH"
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
# zsh falcon colouring
source $HOME/Documents/Work/internal/vim/colors/falcon/zsh/falcon.zsh
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
alias luamake=$HOME/tmp/lua-language-server/3rd/luamake/luamake
# fasd setup
# eval "$(fasd --init auto)"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
eval "$(zoxide init zsh)"
source ~pc/.aliases.zsh
# simple profiling and output
# zprof > ~/tmp/prof.txt
# more complete profiling
# unsetopt xtrace
# exec 2>&3 3>&-