Advertisement
linuxopsys-code

zshrc file

Dec 21st, 2022
5,620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.91 KB | None | 0 0
  1. # ~/.zshrc file for zsh interactive shells.
  2. # see /usr/share/doc/zsh/examples/zshrc for examples
  3.  
  4. setopt autocd # change directory just by typing its name
  5. #setopt correct # auto correct mistakes
  6. setopt interactivecomments # allow comments in interactive mode
  7. setopt magicequalsubst # enable filename expansion for arguments of the form ‘anything=expression’
  8. setopt nonomatch # hide error message if there is no match for the pattern
  9. setopt notify # report the status of background jobs immediately
  10. setopt numericglobsort # sort filenames numerically when it makes sense
  11. setopt promptsubst # enable command substitution in prompt
  12.  
  13. WORDCHARS=${WORDCHARS//\/} # Don't consider certain characters part of the word
  14.  
  15. # hide EOL sign ('%')
  16. PROMPT_EOL_MARK=""
  17.  
  18. # configure key keybindings
  19. bindkey -e # emacs key bindings
  20. bindkey ' ' magic-space # do history expansion on space
  21. bindkey '^U' backward-kill-line # ctrl + U
  22. bindkey '^[[3;5~' kill-word # ctrl + Supr
  23. bindkey '^[[3~' delete-char # delete
  24. bindkey '^[[1;5C' forward-word # ctrl + ->
  25. bindkey '^[[1;5D' backward-word # ctrl + <-
  26. bindkey '^[[5~' beginning-of-buffer-or-history # page up
  27. bindkey '^[[6~' end-of-buffer-or-history # page down
  28. bindkey '^[[H' beginning-of-line # home
  29. bindkey '^[[F' end-of-line # end
  30. bindkey '^[[Z' undo # shift + tab undo last action
  31.  
  32. # enable completion features
  33. autoload -Uz compinit
  34. compinit -d ~/.cache/zcompdump
  35. zstyle ':completion:*:*:*:*:*' menu select
  36. zstyle ':completion:*' auto-description 'specify: %d'
  37. zstyle ':completion:*' completer _expand _complete
  38. zstyle ':completion:*' format 'Completing %d'
  39. zstyle ':completion:*' group-name ''
  40. zstyle ':completion:*' list-colors ''
  41. zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
  42. zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
  43. zstyle ':completion:*' rehash true
  44. zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
  45. zstyle ':completion:*' use-compctl false
  46. zstyle ':completion:*' verbose true
  47. zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
  48.  
  49. # History configurations
  50. HISTFILE=~/.zsh_history
  51. HISTSIZE=1000
  52. SAVEHIST=2000
  53. setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
  54. setopt hist_ignore_dups # ignore duplicated commands history list
  55. setopt hist_ignore_space # ignore commands that start with space
  56. setopt hist_verify # show command with history expansion to user before running it
  57. #setopt share_history # share command history data
  58.  
  59. # force zsh to show the complete history
  60. alias history="history 0"
  61.  
  62. # configure `time` format
  63. TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S\ncpu\t%P'
  64.  
  65. # make less more friendly for non-text input files, see lesspipe(1)
  66. #[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  67.  
  68. # set variable identifying the chroot you work in (used in the prompt below)
  69. if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  70. debian_chroot=$(cat /etc/debian_chroot)
  71. fi
  72.  
  73. # set a fancy prompt (non-color, unless we know we "want" color)
  74. case "$TERM" in
  75. xterm-color|*-256color) color_prompt=yes;;
  76. esac
  77.  
  78. # uncomment for a colored prompt, if the terminal has the capability; turned
  79. # off by default to not distract the user: the focus in a terminal window
  80. # should be on the output of commands, not on the prompt
  81. force_color_prompt=yes
  82.  
  83. if [ -n "$force_color_prompt" ]; then
  84. if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  85. # We have color support; assume it's compliant with Ecma-48
  86. # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  87. # a case would tend to support setf rather than setaf.)
  88. color_prompt=yes
  89. else
  90. color_prompt=
  91. fi
  92. fi
  93.  
  94. configure_prompt() {
  95. prompt_symbol=㉿
  96. # Skull emoji for root terminal
  97. #[ "$EUID" -eq 0 ] && prompt_symbol=💀
  98. case "$PROMPT_ALTERNATIVE" in
  99. twoline)
  100. PROMPT=$'%F{%(#.blue.green)}┌──${debian_chroot:+($debian_chroot)─}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))─}(%B%F{%(#.red.blue)}%n'$prompt_symbol$'%m%b%F{%(#.blue.green)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.green)}]\n└─%B%(#.%F{red}#.%F{blue}$)%b%F{reset} '
  101. # Right-side prompt with exit codes and background processes
  102. #RPROMPT=$'%(?.. %? %F{red}%B⨯%b%F{reset})%(1j. %j %F{yellow}%B⚙%b%F{reset}.)'
  103. ;;
  104. oneline)
  105. PROMPT=$'${debian_chroot:+($debian_chroot)}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))}%B%F{%(#.red.blue)}%n@%m%b%F{reset}:%B%F{%(#.blue.green)}%~%b%F{reset}%(#.#.$) '
  106. RPROMPT=
  107. ;;
  108. backtrack)
  109. PROMPT=$'${debian_chroot:+($debian_chroot)}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))}%B%F{red}%n@%m%b%F{reset}:%B%F{blue}%~%b%F{reset}%(#.#.$) '
  110. RPROMPT=
  111. ;;
  112. esac
  113. unset prompt_symbol
  114. }
  115.  
  116. # The following block is surrounded by two delimiters.
  117. # These delimiters must not be modified. Thanks.
  118. # START KALI CONFIG VARIABLES
  119. PROMPT_ALTERNATIVE=twoline
  120. NEWLINE_BEFORE_PROMPT=yes
  121. # STOP KALI CONFIG VARIABLES
  122.  
  123. if [ "$color_prompt" = yes ]; then
  124. # override default virtualenv indicator in prompt
  125. VIRTUAL_ENV_DISABLE_PROMPT=1
  126.  
  127. configure_prompt
  128.  
  129. # enable syntax-highlighting
  130. if [ -f /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
  131. . /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  132. ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
  133. ZSH_HIGHLIGHT_STYLES[default]=none
  134. ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=white,underline
  135. ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=cyan,bold
  136. ZSH_HIGHLIGHT_STYLES[suffix-alias]=fg=green,underline
  137. ZSH_HIGHLIGHT_STYLES[global-alias]=fg=green,bold
  138. ZSH_HIGHLIGHT_STYLES[precommand]=fg=green,underline
  139. ZSH_HIGHLIGHT_STYLES[commandseparator]=fg=blue,bold
  140. ZSH_HIGHLIGHT_STYLES[autodirectory]=fg=green,underline
  141. ZSH_HIGHLIGHT_STYLES[path]=bold
  142. ZSH_HIGHLIGHT_STYLES[path_pathseparator]=
  143. ZSH_HIGHLIGHT_STYLES[path_prefix_pathseparator]=
  144. ZSH_HIGHLIGHT_STYLES[globbing]=fg=blue,bold
  145. ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=blue,bold
  146. ZSH_HIGHLIGHT_STYLES[command-substitution]=none
  147. ZSH_HIGHLIGHT_STYLES[command-substitution-delimiter]=fg=magenta,bold
  148. ZSH_HIGHLIGHT_STYLES[process-substitution]=none
  149. ZSH_HIGHLIGHT_STYLES[process-substitution-delimiter]=fg=magenta,bold
  150. ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=fg=green
  151. ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=fg=green
  152. ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=none
  153. ZSH_HIGHLIGHT_STYLES[back-quoted-argument-delimiter]=fg=blue,bold
  154. ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=yellow
  155. ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=yellow
  156. ZSH_HIGHLIGHT_STYLES[dollar-quoted-argument]=fg=yellow
  157. ZSH_HIGHLIGHT_STYLES[rc-quote]=fg=magenta
  158. ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=magenta,bold
  159. ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=magenta,bold
  160. ZSH_HIGHLIGHT_STYLES[back-dollar-quoted-argument]=fg=magenta,bold
  161. ZSH_HIGHLIGHT_STYLES[assign]=none
  162. ZSH_HIGHLIGHT_STYLES[redirection]=fg=blue,bold
  163. ZSH_HIGHLIGHT_STYLES[comment]=fg=black,bold
  164. ZSH_HIGHLIGHT_STYLES[named-fd]=none
  165. ZSH_HIGHLIGHT_STYLES[numeric-fd]=none
  166. ZSH_HIGHLIGHT_STYLES[arg0]=fg=cyan
  167. ZSH_HIGHLIGHT_STYLES[bracket-error]=fg=red,bold
  168. ZSH_HIGHLIGHT_STYLES[bracket-level-1]=fg=blue,bold
  169. ZSH_HIGHLIGHT_STYLES[bracket-level-2]=fg=green,bold
  170. ZSH_HIGHLIGHT_STYLES[bracket-level-3]=fg=magenta,bold
  171. ZSH_HIGHLIGHT_STYLES[bracket-level-4]=fg=yellow,bold
  172. ZSH_HIGHLIGHT_STYLES[bracket-level-5]=fg=cyan,bold
  173. ZSH_HIGHLIGHT_STYLES[cursor-matchingbracket]=standout
  174. fi
  175. else
  176. PROMPT='${debian_chroot:+($debian_chroot)}%n@%m:%~%(#.#.$) '
  177. fi
  178. unset color_prompt force_color_prompt
  179.  
  180. toggle_oneline_prompt(){
  181. if [ "$PROMPT_ALTERNATIVE" = oneline ]; then
  182. PROMPT_ALTERNATIVE=twoline
  183. else
  184. PROMPT_ALTERNATIVE=oneline
  185. fi
  186. configure_prompt
  187. zle reset-prompt
  188. }
  189. zle -N toggle_oneline_prompt
  190. bindkey ^P toggle_oneline_prompt
  191.  
  192. # If this is an xterm set the title to user@host:dir
  193. case "$TERM" in
  194. xterm*|rxvt*|Eterm|aterm|kterm|gnome*|alacritty)
  195. TERM_TITLE=$'\e]0;${debian_chroot:+($debian_chroot)}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))}%n@%m: %~\a'
  196. ;;
  197. *)
  198. ;;
  199. esac
  200.  
  201. precmd() {
  202. # Print the previously configured title
  203. print -Pnr -- "$TERM_TITLE"
  204.  
  205. # Print a new line before the prompt, but only if it is not the first line
  206. if [ "$NEWLINE_BEFORE_PROMPT" = yes ]; then
  207. if [ -z "$_NEW_LINE_BEFORE_PROMPT" ]; then
  208. _NEW_LINE_BEFORE_PROMPT=1
  209. else
  210. print ""
  211. fi
  212. fi
  213. }
  214.  
  215. # enable color support of ls, less and man, and also add handy aliases
  216. if [ -x /usr/bin/dircolors ]; then
  217. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  218. export LS_COLORS="$LS_COLORS:ow=30;44:" # fix ls color for folders with 777 permissions
  219.  
  220. alias ls='ls --color=auto'
  221. #alias dir='dir --color=auto'
  222. #alias vdir='vdir --color=auto'
  223.  
  224. alias grep='grep --color=auto'
  225. alias fgrep='fgrep --color=auto'
  226. alias egrep='egrep --color=auto'
  227. alias diff='diff --color=auto'
  228. alias ip='ip --color=auto'
  229.  
  230. export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink
  231. export LESS_TERMCAP_md=$'\E[1;36m' # begin bold
  232. export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink
  233. export LESS_TERMCAP_so=$'\E[01;33m' # begin reverse video
  234. export LESS_TERMCAP_se=$'\E[0m' # reset reverse video
  235. export LESS_TERMCAP_us=$'\E[1;32m' # begin underline
  236. export LESS_TERMCAP_ue=$'\E[0m' # reset underline
  237.  
  238. # Take advantage of $LS_COLORS for completion as well
  239. zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
  240. zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
  241. fi
  242.  
  243. # some more ls aliases
  244. alias ll='ls -l'
  245. alias la='ls -A'
  246. alias l='ls -CF'
  247.  
  248. # enable auto-suggestions based on the history
  249. if [ -f /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then
  250. . /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  251. # change suggestion color
  252. ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#999'
  253. fi
  254.  
  255. # enable command-not-found if installed
  256. if [ -f /etc/zsh_command_not_found ]; then
  257. . /etc/zsh_command_not_found
  258. fi
  259. compinit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement