zshrc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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='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 gil='git log --graph --abbrev-commit --stat --summary -C --decorate --date=local'
  75. alias gib='git branch'
  76. alias gis='git status'
  77. alias gid='git diff -C --date=local'
  78. alias gic='git checkout'
  79. alias giu='git reset HEAD\^'
  80. alias gn='git number'
  81. alias hgw='hg diff --change .'
  82. alias class='xprop -notype WM_CLASS'
  83. alias tree='tree -AvL 10'
  84. alias vi='vi -p'
  85. alias vil='vi *(.om[1])'
  86. alias dt='gnome-terminal --hide-menubar'
  87. alias sudovi="sudo vi -N -u $HOME/.vimrc"
  88. alias shrug="echo -n '¯\\(°_o)/¯' | xclip -selection clipboard"
  89. function https() {
  90. openssl s_client -connect $1:443 -servername $1 < /dev/null | \
  91. openssl x509 -noout -text -certopt no_header,no_version,no_serial,no_signame,no_pubkey,no_sigdump
  92. }
  93. function cl() {
  94. if [ $# = 0 ]; then
  95. cd && ls
  96. else
  97. cd "$*" && ls
  98. fi
  99. }
  100. function pdf() {
  101. atril "$*" &> /dev/null &!
  102. }
  103. export PYTHONSTARTUP=$HOME/.pystartup.py
  104. export VIRTUAL_ENV=$HOME/venv
  105. if [ -d $VIRTUAL_ENV ]; then
  106. PATH=$VIRTUAL_ENV/bin:$PATH
  107. fi
  108. if [ -d $HOME/.cargo/bin ]; then
  109. PATH=$HOME/.cargo/bin:$PATH
  110. fi
  111. export BUN_INSTALL=$HOME/.bun
  112. if [ -d $BUN_INSTALL ]; then
  113. source $BUN_INSTALL/_bun
  114. PATH="$BUN_INSTALL/bin:$PATH"
  115. fi
  116. if [ -d $HOME/bin ]; then
  117. PATH=$HOME/bin:$PATH
  118. fi
  119. if builtin which starship > /dev/null; then
  120. eval "$(starship init zsh)"
  121. else
  122. autoload colors
  123. colors
  124. bright_cyan='%{%}' # not provided by colors
  125. autoload -Uz vcs_info
  126. zstyle ':vcs_info:*' unstagedstr "%{$fg[red]%}*"
  127. zstyle ':vcs_info:*' stagedstr "%{$fg[red]%}+"
  128. zstyle ':vcs_info:*' formats "$bright_cyan%b%u%c"
  129. zstyle ':vcs_info:*' actionformats "$bright_cyan%b%u%c|%a"
  130. zstyle ':vcs_info:git:*' check-for-changes true
  131. zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b:%r'
  132. zstyle ':vcs_info:bzr:*' use-simple true
  133. zstyle ':vcs_info:*' enable git hg bzr svn cvs
  134. precmd () { vcs_info }
  135. PROMPT="%{$fg_bold[grey]%}%* " # time
  136. PROMPT+="%{${fg_bold[green]}%}%m%{${reset_color}%}:" # host
  137. PROMPT+="%{${fg_bold[blue]}%}%50<...<%~%<<%{${reset_color}%} " # path
  138. PROMPT+='${vcs_info_msg_0_} '
  139. PROMPT+="%(?..%{$fg_bold[red]%}%? %{$reset_color%})" # exit status
  140. PROMPT+="%1(j.%{$fg[green]%}%j .)" # suspended jobs
  141. PROMPT+=$'%{$reset_color%} \n%(!.#.\$) '
  142. fi
  143. if [ -x /usr/bin/fzf ]; then
  144. FZF_DEFAULT_OPTS='--no-mouse'
  145. source "/usr/share/doc/fzf/examples/key-bindings.zsh"
  146. __fzf_git_commit_sha() {
  147. setopt localoptions pipefail no_aliases 2> /dev/null
  148. git log --color=always -n 50 --format='%C(auto)%h%d %s %C(black)%C(bold)%cr' |
  149. FZF_DEFAULT_OPTS="--ansi --no-sort --tiebreak=index --reverse \
  150. --preview 'git show --color=always {1}' ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
  151. sed -r -e 's/([0-9a-f]+) .+/\1/' -e 's/.+ ([0-9a-f]+)/\1/'
  152. }
  153. fzf-git-commit-sha-widget() {
  154. LBUFFER="${LBUFFER}$(__fzf_git_commit_sha)"
  155. local ret=$?
  156. zle reset-prompt
  157. return $ret
  158. }
  159. zle -N fzf-git-commit-sha-widget
  160. bindkey '^G' fzf-git-commit-sha-widget
  161. __fzf_pid() {
  162. setopt localoptions pipefail no_aliases 2> /dev/null
  163. ps axo pid,start,user,command |
  164. FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse ${FZF_DEFAULT_OPTS-}" $(__fzfcmd) -m "$@" |
  165. awk '{print $1}'
  166. }
  167. fzf-pid-widget() {
  168. LBUFFER="${LBUFFER}$(__fzf_pid)"
  169. local ret=$?
  170. zle reset-prompt
  171. return $ret
  172. }
  173. zle -N fzf-pid-widget
  174. bindkey '^O' fzf-pid-widget
  175. __fzf_rg() {
  176. setopt localoptions pipefail no_aliases 2> /dev/null
  177. RELOAD='reload:rg --column --color=always --smart-case {q} || :'
  178. $(__fzfcmd) --disabled --ansi --multi \
  179. --bind "start:$RELOAD" --bind "change:$RELOAD" \
  180. --bind 'alt-a:select-all,alt-d:deselect-all,ctrl-/:toggle-preview' \
  181. --delimiter : \
  182. --preview 'bat --style=full --color=always --highlight-line {2} {1}' \
  183. --preview-window '~4,+{2}+4/3,<80(up)' \
  184. --query "$*" |
  185. cut -d: -f1
  186. }
  187. fzf-rg-widget() {
  188. LBUFFER="${LBUFFER}$(__fzf_rg)"
  189. local ret=$?
  190. zle reset-prompt
  191. return $ret
  192. }
  193. zle -N fzf-rg-widget
  194. bindkey '^S' fzf-rg-widget
  195. giw() {
  196. local commit=${1:-HEAD}
  197. git diff-tree --color=always --stat --no-commit-id $commit | sed '$d' | cut -c 2- | \
  198. fzf --filepath-word --ansi --layout=reverse --bind enter:abort \
  199. --header="$(git show --date=local --decorate --shortstat --color=always $commit)" \
  200. --preview-window='right,<110(down,70%)' \
  201. --preview="git diff-tree --patch --no-commit-id --color=always $commit {1} | delta" \
  202. --bind tab:toggle-preview,ctrl-y:preview-up,ctrl-e:preview-down \
  203. --bind ctrl-b:preview-page-up,ctrl-f:preview-page-down \
  204. --bind ctrl-u:preview-half-page-up,ctrl-d:preview-half-page-down \
  205. --bind="ctrl-o:execute(git diff-tree --patch --no-commit-id --color=always $commit {1} | delta --paging=always)" \
  206. --bind="ctrl-s:execute(git show -C --date=local --decorate $commit)"
  207. }
  208. else
  209. alias giw='git show -C --date=local --decorate'
  210. fi
  211. stty stop undef