zshrc 8.0 KB

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