.zshrc 5.4 KB

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