0
0

.zshrc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. ################################################################################
  14. # History
  15. ################################################################################
  16. HISTFILE=${ZDOTDIR}/.zsh_history
  17. HISTSIZE=2147483647
  18. SAVEHIST=$HISTSIZE
  19. export HISTORY_IGNORE="(ls|lsd|la|cd|pwd|exit)*"
  20. setopt HIST_EXPIRE_DUPS_FIRST
  21. setopt HIST_IGNORE_ALL_DUPS
  22. setopt HIST_IGNORE_DUPS
  23. setopt HIST_IGNORE_SPACE
  24. setopt HIST_REDUCE_BLANKS
  25. setopt HIST_VERIFY
  26. setopt INC_APPEND_HISTORY
  27. setopt SHARE_HISTORY
  28. ################################################################################
  29. # Prompt
  30. ################################################################################
  31. # A pleasant, informative, and transient prompt. Made possible by an arcane
  32. # incantation from [powerlevel10k](https://github.com/romkatv/powerlevel10k/),
  33. # as described in the project's issue tracker:
  34. # https://github.com/romkatv/powerlevel10k/issues/888#issuecomment-657969840
  35. autoload -Uz compinit
  36. compinit
  37. autoload -Uz vcs_info
  38. precmd_vcs_info() { vcs_info }
  39. setopt prompt_subst
  40. zstyle ':vcs_info:git:*' formats '%F{3}%F{8} %b '
  41. set-long-prompt() {
  42. if [ "$NEW_LINE_BEFORE_PROMPT" -eq 1 ]; then
  43. print ''
  44. else
  45. NEW_LINE_BEFORE_PROMPT=1
  46. fi
  47. 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
  48. %F{3}$ %f%k'
  49. }
  50. set-short-prompt() {
  51. if [[ $PROMPT != '%F{3}$ %f%k' ]]; then
  52. PROMPT='%F{3}$ %f%k'
  53. zle .reset-prompt
  54. fi
  55. }
  56. precmd_functions=(
  57. set-long-prompt
  58. precmd_vcs_info
  59. )
  60. zle-line-finish() {
  61. set-short-prompt
  62. }
  63. zle -N zle-line-finish
  64. trap 'set-short-prompt; return 130' INT
  65. ################################################################################
  66. # Potentially interactive execution
  67. ################################################################################
  68. # Load SSH key into keychain
  69. if [[ $OSTYPE == darwin* ]] then
  70. ssh-add --apple-use-keychain $HOME/.ssh/id_rsa >/dev/null 2>&1
  71. else
  72. eval `keychain --eval --quiet id_rsa`
  73. fi
  74. ################################################################################
  75. # Aliases
  76. ################################################################################
  77. alias c="clear && NEW_LINE_BEFORE_PROMPT=0"
  78. alias clear="clear && NEW_LINE_BEFORE_PROMPT=0"
  79. # nvim
  80. if command -v nvim &>/dev/null; then;
  81. alias n="nvim"
  82. fi;
  83. # granted
  84. if command -v assume &>/dev/null; then;
  85. alias assume=". assume"
  86. fi;
  87. # brew
  88. if command -v brew &>/dev/null; then;
  89. alias brewdump="(cd $XDG_CONFIG_HOME/brew/ && brew bundle dump --force --describe)"
  90. fi;
  91. # docker
  92. if command -v docker &>/dev/null; then;
  93. alias dockerprune="(docker system prune -a -f && docker system df -v) | less"
  94. fi;
  95. # git
  96. if command -v git &>/dev/null; then;
  97. alias g="git"
  98. alias gs="git s"
  99. alias gl="git l"
  100. fi;
  101. # lsd
  102. if command -v lsd &>/dev/null; then;
  103. alias ls="lsd -a"
  104. alias la="lsd -la"
  105. fi;
  106. # lazygit
  107. if command -v lazygit &>/dev/null; then;
  108. alias lg="lazygit"
  109. fi;
  110. # lazydocker
  111. if command -v lazydocker &>/dev/null; then;
  112. alias lg="lazydocker"
  113. fi;
  114. ################################################################################
  115. # fzf
  116. ################################################################################
  117. if command -v fzf >> /dev/null; then
  118. eval "$(fzf --zsh)"
  119. fi
  120. ################################################################################
  121. # From github.com/zsh-users:
  122. # * zsh-autosuggestions
  123. # * zsh-syntax-highlighting
  124. # Both can be installed through Homebrew.
  125. ################################################################################
  126. if command -v brew >> /dev/null; then
  127. source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  128. source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  129. fi