zshrc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 print_exit_value
  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_paste
  44. export EDITOR=vi
  45. if builtin which batcat > /dev/null; then
  46. export MANPAGER='batcat -l man -p'
  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. if [ -x ~/bin/eza ]; then
  54. alias ls='eza --group-directories-first --mounts --group --icons=auto'
  55. else
  56. alias ls='ls --color=auto -hv --group-directories-first'
  57. fi
  58. if [ $TERM = xterm-kitty ]; then
  59. alias ssh='kitten ssh'
  60. fi
  61. alias ll='ls -l'
  62. alias l.='ls -Ad .*'
  63. alias la='ls -A'
  64. alias llr='lr -1AGl -ov'
  65. alias bat=batcat
  66. alias grep='grep --color -s'
  67. alias df='df -hx tmpfs'
  68. alias du='du --max-depth=1'
  69. alias fd='fdfind'
  70. alias sr='screen -r'
  71. alias gip='git pull --ff-only'
  72. alias gil='git log --graph --abbrev-commit --stat --summary -C --decorate --date=local'
  73. alias gib='git branch'
  74. alias gis='git status'
  75. alias gid='git diff -C --date=local'
  76. alias giw='git show -C --date=local --decorate'
  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 starship > /dev/null; then
  119. eval "$(starship init zsh)"
  120. else
  121. autoload colors
  122. colors
  123. bright_cyan='%{%}' # not provided by colors
  124. autoload -Uz vcs_info
  125. zstyle ':vcs_info:*' unstagedstr "%{$fg[red]%}*"
  126. zstyle ':vcs_info:*' stagedstr "%{$fg[red]%}+"
  127. zstyle ':vcs_info:*' formats "$bright_cyan%b%u%c"
  128. zstyle ':vcs_info:*' actionformats "$bright_cyan%b%u%c|%a"
  129. zstyle ':vcs_info:git:*' check-for-changes true
  130. zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b:%r'
  131. zstyle ':vcs_info:bzr:*' use-simple true
  132. zstyle ':vcs_info:*' enable git hg bzr svn cvs
  133. precmd () { vcs_info }
  134. PROMPT="%{$fg_bold[grey]%}%* " # time
  135. PROMPT+="%{${fg_bold[green]}%}%m%{${reset_color}%}:" # host
  136. PROMPT+="%{${fg_bold[blue]}%}%50<...<%~%<<%{${reset_color}%} " # path
  137. PROMPT+='${vcs_info_msg_0_} '
  138. PROMPT+="%(?..%{$fg_bold[red]%}%? %{$reset_color%})" # exit status
  139. PROMPT+="%1(j.%{$fg[green]%}%j .)" # suspended jobs
  140. PROMPT+=$'%{$reset_color%} \n%(!.#.\$) '
  141. fi
  142. if [ -x /usr/bin/fzf ]; then
  143. FZF_DEFAULT_OPTS='--no-mouse'
  144. source "/usr/share/doc/fzf/examples/key-bindings.zsh"
  145. __fzf_git_commit_sha() {
  146. setopt localoptions pipefail no_aliases 2> /dev/null
  147. git log --color=always -n 50 --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' |
  148. FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse \
  149. --preview 'git show --color=always {1}' ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
  150. sed -r -e 's/([0-9a-f]+) .+/\1/' -e 's/.+ ([0-9a-f]+)/\1/'
  151. }
  152. fzf-git-commit-sha-widget() {
  153. LBUFFER="${LBUFFER}$(__fzf_git_commit_sha)"
  154. local ret=$?
  155. zle reset-prompt
  156. return $ret
  157. }
  158. zle -N fzf-git-commit-sha-widget
  159. bindkey '^G' fzf-git-commit-sha-widget
  160. __fzf_pid() {
  161. setopt localoptions pipefail no_aliases 2> /dev/null
  162. ps axo pid,start,user,command |
  163. FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
  164. cut -c -6 | xargs
  165. }
  166. fzf-pid-widget() {
  167. LBUFFER="${LBUFFER}$(__fzf_pid)"
  168. local ret=$?
  169. zle reset-prompt
  170. return $ret
  171. }
  172. zle -N fzf-pid-widget
  173. bindkey '^O' fzf-pid-widget
  174. fi
  175. stty stop undef