.zshrc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. ################################################################################
  2. # Basic configuration
  3. ################################################################################
  4. setopt BEEP
  5. export TERM=alacritty
  6. export LANG=en_US.UTF-8
  7. # Disable the log builtin, so we don't conflict with /usr/bin/log
  8. disable log
  9. # Correctly display UTF-8 with combining characters.
  10. if [[ "$(locale LC_CTYPE)" == "UTF-8" ]]; then
  11. setopt COMBINING_CHARS
  12. fi
  13. # Use `nvim` as editor, preferring current instance if nested
  14. export EDITOR="${DOTFILES_DIR}/.scripts/nvim_editor.zsh"
  15. # Fixes plugin keymap conflicts
  16. export ZVM_INIT_MODE=sourcing
  17. ################################################################################
  18. # History
  19. ################################################################################
  20. HISTFILE=${ZDOTDIR}/.zsh_history
  21. HISTSIZE=2147483647
  22. SAVEHIST=$HISTSIZE
  23. export HISTORY_IGNORE="(ls|lsd|la|cd|pwd|exit)*"
  24. setopt HIST_EXPIRE_DUPS_FIRST
  25. setopt HIST_IGNORE_ALL_DUPS
  26. setopt HIST_IGNORE_DUPS
  27. setopt HIST_IGNORE_SPACE
  28. setopt HIST_REDUCE_BLANKS
  29. setopt HIST_VERIFY
  30. setopt INC_APPEND_HISTORY
  31. setopt SHARE_HISTORY
  32. ################################################################################
  33. # Prompt
  34. ################################################################################
  35. # A pleasant, informative, and transient prompt. Made possible by an arcane
  36. # incantation from [powerlevel10k](https://github.com/romkatv/powerlevel10k/),
  37. # as described in the project's issue tracker:
  38. # https://github.com/romkatv/powerlevel10k/issues/888#issuecomment-657969840
  39. autoload -Uz compinit
  40. compinit
  41. autoload -Uz vcs_info
  42. precmd_vcs_info() { vcs_info }
  43. setopt prompt_subst
  44. zstyle ':vcs_info:git:*' formats '%F{3}%F{8} %b '
  45. set-long-prompt() {
  46. if [ "$NEW_LINE_BEFORE_PROMPT" -eq 1 ]; then
  47. print ''
  48. else
  49. NEW_LINE_BEFORE_PROMPT=1
  50. fi
  51. PROMPT='%F{3}%F{8} %d %0(?..%F{3}%F{8} %? )${vcs_info_msg_0_}%F{3}󰒋%F{8} %m %F{3}%F{8} %n
  52. %F{3}$ %f%k'
  53. }
  54. set-short-prompt() {
  55. if [[ $PROMPT != '%F{3}$ %f%k' ]]; then
  56. PROMPT='%F{3}$ %f%k'
  57. zle .reset-prompt
  58. fi
  59. }
  60. precmd_functions=(
  61. set-long-prompt
  62. precmd_vcs_info
  63. )
  64. zle-line-finish() {
  65. set-short-prompt
  66. }
  67. zle -N zle-line-finish
  68. trap 'set-short-prompt; return 130' INT
  69. ################################################################################
  70. # Potentially interactive execution
  71. ################################################################################
  72. # Load SSH key into keychain
  73. if [[ $OSTYPE == darwin* ]] then
  74. ssh-add --apple-use-keychain $HOME/.ssh/id_rsa >/dev/null 2>&1
  75. else
  76. eval `keychain --eval --quiet id_rsa`
  77. fi
  78. ################################################################################
  79. # Aliases
  80. ################################################################################
  81. alias x="exit"
  82. alias c="clear && NEW_LINE_BEFORE_PROMPT=0"
  83. alias clear="clear && NEW_LINE_BEFORE_PROMPT=0"
  84. # nvim
  85. if command -v nvim &>/dev/null; then;
  86. alias n="nvim"
  87. fi;
  88. # granted
  89. if command -v assume &>/dev/null; then;
  90. alias assume=". assume"
  91. fi;
  92. # brew
  93. if command -v brew &>/dev/null; then;
  94. alias brewdump="(cd $XDG_CONFIG_HOME/brew/ && brew bundle dump --force --describe)"
  95. fi;
  96. # docker
  97. if command -v docker &>/dev/null; then;
  98. alias dockerprune="(docker system prune -a -f && docker system df -v) | less"
  99. fi;
  100. # git
  101. if command -v git &>/dev/null; then;
  102. alias g="git"
  103. alias gs="git s"
  104. alias gl="git l"
  105. fi;
  106. # lsd
  107. if command -v lsd &>/dev/null; then;
  108. alias ls="lsd -a"
  109. alias la="lsd -la"
  110. fi;
  111. # lazygit
  112. if command -v lazygit &>/dev/null; then;
  113. alias lg="lazygit"
  114. fi;
  115. # lazydocker
  116. if command -v lazydocker &>/dev/null; then;
  117. alias lg="lazydocker"
  118. fi;
  119. ################################################################################
  120. # From github.com/zsh-users:
  121. # * zsh-autosuggestions
  122. # * zsh-syntax-highlighting
  123. # Both can be installed through Homebrew.
  124. ################################################################################
  125. if command -v brew >> /dev/null; then
  126. source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  127. source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  128. source $(brew --prefix)/opt/zsh-vi-mode/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
  129. fi
  130. ################################################################################
  131. # fzf
  132. ################################################################################
  133. if command -v fzf >> /dev/null; then
  134. eval "$(fzf --zsh)"
  135. fi
  136. ################################################################################
  137. # Keybinds
  138. ################################################################################
  139. # Ctrl+Y copies buffer to clipboard
  140. cmd_to_clip () { pbcopy <<< $BUFFER }
  141. zle -N cmd_to_clip
  142. bindkey '^Y' cmd_to_clip
  143. # Ctrl+G copies git-tracked file contents in directory to the clipboard
  144. copy_dir_llm_style () {
  145. git ls-files | column;
  146. if read -s -q "choice?Total files: $( git ls-files | wc -l) | Press 'y' to copy contents"; then;
  147. {
  148. echo "Here is the contents of \`$(basename "$PWD")/\`:\n";
  149. git ls-files -z |
  150. while IFS= read -r -d $'\0' f; do
  151. echo "$f"; echo '```';
  152. cat "$f"; echo '```';
  153. echo;
  154. done;
  155. } | pbcopy
  156. echo "\nCopied!"
  157. else;
  158. echo "\nQuit without copying anything"
  159. fi
  160. }
  161. zle -N copy_dir_llm_style
  162. bindkey '^G' copy_dir_llm_style