.zshrc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ################################################################################
  2. # ZSH Configuration
  3. #
  4. # Note: in order for files in ~/.config/ to be picked up, be sure to set the
  5. # global XDG_* and ZDOTDIR paths. On macOS, these is set at /etc/zshenv, and
  6. # look something like the following block:
  7. #
  8. # export XDG_CONFIG_HOME=$HOME/.config
  9. # export XDG_CACHE_HOME=$HOME/.cache
  10. # export XDG_DATA_HOME=$HOME/.local/share
  11. # export XDG_STATE_HOME=$HOME/.local/state
  12. # export XDG_RUNTIME_DIR=$HOME/.run
  13. # export XDG_DATA_DIRS=/usr/local/share:/usr/share
  14. # export XDG_CONFIG_DIRS=/etc/xdg
  15. # export ZDOTDIR=$XDG_CONFIG_HOME/zsh
  16. #
  17. ################################################################################
  18. ################################################################################
  19. # Basic configuration
  20. ################################################################################
  21. export TERM=alacritty
  22. export LANG=en_US.UTF-8
  23. export HISTSIZE=50000
  24. export SAVEHIST=50000
  25. export HISTORY_IGNORE="(ls|lsd|la|cd|pwd|exit)*"
  26. setopt INC_APPEND_HISTORY
  27. setopt HIST_IGNORE_ALL_DUPS
  28. setopt HIST_IGNORE_SPACE
  29. setopt HIST_REDUCE_BLANKS
  30. ################################################################################
  31. # Prompt
  32. ################################################################################
  33. # A pleasant, informative, and transient prompt. Made possible by an arcane
  34. # incantation from [powerlevel10k](https://github.com/romkatv/powerlevel10k/),
  35. # as described in the project's issue tracker:
  36. # https://github.com/romkatv/powerlevel10k/issues/888#issuecomment-657969840
  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 ~/.ssh/id_rsa >/dev/null 2>&1
  71. else
  72. eval `keychain --eval --quiet id_rsa`
  73. fi
  74. ################################################################################
  75. # Aliases
  76. ################################################################################
  77. # Redirect Neovim when running ZSH in Vim's Floaterm
  78. if command -v floaterm &> /dev/null
  79. then
  80. alias n="floaterm"
  81. alias nvim="floaterm"
  82. fi
  83. ################################################################################
  84. # fzf
  85. ################################################################################
  86. if command -v fzf >> /dev/null; then
  87. eval "$(fzf --zsh)"
  88. fi
  89. ################################################################################
  90. # From github.com/zsh-users:
  91. # * zsh-autosuggestions
  92. # * zsh-syntax-highlighting
  93. # Both can be installed through Homebrew.
  94. ################################################################################
  95. if command -v brew >> /dev/null; then
  96. source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  97. source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  98. fi