.zshrc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # Shell options
  2. setopt autocd correct globdots extendedglob nomatch notify \
  3. share_history inc_append_history hist_expire_dups_first hist_reduce_blanks \
  4. hist_find_no_dups hist_verify extended_history auto_pushd pushd_ignore_dups \
  5. prompt_subst
  6. unsetopt beep
  7. bindkey -e
  8. # Load secrets
  9. if [[ -f .env ]]; then
  10. set -a # automatically export all variables
  11. source .env
  12. set +a
  13. fi
  14. # Completions
  15. local compdump=${XDG_CACHE_HOME:-$HOME/.cache}/zsh/zcompdump-${HOST}-${ZSH_VERSION}
  16. [[ -d ${compdump:h} ]] || mkdir -p ${compdump:h}
  17. zstyle ':completion:*' menu select
  18. zstyle ':completion:*' gain-privileges 1
  19. zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
  20. zmodload zsh/complist
  21. autoload -Uz compinit && compinit -d "$compdump"
  22. # History
  23. HISTFILE=${XDG_STATE_HOME:-$HOME}/.histfile
  24. [[ -d $HISTFILE:h ]] || mkdir -p $HISTFILE:h
  25. HISTSIZE=1000000
  26. SAVEHIST=1000000
  27. autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
  28. zle -N up-line-or-beginning-search
  29. zle -N down-line-or-beginning-search
  30. # Colors
  31. autoload -Uz colors && colors
  32. # Prompt
  33. if [[ $EUID -eq 0 ]]; then
  34. user_color=red
  35. else
  36. user_color=white
  37. fi
  38. # Assign colors based on the hostname
  39. if [[ -v TOOLBOX_PATH ]]; then
  40. host_color=magenta
  41. elif [[ -v DISTROBOX_ENTER_PATH ]]; then
  42. host_color=15
  43. else
  44. case $HOSTNAME in
  45. laptop) host_color=green ;;
  46. workstation) host_color=red ;;
  47. bryan-pc) host_color=cyan ;;
  48. time4vps) host_color=blue ;;
  49. racknerd) host_color=yellow ;;
  50. htpc) host_color=214 ;;
  51. hartmanlab) host_color=magenta ;;
  52. router) host_color=blue ;;
  53. ax6000) host_color=87 ;;
  54. home-router) host_color=218 ;;
  55. vm-fedora*) host_color=57 ;;
  56. *) host_color=white ;;
  57. esac
  58. fi
  59. _git_prompt() {
  60. local br
  61. if br=$(git symbolic-ref --short HEAD 2>/dev/null); then
  62. print -n " %F{242}($br)%f"
  63. fi
  64. }
  65. PROMPT='[%F{'$user_color'}%n%f@%F{'$host_color'}%m%f]%~$(_git_prompt)%(!.#.$) '
  66. # RPROMPT='%*' # display clock to right of screen
  67. precmd() { print -Pn "\e]0;%n@%m: ${PWD/#$HOME/~}\a" ; }
  68. # Set hostname on OpenWRT
  69. [[ -z $HOSTNAME ]] && HOSTNAME=$(noglob uci get system.@system[0].hostname 2>/dev/null)
  70. # Paths
  71. typeset -U path PATH
  72. path=(
  73. $HOME/bin
  74. $HOME/.local/bin
  75. $HOME/documents/develop/scripts/shell
  76. $path
  77. )
  78. export PATH
  79. export R_LIBS_USER="$HOME/R/qhtcp-workflow"
  80. # Keybindings
  81. typeset -g -A key
  82. for k v in \
  83. Home khome End kend Insert kich1 Backspace kbs Delete kdch1 \
  84. Up kcuu1 Down kcud1 Left kcub1 Right kcuf1 PageUp kpp PageDown knp ShiftTab kcbt; do
  85. [[ -n ${terminfo[$v]} ]] && key[$k]=${terminfo[$v]}
  86. done
  87. bindkey -- ${key[Home]-} beginning-of-line
  88. bindkey -- ${key[End]-} end-of-line
  89. bindkey -- ${key[Insert]-} overwrite-mode
  90. bindkey -- ${key[Backspace]-} backward-delete-char
  91. bindkey -- ${key[Delete]-} delete-char
  92. bindkey -- ${key[Left]-} backward-char
  93. bindkey -- ${key[Right]-} forward-char
  94. bindkey -- ${key[PageUp]-} beginning-of-buffer-or-history
  95. bindkey -- ${key[PageDown]-} end-of-buffer-or-history
  96. bindkey -- ${key[ShiftTab]-} reverse-menu-complete
  97. bindkey -- ${key[Up]-} up-line-or-beginning-search
  98. bindkey -- ${key[Down]-} down-line-or-beginning-search
  99. if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
  100. autoload -Uz add-zle-hook-widget
  101. zle_app_start() { echoti smkx; }
  102. zle_app_finish() { echoti rmkx; }
  103. add-zle-hook-widget zle-line-init zle_app_start
  104. add-zle-hook-widget zle-line-finish zle_app_finish
  105. fi
  106. # Aliases and one-liners
  107. alias ll='ls -lh'
  108. alias la='ls -A'
  109. alias vmd='vmd -nt'
  110. alias dnf-list-files='dnf repoquery -l'
  111. alias gedit='gnome-text-editor'
  112. alias xclip='xclip -selection c'
  113. alias pdoman='podman'
  114. alias workon='virtualenv-workon'
  115. alias git-list='git ls-tree -r HEAD --name-only'
  116. alias chatgpt='chatgpt --model gpt-4o'
  117. podman-update-images() {
  118. podman images --format '{{.Repository}}' | grep -v '^<none>$' | xargs -r -L1 podman pull
  119. }
  120. buildah-prune() { buildah rm --all; }