.zshrc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. autoload -U colors && colors # Load colors
  2. # git prompt
  3. autoload -Uz vcs_info
  4. precmd_vcs_info() { vcs_info; }
  5. precmd_functions+=(precmd_vcs_info)
  6. setopt prompt_subst
  7. # shellcheck disable=SC2016
  8. RPROMPT='%F{2}${vcs_info_msg_0_}%f'
  9. zstyle ':vcs_info:git:*' formats '%b'
  10. # k8s prompt
  11. get_k8s_info() {
  12. local k8s_context k8s_namespace
  13. k8s_context=$(kubectl config current-context 2>/dev/null)
  14. k8s_namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)
  15. # If both context and namespace are available, display them
  16. if [[ -n $k8s_context ]]; then
  17. echo "[${k8s_context}:${k8s_namespace}]" # the brachet type matters!
  18. fi
  19. }
  20. # shellcheck disable=SC2016
  21. RPROMPT+=' %F{yellow}$(get_k8s_info)%f'
  22. NEWLINE=$'\n'
  23. # shellcheck disable=SC2034
  24. PROMPT="%B%F{1}[%F{6}%n%F{7}@%F{4}%m%F{7}:%F{5}%80<..<%~%F{1}]%F{2}${NEWLINE}$%f%b "
  25. # history options
  26. setopt hist_ignore_all_dups
  27. setopt hist_ignore_space
  28. setopt hist_verify
  29. setopt inc_append_history
  30. setopt autocd # Automatically cd into typed directory.
  31. # completions, https://thevaluable.dev/zsh-completion-guide-examples/
  32. zstyle ':completion:*' use-ip true
  33. zstyle ':completion:*' use-cache on
  34. zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/.zcompcache"
  35. zstyle ':completion:*' completer _extensions _complete _approximate
  36. zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'
  37. zstyle ':completion:*:*:*:*:corrections' format '%F{yellow}!- %d (errors: %e) -!%f'
  38. zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'
  39. zstyle ':completion:*:warnings' format ' %F{red}-- no matches found --%f'
  40. zstyle ':completion:*' group-name ''
  41. # zstyle ':completion:*:*:-command-:*:*' group-order alias builtins functions commands
  42. zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} # Colorful Completion List
  43. zstyle ':completion:*' squeeze-slashes true
  44. # zstyle ':completion:*' file-sort access reverse
  45. # zstyle ':completion:*' file-list all # ls -l
  46. # Basic auto/tab complete:
  47. autoload -U compinit
  48. zstyle ':completion:*' menu select
  49. zmodload zsh/complist
  50. compinit
  51. _comp_options+=(globdots) # Include hidden files.
  52. # https://forum.endeavouros.com/t/tip-better-url-pasting-in-zsh/6962
  53. # First load zsh-autosuggestions
  54. source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  55. ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
  56. # other ZSH_AUTOSUGGEST config goes here
  57. # Then load url-quote-magic and bracketed-paste-magic as above
  58. autoload -U url-quote-magic bracketed-paste-magic
  59. zle -N self-insert url-quote-magic
  60. zle -N bracketed-paste bracketed-paste-magic
  61. # Now the fix, setup these two hooks:
  62. pasteinit() {
  63. OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  64. zle -N self-insert url-quote-magic
  65. }
  66. pastefinish() {
  67. zle -N self-insert $OLD_SELF_INSERT
  68. }
  69. zstyle :bracketed-paste-magic paste-init pasteinit
  70. zstyle :bracketed-paste-magic paste-finish pastefinish
  71. # and finally, make sure zsh-autosuggestions does not interfere with it:
  72. ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
  73. # emacs keybindings mode
  74. bindkey -e
  75. x-copy-region-as-kill () {
  76. zle copy-region-as-kill
  77. print -rn $CUTBUFFER | xsel -i -b
  78. }
  79. zle -N x-copy-region-as-kill
  80. x-kill-region () {
  81. zle kill-region
  82. print -rn $CUTBUFFER | xsel -i -b
  83. }
  84. zle -N x-kill-region
  85. x-yank () {
  86. CUTBUFFER=$(xsel -o -b </dev/null)
  87. zle yank
  88. }
  89. zle -N x-yank
  90. go-back() {
  91. cd ..
  92. echo ""
  93. zle reset-prompt
  94. }
  95. zle -N go-back
  96. bindkey "^\^" go-back
  97. bindkey -e '\ew' x-copy-region-as-kill
  98. bindkey -e '^W' x-kill-region
  99. bindkey -e '^Y' x-yank
  100. bindkey -s '^x' 'fzf_cmd\n' # function inside ~/.rc.d/environment_variables
  101. bindkey -s '^t' 'tmux new-session -As0\n'
  102. bindkey -s '^v' 'bg && disown\n'
  103. bindkey '^[[1;5D' backward-word
  104. bindkey '^[[1;5C' forward-word
  105. # alt + key (alt == \e)
  106. bindkey -s '\ep' 'pass-fzy.sh\n'
  107. source <(cd "$RC_DIRECTORY" && cat -- *)
  108. # Load syntax highlighting; should be last.
  109. source "$(find /usr/share/zsh* -mount -type f -name '*-syntax-highlighting*.zsh')" || echo "install zsh-syntax-highlighting"