From 88522c934f3ce21ef3eb32c1ddd76ed0c35f9748 Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Tue, 23 May 2023 10:22:24 -0500 Subject: [PATCH] refactored: completion system --- .gitignore | 2 +- .zshenv | 4 ++- .zshrc | 70 +++++++++++-------------------------- completions/completions.zsh | 43 +++++++++++++++++++++++ include/aliases.zsh | 16 +++++---- include/functions.zsh | 12 +++---- include/plugins.zsh | 31 ++++++++++------ 7 files changed, 102 insertions(+), 76 deletions(-) create mode 100644 completions/completions.zsh diff --git a/.gitignore b/.gitignore index 73f6819..ed5fc63 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ !.zshenv !.zprofile !include/ - +!completions/ diff --git a/.zshenv b/.zshenv index 615c9ea..231eec6 100644 --- 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 5cafc87..085999a 100644 --- 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 index 0000000..60437f3 --- /dev/null +++ b/completions/completions.zsh @@ -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)" diff --git a/include/aliases.zsh b/include/aliases.zsh index 4fec9c9..69f3a01 100644 --- a/include/aliases.zsh +++ b/include/aliases.zsh @@ -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' diff --git a/include/functions.zsh b/include/functions.zsh index 7be567d..5e6a6ff 100644 --- a/include/functions.zsh +++ b/include/functions.zsh @@ -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 diff --git a/include/plugins.zsh b/include/plugins.zsh index b81330b..c9e4207 100644 --- a/include/plugins.zsh +++ b/include/plugins.zsh @@ -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 -- 2.44.2