]> git.huck.website - zsh.git/commitdiff
refactored: completion system
authorHuck Boles <huck@huck.website>
Tue, 23 May 2023 15:22:24 +0000 (10:22 -0500)
committerHuck Boles <huck@huck.website>
Tue, 23 May 2023 15:22:24 +0000 (10:22 -0500)
.gitignore
.zshenv
.zshrc
completions/completions.zsh [new file with mode: 0644]
include/aliases.zsh
include/functions.zsh
include/plugins.zsh

index 73f6819358bb62951921c32fe1107c0f2764fccb..ed5fc63df9fbe51d22264398d16ddb691cfe76b3 100644 (file)
@@ -6,4 +6,4 @@
 !.zshenv
 !.zprofile
 !include/
-
+!completions/
diff --git a/.zshenv b/.zshenv
index 615c9ea3e4b8c1e431efecb35f704f81ec0732f1..231eec648a7d0c89b8b7567a92a41d153a00b263 100644 (file)
--- a/.zshenv
+++ b/.zshenv
@@ -7,7 +7,9 @@ export XDG_CACHE_HOME="$HOME/.local/cache"
 # shell variables
 export SHELL="/bin/zsh"
 export ZSH="$ZDOTDIR"
-export ZSH_CUSTOM="$ZSH/custom"
+export ZSHEXTRA="$ZDOTDIR/extra"
+export ZSHINCLUDE="$ZDOTDIR/include"
+export ZSHCOMPLETION="$ZSH/completions"
 export ZSH_COMPDUMP="$ZSH/cache/.zcompdump-$HOST"
 
 # my folders
diff --git a/.zshrc b/.zshrc
index 5cafc8704f43b14f5bf7c2149052ef38d3d9bf9e..085999a7ad2089ec0f1f03885e1c199b0d931e6d 100644 (file)
--- a/.zshrc
+++ b/.zshrc
@@ -1,19 +1,10 @@
 #shellcheck disable=all
 
-# sourcing  -------------------------------------------------
-. $ZSH/.zshenv
-ZSHEXTRA=$ZSH/extra
-ZSHINCLUDE=$ZSH/include
-[[ ! -d $ZSH ]] && mkdir $ZSH/{cache,extra,include}
+# setup ~/.config/zsh
+. $ZDOTDIR/.zshenv
+[[ ! -d $ZSH ]] && mkdir -p $ZSH/cache $ZSHINCLUDE $ZSHCOMPLETION $ZSHEXTRA
 
-# source files from include dir
-for file in $ZSHINCLUDE/*; do . ${file}; done
-
-# start programs 
-[[ -f $XDG_CONFIG_HOME/.dircolors ]] && eval $(dircolors -b $XDG_CONFIG_HOME/.dircolors)
-[[ $(which zoxide) ]] && eval "$(zoxide init zsh --cmd z)"
-
-# options ------------------------------------------------------------
+# options
 ENABLE_CORRECTION="true"
 COMPLETION_WAITING_DOTS="true"
 HISTFILE=$ZSH/history/zsh-history
@@ -37,46 +28,26 @@ setopt auto_param_keys auto_param_slash auto_remove_slash
 setopt null_glob glob glob_dots glob_star_short bang_hist
 unsetopt flow_control
 
-# completion ---------------------------------------------------------
-zstyle ':completion:*' auto-description '%d'
-zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
-zstyle ':completion:*' completions 1
-zstyle ':completion:*' expand prefix suffix
-zstyle ':completion:*' file-sort access
-zstyle ':completion:*' format '%d'
-zstyle ':completion:*' glob 1
-zstyle ':completion:*' group-name ''
-zstyle ':completion:*' ignore-parents parent pwd
-zstyle ':completion:*' insert-unambiguous true
-zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
-zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
-zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'r:|[._-,]=** r:|=**' 'l:|=* r:|=*'
-zstyle ':completion:*' max-errors 3
-zstyle ':completion:*' menu select=long interactive
-zstyle ':completion:*' original true
-zstyle ':completion:*' prompt '%e'
-zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
-zstyle ':completion:*' squeeze-slashes true
-zstyle ':completion:*' substitute 1
-zstyle ':completion:*' verbose true
+# completion
+fpath=($ZSHCOMPLETION $fpath)
+[[ -f $ZSHCOMPLETION/completions.zsh ]] && source $ZSHCOMPLETION/completions.zsh
 
-autoload -Uz compinit
-for dump in ~/.zcompdump(N.mh+24); do
-    compinit
-done
-compinit -C
-zshcache_time="$(date +%s%N)"
+# source files from include dir
+for file in $ZSHINCLUDE/*; do . ${file}; done
 
-# zle plugins -------------------------------------------------------
+# start programs
+[[ -f $XDG_CONFIG_HOME/.dircolors ]] && eval $(dircolors -b $XDG_CONFIG_HOME/.dircolors)
+[[ $(which zoxide) ]] && eval "$(zoxide init zsh --cmd z)"
+
+# zle plugins
 autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
+autoload -Uz run-help
 
 add-zsh-hook chpwd chpwd_recent_dirs
 
 chpwd() { ls -Ah }
 
-autoload -Uz run-help
-
-# keybindings -------------------------------------------------------
+# keybindings
 bindkey "\e[1~" beginning-of-line
 bindkey "\e[4~" end-of-line
 bindkey "\e[5~" beginning-of-history
@@ -84,12 +55,12 @@ bindkey "\e[6~" end-of-history
 bindkey "\e[3~" delete-char
 bindkey "\e[2~" quoted-insert
 
-# custom prompt -----------------------------------------------------
+# custom prompt
 if [[ -n $SSH_CONNECTION ]]; then
-PROMPT='%(?..%B%F{red}x) 
-%B%F{yellow}%n%b%f@%B%F{blue}%M%b%f -> %F{green}%d %F{red}[SSH] %B%F{magenta}[gentoo]%f%b %B%F{yellow}%t %W 
+PROMPT='%(?..%B%F{red}x)
+%B%F{yellow}%n%b%f@%B%F{blue}%m%b%f: %F{cyan}%~ %F{red}[SSH] $F{magenta}[gentoo] %f$(git_prompt_enhanced_status)
 %B%F{green}%(!.#.$) %f%b> '
-RPROMPT='$(git_prompt_enhanced_status) %f[%!]'
+RPROMPT='%f[%!]'
 else
 PROMPT='%(?..%B%F{red}x)
 %B%F{green}%n%b%f@%B%F{red}%m%b%f: %F{blue}%~ %f$(git_prompt_enhanced_status)
@@ -99,4 +70,3 @@ fi
 
 PS2='%B%F{green}%(!.#.$)%f%b >  %F{cyan}*%f '
 PS3='%B%F{green}%(!.#.$)%f%b %B%F{magenta}? '
-
diff --git a/completions/completions.zsh b/completions/completions.zsh
new file mode 100644 (file)
index 0000000..60437f3
--- /dev/null
@@ -0,0 +1,43 @@
+LIST_PACKED=true
+GLOB_COMPLETE=true
+
+zstyle ':completion:*' completer _expand _extensions _complete _approximate
+zstyle ':completion:*' completions true
+zstyle ':completion:*' expand prefix suffix
+zstyle ':completion:*' insert-unambiguous true
+zstyle ':completion:*' max-errors 3
+
+zstyle ':completion:*' file-sort time follow
+zstyle ':completion:*' file-list all
+
+zstyle ':completion:*' path-completion true
+zstyle ':completion:*' glob true
+zstyle ':completion:*' group-name ''
+zstyle ':completion:*' ignore-parents parent pwd
+zstyle ':completion:*' substitute true
+zstyle ':completion:*' squeeze-slashes true
+
+zstyle ':completion:*' menu select=long search
+zstyle ':completion:*' original true
+zstyle ':completion:*' verbose true
+zstyle ':completion:*' prompt '%e'
+zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
+zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' 'r:|[._-,]=** r:|=**' 'l:|=* r:|=*'
+
+zstyle ':completion:*' gain-privileges true
+
+zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
+zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
+
+zstyle ':completion:*' auto-description '%d'
+zstyle ':completion:*:*:*:*:descriptions' format '%F{green}-- %d --%f'
+zstyle ':completion:*:corrections' format '%F{yellow}!- %d -!%f'
+zstyle ':completion:*:warnings' format '%F{red}no matches%f'
+zstyle ':completion:*:messages' format '%F{blue}== %d ==%f'
+
+autoload -Uz compinit
+for dump in ~/.zcompdump(N.mh+24); do
+    compinit
+done
+compinit -C
+zshcache_time="$(date +%s%N)"
index 4fec9c975bd16b07b43f2257f9d9d2da2de8a27b..69f3a017ffc4687d96491a927b38676e5d6e7bd6 100644 (file)
@@ -1,33 +1,35 @@
-#shell aliases
 alias cp='cp -vr'
 alias rm='rm -v'
 alias mv='mv -v'
 alias mkdir='mkdir -pv'
 alias mount='mount --mkdir'
 alias lsblk='lsblk -f'
+
 alias reload='source $ZSH/.zshrc'
 alias quit='disown -a && exit'
 alias :q='exit'
 
-# convenience aliases
 alias v='nvim'
-alias sv='sudoedit'
-alias s="s!!"
-alias sudo="sudo "
 alias vsesh='nvim -S'
 alias vdiff='nvim -d'
+
+alias sv='sudoedit'
+alias sudo="sudo "
+
 alias ..='cd ..'
 alias ...='cd ../..'
 alias ....='cd ../../..'
+
 alias h='history 0'
 alias j='jobs -l'
 alias c='clear'
-alias ear='clear'
 alias zc='cd;clear'
+
+alias cd='z '
+
 alias make='make -j16 -l6 CFLAGS="-march=bdver1"'
 alias dust='dust -rb'
 
-# ls/exa aliases
 alias ls='lsd'
 alias l='ls'
 alias ll='ls -lAh'
index 7be567dc9ab6cb761dfd8306088220dacbc96d7b..5e6a6ffb2711eb42fb793bc8836f64357e42304c 100644 (file)
@@ -6,10 +6,10 @@ f() {
 }
 
 # wrapper around cd for easier navigation + always show files in dir
-cd() {
-    z $1
-    la
-}
+cd() {
+    z $1
+    la
+}
 
 # smart remove
 rem() {
@@ -19,9 +19,9 @@ rem() {
         if [ "$(ls -A $arg)" ]; then  # move to trash if non empty dir
             mv -f "$arg" "$HOME/.trash/$1"
         elif [ -d "$arg" ]; then  # delete empty directories
-            rmdir "$arg"                   
+            rmdir "$arg"
         elif [ -f "$arg" ]; then  # move files to trash
-            mv -f "$arg" "$HOME/.trash/$1" 
+            mv -f "$arg" "$HOME/.trash/$1"
         else
             echo -e "\n\033[31;1;4mFile Not Found:\033[0m\033[34;1m $1\033[0m\n"
         fi
index b81330b1d0f489bdf200c71b2ae49af1f7c99ae9..c9e4207b7e707eaea1c377fbe9156f666b6a4d10 100644 (file)
@@ -1,16 +1,25 @@
-if [[ -d $ZSHEXTRA/zsh-autosuggestions ]]; then
-    source $ZSHEXTRA/zsh-autosuggestions/zsh-autosuggestions.zsh
-    ZSH_AUTOSUGGEST_STRATEGY=(history completion)
-    set ZSH_AUTOSUGGEST_USE_ASYNC
+# fish like autosuggestions
+if [[ ! -d $ZSHEXTRA/zsh-autosuggestions ]]; then
+    cd $ZSHEXTRA
+    git clone 'https://github.com/zsh-users/zsh-autosuggestions' "$ZSHEXTRA/zsh-autosuggestions"
 fi
+source "$ZSHEXTRA/zsh-autosuggestions/zsh-autosuggestions.zsh"
+ZSH_AUTOSUGGEST_STRATEGY=(history completion)
+set ZSH_AUTOSUGGEST_USE_ASYNC
 
-if [[ -d $ZSHEXTRA/zsh-fast-syntax-highlighting ]]; then
-    source $ZSHEXTRA/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
-    fast-theme -q $ZSH/extra/zsh-fast-syntax-highlighting/themes/custom.ini
+# syntax highlighing
+if [[ ! -d $ZSHEXTRA/zsh-fast-syntax-highlighting ]]; then
+    cd $ZSHEXTRA
+    git clone 'https://github.com/zdharma-continuum/fast-syntax-highlighting' "$ZSHEXTRA/zsh-fast-syntax-highlighting"
 fi
+source $ZSHEXTRA/zsh-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
+fast-theme -q $ZSH/extra/zsh-fast-syntax-highlighting/themes/custom.ini
 
-if [[ -d $ZSHEXTRA/zsh-history-substring-search ]]; then
-    source $ZSHEXTRA/zsh-history-substring-search/zsh-history-substring-search.zsh
-    bindkey '^[[A' history-substring-search-up
-    bindkey '^[[B' history-substring-search-down
+# up arrow history search of partial commands
+if [[ ! -d $ZSHEXTRA/zsh-history-substring-search ]]; then
+    cd $ZSHEXTRA
+    git clone 'https://github.com/zsh-users/zsh-history-substring-search'
 fi
+source $ZSHEXTRA/zsh-history-substring-search/zsh-history-substring-search.zsh "$ZSHEXTRA/zsh-history-substring-search"
+bindkey '^[[A' history-substring-search-up
+bindkey '^[[B' history-substring-search-down