0
0

.zshrc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. # docker
  93. if command -v docker &>/dev/null; then;
  94. alias dockerprune="(docker system prune -a -f && docker system df -v) | less"
  95. fi;
  96. # git
  97. if command -v git &>/dev/null; then;
  98. alias g="git"
  99. alias gs="git s"
  100. alias gl="git l"
  101. fi;
  102. # lsd
  103. if command -v lsd &>/dev/null; then;
  104. alias ls="lsd -a"
  105. alias la="lsd -la"
  106. fi;
  107. # lazygit
  108. if command -v lazygit &>/dev/null; then;
  109. alias lg="lazygit"
  110. fi;
  111. # lazydocker
  112. if command -v lazydocker &>/dev/null; then;
  113. alias lg="lazydocker"
  114. fi;
  115. ################################################################################
  116. # From github.com/zsh-users:
  117. # * zsh-autosuggestions
  118. # * zsh-syntax-highlighting
  119. # Both can be installed through Homebrew.
  120. ################################################################################
  121. if command -v brew >> /dev/null; then
  122. source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  123. source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  124. source $(brew --prefix)/opt/zsh-vi-mode/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
  125. fi
  126. ################################################################################
  127. # fzf
  128. ################################################################################
  129. if command -v fzf >> /dev/null; then
  130. eval "$(fzf --zsh)"
  131. fi
  132. ################################################################################
  133. # Keybinds
  134. ################################################################################
  135. # Ctrl+Y copies buffer to clipboard
  136. cmd_to_clip () { pbcopy <<< $BUFFER }
  137. zle -N cmd_to_clip
  138. bindkey '^Y' cmd_to_clip
  139. # Ctrl+G copies git-tracked file contents in directory to the clipboard
  140. copy_dir_llm_style () {
  141. git ls-files | column;
  142. if read -s -q "choice?Total files: $( git ls-files | wc -l) | Press 'y' to copy contents"; then;
  143. {
  144. echo "Here is the contents of \`$(basename "$PWD")/\`:\n";
  145. git ls-files -z |
  146. while IFS= read -r -d $'\0' f; do
  147. if [[ "$(file -b --mime-type "$f")" == "text/"* ]]; then
  148. echo "$f"; echo '```';
  149. cat "$f"; echo '```';
  150. echo;
  151. fi
  152. done;
  153. } | pbcopy
  154. echo "\nCopied!"
  155. else;
  156. echo "\nQuit without copying anything"
  157. fi
  158. }
  159. zle -N copy_dir_llm_style
  160. bindkey '^G' copy_dir_llm_style