.zshrc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. ### SHELL OPTIONS ###
  2. setopt autocd correct globdots extendedglob nomatch notify
  3. unsetopt beep
  4. bindkey -e
  5. ### AUTOCOMPLETION ###
  6. zstyle ':completion::complete:*' gain-privileges 1
  7. zstyle ':completion:*' menu select
  8. zstyle ':completion:*:ssh:*' hosts
  9. autoload -Uz compinit
  10. compinit
  11. ### HISTORY ###
  12. setopt share_history inc_append_history hist_expire_dups_first hist_reduce_blanks hist_find_no_dups
  13. HISTFILE=~/.histfile
  14. HISTSIZE=10000000
  15. SAVEHIST=100000
  16. HISTCONTROL=ignorespace
  17. # History search
  18. autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
  19. zle -N up-line-or-beginning-search
  20. zle -N down-line-or-beginning-search
  21. [[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-beginning-search
  22. [[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-beginning-search
  23. ### PROMPT ###
  24. autoload -Uz promptinit
  25. promptinit
  26. # Color codes
  27. # https://www.ditig.com/publications/256-colors-cheat-sheet
  28. # color root user red
  29. if [[ $USER == "root" ]]; then
  30. user_color="red"
  31. else
  32. user_color="white"
  33. fi
  34. # For OpenWRT
  35. [[ -z $HOSTNAME ]] && HOSTNAME=$(noglob uci get system.@system[0].hostname)
  36. # For toolbox
  37. if [[ -v TOOLBOX_PATH ]]; then
  38. host_color=magenta
  39. else
  40. case $HOSTNAME in;
  41. laptop)
  42. host_color=green
  43. ;;
  44. workstation)
  45. host_color=red
  46. ;;
  47. bryan-pc)
  48. host_color=cyan
  49. ;;
  50. time4vps)
  51. host_color=blue
  52. ;;
  53. racknerd)
  54. host_color=yellow
  55. ;;
  56. htpc)
  57. host_color=214 # orange
  58. ;;
  59. hartmanlab)
  60. host_color=magenta
  61. ;;
  62. router)
  63. host_color=blue
  64. ;;
  65. ax6000)
  66. host_color=87 # slate gray
  67. ;;
  68. home-router)
  69. host_color=218 # pink
  70. ;;
  71. *)
  72. echo "Hostname $HOSTNAME unknown, consider adding to .zshrc"
  73. host_color=white
  74. ;;
  75. esac
  76. fi
  77. PS1="[%F{${user_color}}%n%F{white}@%{%F{${host_color}}%}%m%F{white}]%~$ "
  78. case $TERM in
  79. xterm*)
  80. precmd () {print -Pn "\e]0;${PWD/$HOME/\~}\a"}
  81. ;;
  82. esac
  83. ### PATH ###
  84. typeset -U PATH path
  85. BINPATH="$HOME/bin"
  86. GOPATH="$HOME/go"
  87. path+=("${GOPATH//://bin:}/bin" "$HOME/Documents/develop/scripts/shell" "$HOME/.local/bin" "$HOME/.local/bin/*")
  88. export PATH
  89. ### ALIASES ###
  90. alias vmd='vmd -nt'
  91. alias -g dnf-list-files='dnf repoquery -l'
  92. alias -g gedit='gnome-text-editor'
  93. alias -g dnf='dnf5'
  94. alias xclip="xclip -selection c" # shouldn't need this on wayland, use wl-copy instead
  95. alias -g pdoman="podman"
  96. alias virtualenv-workon="workon"
  97. alias git-list="git ls-tree -r master --name-only"
  98. ### KEYBINDINGS ###
  99. # create a zkbd compatible hash;
  100. # to add other keys to this hash, see: man 5 terminfo
  101. typeset -g -A key
  102. key[Home]="${terminfo[khome]}"
  103. key[End]="${terminfo[kend]}"
  104. key[Insert]="${terminfo[kich1]}"
  105. key[Backspace]="${terminfo[kbs]}"
  106. key[Delete]="${terminfo[kdch1]}"
  107. key[Up]="${terminfo[kcuu1]}"
  108. key[Down]="${terminfo[kcud1]}"
  109. key[Left]="${terminfo[kcub1]}"
  110. key[Right]="${terminfo[kcuf1]}"
  111. key[PageUp]="${terminfo[kpp]}"
  112. key[PageDown]="${terminfo[knp]}"
  113. key[ShiftTab]="${terminfo[kcbt]}"
  114. # setup key accordingly
  115. [[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
  116. [[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
  117. [[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode
  118. [[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
  119. [[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
  120. [[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history
  121. [[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history
  122. [[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char
  123. [[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char
  124. [[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
  125. [[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
  126. [[ -n "${key[ShiftTab]}" ]] && bindkey -- "${key[ShiftTab]}" reverse-menu-complete
  127. # Finally, make sure the terminal is in application mode, when zle is
  128. # active. Only then are the values from $terminfo valid.
  129. if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
  130. autoload -Uz add-zle-hook-widget
  131. function zle_application_mode_start {
  132. echoti smkx
  133. }
  134. function zle_application_mode_stop {
  135. echoti rmkx
  136. }
  137. add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
  138. add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
  139. fi
  140. # Functions
  141. function podman-update-images () {
  142. podman images |grep -v REPOSITORY|awk '{print $1}'|xargs -L1 podman pull
  143. }
  144. function extract()
  145. {
  146. if [ -f $1 ] ; then
  147. case $1 in
  148. *.tar.bz2) tar xvjf $1 ;;
  149. *.tar.gz) tar xvzf $1 ;;
  150. *.bz2) bunzip2 $1 ;;
  151. *.rar) unrar x $1 ;;
  152. *.gz) gunzip $1 ;;
  153. *.tar) tar xvf $1 ;;
  154. *.tbz2) tar xvjf $1 ;;
  155. *.tgz) tar xvzf $1 ;;
  156. *.zip) unzip $1 ;;
  157. *.Z) uncompress $1 ;;
  158. *.7z) 7z x $1 ;;
  159. *) echo "'$1' cannot be extracted via >extract<" ;;
  160. esac
  161. else
  162. echo "'$1' is not a valid file"
  163. fi
  164. }
  165. function buildah-prune() {
  166. buildah containers | cut -d" " -f 1 | tail -n +2| xargs buildah rm
  167. }