Advertisement
Guest User

Untitled

a guest
Sep 19th, 2024
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.81 KB | Source Code | 0 0
  1. #           ░▒▓████████▓▒░  ░▒▓███████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓███████▓▒░   ░▒▓██████▓▒░
  2. #                  ░▒▓█▓▒░ ░▒▓█▓▒░        ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░
  3. #                ░▒▓██▓▒░  ░▒▓█▓▒░        ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
  4. #              ░▒▓██▓▒░     ░▒▓██████▓▒░  ░▒▓████████▓▒░ ░▒▓███████▓▒░  ░▒▓█▓▒░
  5. #            ░▒▓██▓▒░             ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░
  6. #  ░▒▓██▓▒░ ░▒▓█▓▒░               ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░
  7. #  ░▒▓██▓▒░ ░▒▓████████▓▒░ ░▒▓███████▓▒░  ░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░  ░▒▓██████▓▒░
  8. #
  9. #
  10.  
  11. # [[ Notes ]]
  12. # C-i fzf-completion
  13. # C-t fzf-file-widget
  14. # C-r fzf-history-widget
  15. # A-c fzf-cd-widget
  16. # Ctrl+f accepts autocompletions
  17. # Ctrl+e edit the cmd in $EDITOR
  18.  
  19.  
  20. # Autostart or attach to a tmux session when launching Zsh
  21. # Ensure the terminal is interactive before launching tmux
  22. if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
  23.     if ! tmux ls > /dev/null 2>&1; then
  24.         exec tmux new-session -As workspace
  25.     else
  26.         if tmux has-session -t workspace 2>/dev/null; then
  27.             exec tmux attach-session -t workspace
  28.         else
  29.             exec tmux attach-session
  30.         fi
  31.     fi
  32. elif ! command -v tmux &> /dev/null; then
  33.     echo "You might wanna install tmux"
  34. fi
  35.  
  36. # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
  37. # Initialization code that may require console input (password prompts, [y/n]
  38. # confirmations, etc.) must go above this block; everything else may go below.
  39. if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  40.     source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
  41. fi
  42.  
  43.  
  44. ### Added by Zinit's installer
  45. if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
  46.     print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
  47.     command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
  48.     command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
  49.         print -P "%F{33} %F{34}Installation successful.%f%b" || \
  50.         print -P "%F{160} The clone has failed.%f%b"
  51. fi
  52.  
  53. source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
  54. autoload -Uz _zinit
  55. (( ${+_comps} )) && _comps[zinit]=_zinit
  56.  
  57. # Load a few important annexes, without Turbo
  58. # (this is currently required for annexes)
  59. zinit light-mode for \
  60.     zdharma-continuum/zinit-annex-as-monitor \
  61.     zdharma-continuum/zinit-annex-bin-gem-node \
  62.     zdharma-continuum/zinit-annex-patch-dl \
  63.  
  64.     ### End of Zinit's installer chunk
  65.  
  66. # Add in prompt
  67. zinit ice depth=1; zinit light romkatv/powerlevel10k
  68.  
  69. # Plugin specific config
  70. function _history_substring_search_config() {
  71.     bindkey "^[[1;5A" history-substring-search-up
  72.     bindkey "^[[1;5B" history-substring-search-down
  73. }
  74.  
  75. # Add in zsh plugins
  76. zinit wait lucid for \
  77.     atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
  78.     zdharma-continuum/fast-syntax-highlighting \
  79.     blockf \
  80.     zsh-users/zsh-completions \
  81.     atload"!_zsh_autosuggest_start" \
  82.     atload"bindkey '^Y' autosuggest-execute" \
  83.     zsh-users/zsh-autosuggestions \
  84.     atload"!_history_substring_search_config" \
  85.     zsh-users/zsh-history-substring-search
  86.  
  87. # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
  88. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
  89.  
  90. # [[ Keybindings ]]
  91. # see https://thevaluable.dev/zsh-line-editor-configuration-mouseless/
  92. # https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
  93. # see : bindkey | fzf for a list of bindings
  94. bindkey -e
  95. bindkey '^p' history-search-backward # Ctrl+p
  96. bindkey '^n' history-search-forward # Ctrl+n
  97. bindkey '^[w' kill-region # Ctrl+w => Ctrl+<backSpace>
  98. bindkey '^[[1;5C' forward-word # Ctrl+->
  99. bindkey '\ek' forward-word # Alt+l => Ctrl+->
  100. bindkey '\ej' backward-word # Ctrl+<-
  101. bindkey '\el' forward-word # Alt+l => Ctrl+->
  102. bindkey '\eh' backward-kill-word # Alt+h => Ctrl+<backSpace>
  103. bindkey '^[[1;5D' backward-word # Ctrl+<-
  104.  
  105. autoload -U edit-command-line
  106. zle -N edit-command-line
  107. bindkey '^E' edit-command-line
  108.  
  109. # CURSOR SHAPE # https://unix.stackexchange.com/a/614203
  110. # function zle-keymap-select {
  111. #     if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then
  112. #         echo -ne '\e[1 q'
  113. #     elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] ||
  114. #     [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then
  115. #         echo -ne '\e[5 q'
  116. #     fi
  117. # }
  118. # zle -N zle-keymap-select
  119. #
  120. # _fix_cursor() { echo -ne '\e[5 q'; }
  121. # precmd_functions+=(_fix_cursor)
  122.  
  123. # [[ Snippets ]]
  124. zinit snippet OMZP::git
  125. zinit snippet OMZP::sudo
  126. zinit snippet OMZP::archlinux
  127. zinit snippet OMZP::command-not-found
  128. zinit snippet OMZP::colored-man-pages
  129.  
  130. # [[ History ]]
  131. HISTSIZE=10000
  132. HISTFILE=~/.zsh_history
  133. SAVEHIST=100000
  134. WORDCHARS='*?_-[]~&;!#$%^(){}<>|'
  135. # HISTORY_IGNORE="(ls|cd|pwd|zsh|exit|cd ..)"
  136. # HISTDUP=erase
  137. setopt appendhistory
  138. setopt sharehistory
  139. setopt hist_ignore_space
  140. # setopt hist_ignore_all_dups
  141. # setopt hist_save_no_dups
  142. setopt hist_ignore_dups
  143. setopt hist_find_no_dups
  144. setopt INTERACTIVE_COMMENTS
  145. setopt AUTO_CD # pure directory = cd into it
  146. setopt CD_SILENT
  147. setopt CHASE_LINKS # follow symlinks when they are cd target
  148. setopt NO_BANG_HIST  # don't expand `!`
  149.  
  150. # auto-escape special characters when pasting URLs
  151. autoload -U url-quote-magic bracketed-paste-magic
  152. zle -N self-insert url-quote-magic
  153. zle -N bracketed-paste bracketed-paste-magic
  154.  
  155. command_exists() {
  156.     command -v "$1" >/dev/null 2>&1
  157. }
  158.  
  159. # [[ Shell integrations ]]
  160. command -v fzf &>/dev/null && eval "$(fzf --zsh)" && source ~/.fzf.zshrc
  161. command -v zoxide &>/dev/null && eval "$(zoxide init --cmd cd zsh)"
  162. command -v thefuck &>/dev/null && eval "$(thefuck --alias)"
  163. command -v fzf &>/dev/null && source ~/.fzf.git.zshrc.sh # credits https://github.com/junegunn/fzf-git.sh
  164.  
  165. # Completion styling
  166. if ! command_exists fzf || ! command_exists rg || ! command_exists bat || ! command_exists eza; then
  167.     source ./.comp.zshrc
  168. else
  169.     source ./.comp.zshrc
  170.     zinit light Aloxaf/fzf-tab
  171.     zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
  172.     zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
  173.     zstyle ':completion:*' menu no
  174.     zstyle ':completion:*:git-checkout:*' sort false
  175.     zstyle ':completion:*:descriptions' format '[%d]'
  176.     zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
  177.     zstyle ':fzf-tab:*' popup-min-size 50 8
  178.     zstyle ':fzf-tab:*' switch-group '<' '>'
  179.     zstyle ':fzf-tab:*' fzf-command ftb-tmux-popup
  180.     zstyle ':fzf-tab:*' fzf-pad 4
  181.     zstyle ':fzf-tab:*' fzf-flags \
  182.     --border="rounded" \
  183.     --color=fg:-1,fg+:-1,bg:-1,bg+:-1 \
  184.     --color=hl:#f38ba8,hl+:#5fd7ff,info:#cba6f7,marker:#f5e0dc \
  185.     --color=prompt:#cba6f7,spinner:#f5e0dc,pointer:#f5e0dc,header:#f38ba8 \
  186.     --color=border:#6c7086,label:#aeaeae,query:#d9d9d9 \
  187.     --cycle \
  188.     --preview-window="border-rounded" \
  189.     --prompt=" " \
  190.     --marker=">" \
  191.     --pointer=" " \
  192.     --separator="─" \
  193.     --scroll-off=5 \
  194.     --height=90% \
  195.     --preview-window=border-left \
  196.     --scrollbar="│" \
  197.     --layout="reverse" \
  198.     --info="right" \
  199.  
  200.     zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'eza --color=always $realpath'
  201.     zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --icons -a --group-directories-first --git --color=always $realpath'
  202.     zstyle ':fzf-tab:complete:cd:*' popup-pad 30 0
  203.     zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-preview '[[ $group == "[process ID]" ]] && ps --pid=$word -o cmd --no-headers -w -w'
  204.     zstyle ':fzf-tab:complete:(kill|ps):argument-rest' fzf-flags --preview-window=down:3:wrap
  205.     zstyle ':fzf-tab:complete:systemctl-*:*' fzf-preview 'SYSTEMD_COLORS=1 systemctl status $word'
  206.     zstyle ':fzf-tab:complete:(-command-|-parameter-|-brace-parameter-|export|unset|expand):*' fzf-preview 'echo ${(P)word}'
  207.     zstyle ':fzf-tab:complete:git-log:*' fzf-preview 'git log --color=always $word'
  208.     zstyle ':fzf-tab:complete:git-help:*' fzf-preview 'git help $word | bat -plman --color=always'
  209.     zstyle ':fzf-tab:complete:git-(add|diff|restore):*' fzf-preview 'git diff $word | delta'
  210.     zstyle ':fzf-tab:complete:git-checkout:*' fzf-preview \
  211.         'case "$group" in
  212.        "modified file") git diff $word | delta ;;
  213.        "recent commit object name") git show --color=always $word | delta ;;
  214.        *) git log --color=always $word ;;
  215.        esac'
  216.     zstyle ':fzf-tab:complete:tldr:argument-1' fzf-preview 'tldr --color always $word'
  217. fi
  218.  
  219. # [[ Aliases ]]
  220. type bat &>/dev/null && alias cat='bat'
  221. type eza &>/dev/null && alias ls='eza --icons --group-directories-first'
  222. type eza &>/dev/null && alias ll='eza -l --icons --no-user --group-directories-first  --time-style long-iso'
  223. type eza &>/dev/null && alias la='eza -la --icons --no-user --group-directories-first  --time-style long-iso'
  224. alias ..=" cd .."
  225. alias ...=" cd ../.."
  226. alias ....=" cd ../../.."
  227. alias -g H="--help | bat --language=help --style=plain --wrap=character"
  228.  
  229.  
  230. # [[ Exports ]]
  231. # Affects filetype-coloring in eza, fd, and completion menus
  232. # DOCS https://github.com/eza-community/eza/blob/main/man/eza_colors.5.md
  233. # INFO does also accept specific files via glob, e.g. `README.md=4;33`,
  234. export CLICOLOR=1 # makes `ls` use color by default
  235. export EZA_COLORS="gm=1;38;5;208" # git `modified` with same orange as in starship
  236. export EZA_STRICT=1
  237. export EZA_ICONS_AUTO=1
  238. export EZA_ICON_SPACING=1
  239. export GREP_OPTIONS="--color=auto"
  240. export GREP_COLOR='01;35'
  241. export EDITOR=nvim
  242. export VISUAL=zeditor
  243. export ZSH_AUTOSUGGEST_STRATEGY=(match_prev_cmd history completion)
  244. export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=#d33682,fg=#002b36,bold'
  245. export HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=#dc322f,fg=#002b36,bold'
  246.  
  247. # [[ Utility Functions ]]
  248. if [[ -f ~/.func.zshrc.sh ]]; then
  249.     source ~/.func.zshrc.sh
  250. fi
  251.  
Tags: zshrc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement