Advertisement
Berny23

.zshrc

Jan 28th, 2025
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 12.91 KB | Software | 0 0
  1. # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
  2. # Initialization code that may require console input (password prompts, [y/n]
  3. # confirmations, etc.) must go above this block; everything else may go below.
  4. if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  5.   source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
  6. fi
  7.  
  8. ## Options section
  9. setopt correct                                                  # Auto correct mistakes
  10. setopt extendedglob                                             # Extended globbing. Allows using regular expressions with *
  11. setopt nocaseglob                                               # Case insensitive globbing
  12. setopt rcexpandparam                                            # Array expension with parameters
  13. setopt nocheckjobs                                              # Don't warn about running processes when exiting
  14. setopt numericglobsort                                          # Sort filenames numerically when it makes sense
  15. setopt nobeep                                                   # No beep
  16. setopt appendhistory                                            # Immediately append history instead of overwriting
  17. setopt histignorealldups                                        # If a new command is a duplicate, remove the older one
  18. setopt autocd                                                   # if only directory path is entered, cd there.
  19. setopt inc_append_history                                       # save commands are added to the history immediately, otherwise only when shell exits.
  20. setopt histignorespace                                          # Don't save commands that start with space
  21.  
  22. zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' # Case insensitive tab completion
  23. zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"         # Colored completion (different colors for dirs/files/etc)
  24. zstyle ':completion:*' rehash true                              # automatically find new executables in path
  25. zstyle ':completion:*' menu select                              # Highlight menu selection
  26. # Speed up completions
  27. zstyle ':completion:*' accept-exact '*(N)'
  28. zstyle ':completion:*' use-cache on
  29. zstyle ':completion:*' cache-path ~/.zsh/cache
  30. HISTFILE=~/.histfile
  31. HISTSIZE=10000
  32. SAVEHIST=10000
  33. #export EDITOR=/usr/bin/nano
  34. #export VISUAL=/usr/bin/nano
  35. WORDCHARS=${WORDCHARS//\/[&.;]}                                 # Don't consider certain characters part of the word
  36.  
  37. ## Keybindings section
  38. bindkey -e
  39. bindkey '^[[7~' beginning-of-line                               # Home key
  40. bindkey '^[[H' beginning-of-line                                # Home key
  41. if [[ "${terminfo[khome]}" != "" ]]; then
  42.   bindkey "${terminfo[khome]}" beginning-of-line                # [Home] - Go to beginning of line
  43. fi
  44. bindkey '^[[8~' end-of-line                                     # End key
  45. bindkey '^[[F' end-of-line                                     # End key
  46. if [[ "${terminfo[kend]}" != "" ]]; then
  47.   bindkey "${terminfo[kend]}" end-of-line                       # [End] - Go to end of line
  48. fi
  49. bindkey '^[[2~' overwrite-mode                                  # Insert key
  50. bindkey '^[[3~' delete-char                                     # Delete key
  51. bindkey '^[[C'  forward-char                                    # Right key
  52. bindkey '^[[D'  backward-char                                   # Left key
  53. bindkey '^[[5~' history-beginning-search-backward               # Page up key
  54. bindkey '^[[6~' history-beginning-search-forward                # Page down key
  55.  
  56. # Navigate words with ctrl+arrow keys
  57. bindkey '^[Oc' forward-word                                     #
  58. bindkey '^[Od' backward-word                                    #
  59. bindkey '^[[1;5D' backward-word                                 #
  60. bindkey '^[[1;5C' forward-word                                  #
  61. bindkey '^H' backward-kill-word                                 # delete previous word with ctrl+backspace
  62. bindkey '^[[Z' undo                                             # Shift+tab undo last action
  63.  
  64. ## Alias section
  65. alias cp="cp -i"                                                # Confirm before overwriting something
  66. alias df='df -h'                                                # Human-readable sizes
  67. alias free='free -m'                                            # Show sizes in MB
  68. alias gitu='git add . && git commit && git push'
  69.  
  70. # Theming section
  71. autoload -U compinit colors zcalc
  72. compinit -d
  73. colors
  74.  
  75. # Color man pages
  76. export LESS_TERMCAP_mb=$'\E[01;32m'
  77. export LESS_TERMCAP_md=$'\E[01;32m'
  78. export LESS_TERMCAP_me=$'\E[0m'
  79. export LESS_TERMCAP_se=$'\E[0m'
  80. export LESS_TERMCAP_so=$'\E[01;47;34m'
  81. export LESS_TERMCAP_ue=$'\E[0m'
  82. export LESS_TERMCAP_us=$'\E[01;36m'
  83. export LESS=-R
  84.  
  85. ## Plugins section: Enable fish style features
  86. # Use syntax highlighting
  87. source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  88. # Use history substring search
  89. source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
  90. # bind UP and DOWN arrow keys to history substring search
  91. zmodload zsh/terminfo
  92. bindkey "$terminfo[kcuu1]" history-substring-search-up
  93. bindkey "$terminfo[kcud1]" history-substring-search-down
  94. bindkey '^[[A' history-substring-search-up
  95. bindkey '^[[B' history-substring-search-down
  96.  
  97. # Set terminal window and tab/icon title
  98. #
  99. # usage: title short_tab_title [long_window_title]
  100. #
  101. # See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
  102. # Fully supports screen and probably most modern xterm and rxvt
  103. # (In screen, only short_tab_title is used)
  104. function title {
  105.   emulate -L zsh
  106.   setopt prompt_subst
  107.  
  108.   [[ "$EMACS" == *term* ]] && return
  109.  
  110.   # if $2 is unset use $1 as default
  111.   # if it is set and empty, leave it as is
  112.   : ${2=$1}
  113.  
  114.   case "$TERM" in
  115.     xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|kitty|wezterm|st*)
  116.       print -Pn "\e]2;${2:q}\a" # set window name
  117.       print -Pn "\e]1;${1:q}\a" # set tab name
  118.       ;;
  119.     screen*|tmux*)
  120.       print -Pn "\ek${1:q}\e\\" # set screen hardstatus
  121.       ;;
  122.     *)
  123.     # Try to use terminfo to set the title
  124.     # If the feature is available set title
  125.     if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
  126.       echoti tsl
  127.       print -Pn "$1"
  128.       echoti fsl
  129.     fi
  130.       ;;
  131.   esac
  132. }
  133.  
  134. ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
  135. ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~"
  136.  
  137. # Runs before showing the prompt
  138. function mzc_termsupport_precmd {
  139.   [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
  140.   title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
  141. }
  142.  
  143. # Runs before executing the command
  144. function mzc_termsupport_preexec {
  145.   [[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
  146.  
  147.   emulate -L zsh
  148.  
  149.   # split command into array of arguments
  150.   local -a cmdargs
  151.   cmdargs=("${(z)2}")
  152.   # if running fg, extract the command from the job description
  153.   if [[ "${cmdargs[1]}" = fg ]]; then
  154.     # get the job id from the first argument passed to the fg command
  155.     local job_id jobspec="${cmdargs[2]#%}"
  156.     # logic based on jobs arguments:
  157.     # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs
  158.     # https://www.zsh.org/mla/users/2007/msg00704.html
  159.     case "$jobspec" in
  160.       <->) # %number argument:
  161.         # use the same <number> passed as an argument
  162.         job_id=${jobspec} ;;
  163.       ""|%|+) # empty, %% or %+ argument:
  164.         # use the current job, which appears with a + in $jobstates:
  165.         # suspended:+:5071=suspended (tty output)
  166.         job_id=${(k)jobstates[(r)*:+:*]} ;;
  167.       -) # %- argument:
  168.         # use the previous job, which appears with a - in $jobstates:
  169.         # suspended:-:6493=suspended (signal)
  170.         job_id=${(k)jobstates[(r)*:-:*]} ;;
  171.       [?]*) # %?string argument:
  172.         # use $jobtexts to match for a job whose command *contains* <string>
  173.         job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;;
  174.       *) # %string argument:
  175.         # use $jobtexts to match for a job whose command *starts with* <string>
  176.         job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;;
  177.     esac
  178.  
  179.     # override preexec function arguments with job command
  180.     if [[ -n "${jobtexts[$job_id]}" ]]; then
  181.       1="${jobtexts[$job_id]}"
  182.       2="${jobtexts[$job_id]}"
  183.     fi
  184.   fi
  185.  
  186.   # cmd name only, or if this is sudo or ssh, the next cmd
  187.   local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
  188.   local LINE="${2:gs/%/%%}"
  189.  
  190.   title '$CMD' '%100>...>$LINE%<<'
  191. }
  192.  
  193. autoload -U add-zsh-hook
  194. add-zsh-hook precmd mzc_termsupport_precmd
  195. add-zsh-hook preexec mzc_termsupport_preexec
  196.  
  197. # Required for $langinfo
  198. zmodload zsh/langinfo
  199.  
  200. # URL-encode a string
  201. #
  202. # Encodes a string using RFC 2396 URL-encoding (%-escaped).
  203. # See: https://www.ietf.org/rfc/rfc2396.txt
  204. #
  205. # By default, reserved characters and unreserved "mark" characters are
  206. # not escaped by this function. This allows the common usage of passing
  207. # an entire URL in, and encoding just special characters in it, with
  208. # the expectation that reserved and mark characters are used appropriately.
  209. # The -r and -m options turn on escaping of the reserved and mark characters,
  210. # respectively, which allows arbitrary strings to be fully escaped for
  211. # embedding inside URLs, where reserved characters might be misinterpreted.
  212. #
  213. # Prints the encoded string on stdout.
  214. # Returns nonzero if encoding failed.
  215. #
  216. # Usage:
  217. #  zsh_urlencode [-r] [-m] [-P] <string> [<string> ...]
  218. #
  219. #    -r causes reserved characters (;/?:@&=+$,) to be escaped
  220. #
  221. #    -m causes "mark" characters (_.!~*''()-) to be escaped
  222. #
  223. #    -P causes spaces to be encoded as '%20' instead of '+'
  224. function zsh_urlencode() {
  225.   emulate -L zsh
  226.   local -a opts
  227.   zparseopts -D -E -a opts r m P
  228.  
  229.   local in_str="$@"
  230.   local url_str=""
  231.   local spaces_as_plus
  232.   if [[ -z $opts[(r)-P] ]]; then spaces_as_plus=1; fi
  233.   local str="$in_str"
  234.  
  235.   # URLs must use UTF-8 encoding; convert str to UTF-8 if required
  236.   local encoding=$langinfo[CODESET]
  237.   local safe_encodings
  238.   safe_encodings=(UTF-8 utf8 US-ASCII)
  239.   if [[ -z ${safe_encodings[(r)$encoding]} ]]; then
  240.     str=$(echo -E "$str" | iconv -f $encoding -t UTF-8)
  241.     if [[ $? != 0 ]]; then
  242.       echo "Error converting string from $encoding to UTF-8" >&2
  243.       return 1
  244.     fi
  245.   fi
  246.  
  247.   # Use LC_CTYPE=C to process text byte-by-byte
  248.   local i byte ord LC_ALL=C
  249.   export LC_ALL
  250.   local reserved=';/?:@&=+$,'
  251.   local mark='_.!~*''()-'
  252.   local dont_escape="[A-Za-z0-9"
  253.   if [[ -z $opts[(r)-r] ]]; then
  254.     dont_escape+=$reserved
  255.   fi
  256.   # $mark must be last because of the "-"
  257.   if [[ -z $opts[(r)-m] ]]; then
  258.     dont_escape+=$mark
  259.   fi
  260.   dont_escape+="]"
  261.  
  262.   # Implemented to use a single printf call and avoid subshells in the loop,
  263.   # for performance
  264.   local url_str=""
  265.   for (( i = 1; i <= ${#str}; ++i )); do
  266.     byte="$str[i]"
  267.     if [[ "$byte" =~ "$dont_escape" ]]; then
  268.       url_str+="$byte"
  269.     else
  270.       if [[ "$byte" == " " && -n $spaces_as_plus ]]; then
  271.         url_str+="+"
  272.       else
  273.         ord=$(( [##16] #byte ))
  274.         url_str+="%$ord"
  275.       fi
  276.     fi
  277.   done
  278.   echo -E "$url_str"
  279. }
  280.  
  281. # Emits the control sequence to notify many terminal emulators
  282. # of the cwd
  283. #
  284. # Identifies the directory using a file: URI scheme, including
  285. # the host name to disambiguate local vs. remote paths.
  286. function mzc_termsupport_cwd {
  287.   # Percent-encode the host and path names.
  288.   local URL_HOST URL_PATH
  289.   URL_HOST="$(zsh_urlencode -P $HOST)" || return 1
  290.   URL_PATH="$(zsh_urlencode -P $PWD)" || return 1
  291.  
  292.   # common control sequence (OSC 7) to set current host and path
  293.   printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}"
  294. }
  295.  
  296. # Use a precmd hook instead of a chpwd hook to avoid contaminating output
  297. # i.e. when a script or function changes directory without `cd -q`, chpwd
  298. # will be called the output may be swallowed by the script or function.
  299. add-zsh-hook precmd mzc_termsupport_cwd
  300.  
  301. # File and Dir colors for ls and other outputs
  302. export LS_OPTIONS='--color=auto'
  303. eval "$(dircolors -b)"
  304. alias ls='ls $LS_OPTIONS'
  305.  
  306. ###
  307. #
  308. # Eigene Anpassungen
  309. #
  310. ###
  311.  
  312. export PATH=$PATH:/home/berny23/.spicetify
  313. export XDG_DATA_DIRS="$XDG_DATA_DIRS:/var/lib/flatpak/exports/share:/home/berny23/.local/share/flatpak/exports/share"
  314.  
  315. export QT_QPA_PLATFORM="wayland;xcb"
  316. export GDK_BACKEND=wayland
  317. export ELECTRON_OZONE_PLATFORM_HINT=wayland
  318. export ENABLE_HDR_WSI=1
  319. export SDL_VIDEODRIVER=wayland
  320.  
  321. # Fix dark mode in Flatpaks
  322. export GTK_THEME=Breeze:dark
  323.  
  324. export CUDAToolkit_ROOT="/opt/cuda"
  325. export CUDACXX="/opt/cuda/bin/nvcc"
  326.  
  327. alias ls="ls -alih --color=auto"
  328.  
  329. source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme
  330.  
  331. # zinit zsh plugin manager (via AUR)
  332. source "/usr/share/zinit/zinit.zsh"
  333. zinit ice wait lucid
  334. zinit light joshskidmore/zsh-fzf-history-search
  335.  
  336. ###
  337. #
  338. # Prompt von Powerlevel10k laden
  339. #
  340. ###
  341.  
  342. # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
  343. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
  344.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement