1
0

zshrc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. if [ -x /usr/local/bin/gdircolors ]; then
  2. eval "$(/usr/local/bin/gdircolors -b ~/.dircolors)"
  3. else
  4. export LSCOLORS=ExGxhxDxCxhxhxhxhxExEx
  5. fi
  6. if [ -d /opt/homebrew/share/zsh/site-functions ]; then
  7. fpath=(/opt/homebrew/share/zsh/site-functions $fpath)
  8. fi
  9. autoload -Uz compinit
  10. compinit
  11. zmodload -a complist
  12. zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
  13. zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
  14. zstyle ':completion:*' use-compctl false
  15. zstyle ':completion:*' use-cache on
  16. zstyle ':completion:*' cache-path ~/.zshcache
  17. __git_files () {
  18. _wanted files expl 'local files' _files
  19. }
  20. zstyle :compinstall filename "$HOME/.zshrc"
  21. source $HOME/.zsh_autosuggestions.zsh
  22. HISTFILE=~/.histfile
  23. HISTSIZE=10000
  24. SAVEHIST=10000
  25. setopt no_beep
  26. setopt extendedglob
  27. setopt prompt_subst
  28. setopt complete_in_word
  29. setopt no_auto_menu
  30. setopt no_always_last_prompt
  31. setopt share_history
  32. setopt hist_ignore_all_dups
  33. setopt hist_ignore_space
  34. setopt extended_history
  35. setopt promptsubst
  36. setopt autopushd
  37. setopt pushdignoredups
  38. setopt nomatch
  39. autoload -U edit-command-line
  40. zle -N edit-command-line
  41. bindkey -e
  42. bindkey '^[[3~' delete-char
  43. bindkey '^[[1;5C' forward-word
  44. bindkey '^[[1;5D' backward-word
  45. bindkey '\C-v' edit-command-line
  46. bindkey '\Ea' push-line
  47. local WORDCHARS=${WORDCHARS//\//}\| # remove forward slash, add pipe
  48. autoload -U url-quote-magic
  49. zle -N self-insert url-quote-magic
  50. source $HOME/.zsh_fast_syntax_highlighting/fast-syntax-highlighting.plugin.zsh
  51. export EDITOR=nvim
  52. export GREP_COLORS='ms=01;36:mc=01;31:sl=:cx=:fn=35:ln=33:bn=33:se=01;34'
  53. if [ -x /opt/homebrew/bin/eza ]; then
  54. export EZA_COLORS=bu=0:cr=0
  55. alias ls='eza --group-directories-first --mounts --group --hyperlink --icons=auto'
  56. elif [ -x /opt/homebrew/bin/gls ]; then
  57. alias ls='gls --color=auto -hv --group-directories-first'
  58. else
  59. export CLICOLOR=1
  60. alias ls='ls --color=auto -hv --group-directories-first'
  61. fi
  62. if [ $TERM = xterm-kitty ]; then
  63. alias ssh='kitten ssh'
  64. fi
  65. alias ll='ls -l'
  66. alias l.='ls -Ad .*'
  67. alias la='ls -A'
  68. alias llr='lr -1AGl -ov'
  69. alias grep='grep --color -s'
  70. alias df='gdf -hx tmpfs'
  71. alias du='gdu --max-depth=1'
  72. alias sr='screen -r'
  73. alias gil='git log --graph --abbrev-commit --stat --summary -C --decorate --date=local'
  74. alias gime='git short --author raylu'
  75. alias giw='git show -C --date=local --decorate'
  76. alias gip='git pull --ff-only'
  77. alias gib='git branch'
  78. alias gis='git status'
  79. alias gid='git diff -C --date=local'
  80. alias gic='git checkout'
  81. alias giu='git reset HEAD\^'
  82. alias hgw='hg diff --change .'
  83. alias class='xprop -notype WM_CLASS'
  84. alias fx='FX_NO_MOUSE=1 FX_COLLAPSED=1 FX_SHOW_SIZE=1 fx'
  85. alias tree='tree -AvL 10'
  86. alias vi='nvim -p'
  87. alias vil='nvim *(.om[1])'
  88. alias find='gfind'
  89. alias sudovi="sudo vi -N -u $HOME/.vimrc"
  90. alias shrug="echo -n '¯\\(°_o)/¯' | pbcopy"
  91. alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
  92. alias k8sctl='kubectl --kubeconfig ~/src/infra/docs/kubeconfig/ops.yaml'
  93. alias helm='helm --kubeconfig ~/src/infra/docs/kubeconfig/ops.yaml'
  94. function https() {
  95. openssl s_client -connect $1:443 -servername $1 < /dev/null | \
  96. openssl x509 -noout -text -certopt no_header,no_version,no_serial,no_signame,no_pubkey,no_sigdump
  97. }
  98. function cl() {
  99. if [ $# = 0 ]; then
  100. cd && ls
  101. else
  102. cd "$*" && ls
  103. fi
  104. }
  105. function pdf() {
  106. atril "$*" &> /dev/null &!
  107. }
  108. source $HOME/src/aurelia/packages/benchling-dev-utilities/dev-completion.zsh
  109. if [ -d /usr/lib/cargo/bin ]; then
  110. PATH=/usr/lib/cargo/bin:$PATH
  111. if [ -d /usr/lib/cargo/bin/coreutils ]; then
  112. PATH=/usr/lib/cargo/bin/coreutils:$PATH
  113. fi
  114. fi
  115. PATH=/usr/local/sbin:/usr/local/bin:$PATH
  116. if [ -d /opt/homebrew/sbin ]; then
  117. PATH=/opt/homebrew/sbin:$PATH
  118. fi
  119. if [ -d /opt/homebrew/bin ]; then
  120. PATH=/opt/homebrew/bin:$PATH
  121. fi
  122. if [ -d $HOME/.cargo/bin ]; then
  123. PATH=$HOME/.cargo/bin:$PATH
  124. fi
  125. export BUN_INSTALL=$HOME/.bun
  126. if [ -d $BUN_INSTALL ]; then
  127. source $BUN_INSTALL/_bun
  128. PATH="$BUN_INSTALL/bin:$PATH"
  129. fi
  130. if [ -d $HOME/bin ]; then
  131. PATH=$HOME/bin:$PATH
  132. fi
  133. if builtin which bat > /dev/null; then
  134. export MANPAGER='sh -c "col -bx | bat --language man --paging always --style plain"'
  135. export MANROFFOPT='-c'
  136. elif builtin which nvim > /dev/null; then
  137. export MANPAGER='vim +Man!'
  138. else
  139. export MANPAGER='vim -M +MANPAGER -'
  140. fi
  141. if builtin which oh-my-posh > /dev/null; then
  142. eval "$(oh-my-posh init zsh -c ~/.config/oh-my-posh.toml)"
  143. elif builtin which starship > /dev/null; then
  144. eval "$(starship init zsh)"
  145. else
  146. autoload colors
  147. colors
  148. bright_cyan='%{%}' # not provided by colors
  149. autoload -Uz vcs_info
  150. zstyle ':vcs_info:*' unstagedstr "%{$fg[red]%}*"
  151. zstyle ':vcs_info:*' stagedstr "%{$fg[red]%}+"
  152. zstyle ':vcs_info:*' formats "$bright_cyan%b%u%c"
  153. zstyle ':vcs_info:*' actionformats "$bright_cyan%b%u%c|%a"
  154. zstyle ':vcs_info:git:*' check-for-changes true
  155. zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b:%r'
  156. zstyle ':vcs_info:bzr:*' use-simple true
  157. zstyle ':vcs_info:*' enable git hg bzr svn cvs
  158. precmd () { vcs_info }
  159. PROMPT="%{$fg_bold[grey]%}%* " # time
  160. PROMPT+="%{${fg_bold[green]}%}%m%{${reset_color}%}:" # host
  161. PROMPT+="%{${fg_bold[blue]}%}%50<...<%~%<<%{${reset_color}%} " # path
  162. PROMPT+='${vcs_info_msg_0_} '
  163. PROMPT+="%(?..%{$fg_bold[red]%}%? %{$reset_color%})" # exit status
  164. PROMPT+="%1(j.%{$fg[green]%}%j .)" # suspended jobs
  165. PROMPT+=$'%{$reset_color%} \n%(!.#.\$) '
  166. fi
  167. if builtin which jj > /dev/null; then
  168. source <(COMPLETE=zsh jj)
  169. fi
  170. if builtin which procs > /dev/null; then
  171. source <(procs --gen-completion-out zsh)
  172. fi
  173. if builtin which aws_completer > /dev/null; then
  174. autoload bashcompinit && bashcompinit
  175. complete -C aws_completer aws
  176. fi
  177. if builtin which fzf > /dev/null; then
  178. FZF_DEFAULT_OPTS='--no-mouse'
  179. if [ -f /opt/homebrew/opt/fzf/shell/key-bindings.zsh ]; then
  180. source /opt/homebrew/opt/fzf/shell/key-bindings.zsh
  181. elif [ -f /usr/local/opt/fzf/shell/key-bindings.zsh ]; then
  182. source /usr/local/opt/fzf/shell/key-bindings.zsh
  183. fi
  184. __fzf_git_commit_sha() {
  185. setopt localoptions pipefail no_aliases 2> /dev/null
  186. git log --color=always -n 50 --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' |
  187. FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse \
  188. --preview 'git show --color=always {1}' ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
  189. sed -r -e 's/([0-9a-f]+) .+/\1/' -e 's/.+ ([0-9a-f]+)/\1/'
  190. }
  191. fzf-git-commit-sha-widget() {
  192. LBUFFER="${LBUFFER}$(__fzf_git_commit_sha)"
  193. local ret=$?
  194. zle reset-prompt
  195. return $ret
  196. }
  197. zle -N fzf-git-commit-sha-widget
  198. bindkey '^G' fzf-git-commit-sha-widget
  199. __fzf_git_branch() {
  200. setopt localoptions pipefail no_aliases 2> /dev/null
  201. git branch --all --color=always \
  202. --format='%(if)%(HEAD)%(then)%(color:bold green)%(else)%(if:equals=refs/remotes)%(refname:rstrip=-2)%(then)%(color:red)%(end)%(end)%(refname:short)' |
  203. FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse ${FZF_DEFAULT_OPTS-}" \
  204. $(__fzfcmd) \
  205. --preview 'git log --color=always --abbrev-commit --stat --summary -C --decorate --date=local {1} --max-count=20' \
  206. --height ${FZF_TMUX_HEIGHT:-40%} "$@"
  207. }
  208. fzf-git-branch-widget() {
  209. LBUFFER="${LBUFFER}$(__fzf_git_branch)"
  210. local ret=$?
  211. zle reset-prompt
  212. return $ret
  213. }
  214. zle -N fzf-git-branch-widget
  215. bindkey '^H' fzf-git-branch-widget
  216. __fzf_pid() {
  217. setopt localoptions pipefail no_aliases 2> /dev/null
  218. ps axo pid,start,user,command |
  219. FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
  220. awk '{print $1}'
  221. }
  222. fzf-pid-widget() {
  223. LBUFFER="${LBUFFER}$(__fzf_pid)"
  224. local ret=$?
  225. zle reset-prompt
  226. return $ret
  227. }
  228. zle -N fzf-pid-widget
  229. bindkey '^O' fzf-pid-widget
  230. __fzf_rg() {
  231. setopt localoptions pipefail no_aliases 2> /dev/null
  232. RELOAD='reload:rg --column --color=always --smart-case {q} || :'
  233. $(__fzfcmd) --disabled --ansi --multi \
  234. --bind "start:$RELOAD" --bind "change:$RELOAD" \
  235. --bind 'alt-a:select-all,alt-d:deselect-all,ctrl-/:toggle-preview' \
  236. --delimiter : \
  237. --preview 'bat --style=full --color=always --highlight-line {2} {1}' \
  238. --preview-window '~4,+{2}+4/3,<80(up)' \
  239. --query "$*" |
  240. cut -d: -f1
  241. }
  242. fzf-rg-widget() {
  243. LBUFFER="${LBUFFER}$(__fzf_rg)"
  244. local ret=$?
  245. zle reset-prompt
  246. return $ret
  247. }
  248. zle -N fzf-rg-widget
  249. bindkey '^S' fzf-rg-widget
  250. fi
  251. export NVM_DIR="$HOME/.nvm"
  252. NODE_VERSION=$(cat "$NVM_DIR/alias/default")
  253. source "$NVM_DIR/nvm.sh" --no-use
  254. export PATH="$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH"
  255. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # this loads nvm bash_completion
  256. #eval "$(pyenv init --path --no-rehash)"
  257. #eval "$(pyenv virtualenv-init - | gsed s/precmd/precwd/g)"
  258. #export PATH="/Users/raylu/.local/bin:$PATH"
  259. eval "$(mise activate zsh)"
  260. export KUBECONFIG="${HOME}/.kube/config:${INFRA_DIR:-${HOME}/infra}/docs/kubeconfig/ops.yaml"
  261. source <(kubectl completion zsh 2> /dev/null)
  262. source <(helm completion zsh 2> /dev/null)
  263. ulimit -S -n 10240
  264. stty stop undef