zshrc 6.9 KB

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