feat(zsh): improve plugin load

This commit is contained in:
2026-03-17 22:33:20 +01:00
parent 5b2ecf82f7
commit 5a32bfeac5

View File

@@ -15,35 +15,36 @@ setopt HIST_IGNORE_SPACE # skip commands starting with space
setopt SHARE_HISTORY # share history across sessions setopt SHARE_HISTORY # share history across sessions
setopt HIST_REDUCE_BLANKS # strip extra whitespace setopt HIST_REDUCE_BLANKS # strip extra whitespace
# plugins # -- plugins --
local _plugins="$XDG_DATA_HOME/zsh/plugins" # auto-cloned on first launch, auto-updated weekly in background
local _stamp="$XDG_CACHE_HOME/zsh/plugins-updated" PLUGIN_DIR="$XDG_DATA_HOME/zsh/plugins"
local _repos=( _plugin_stamp="$XDG_CACHE_HOME/zsh/plugins-updated"
"https://github.com/zsh-users/zsh-completions" _plugin_needs_update=0
"https://github.com/zsh-users/zsh-autosuggestions"
"https://github.com/romkatv/zsh-no-ps2"
)
local _needs_update=0
if [[ ! -f "$_stamp" ]] || [[ -n $_stamp(#qN.mh+168) ]]; then # check if a week (168h) has passed since last update
mkdir -p "${_stamp:h}" if [[ ! -f "$_plugin_stamp" ]] || [[ -n $_plugin_stamp(#qN.mh+168) ]]; then
touch "$_stamp" mkdir -p "${_plugin_stamp:h}"
_needs_update=1 touch "$_plugin_stamp"
_plugin_needs_update=1
fi fi
for _repo in $_repos; do function ensure_plugin() {
if [[ ! -d "$_plugins/${_repo:t}" ]]; then local repo=$1 dir="$PLUGIN_DIR/${1##*/}"
git clone "$_repo" "$_plugins/${_repo:t}" # clone if missing, pull if update is due
elif (( _needs_update )); then if [[ ! -d "$dir" ]]; then
git -C "$_plugins/${_repo:t}" pull --quiet & git clone --depth=1 "https://github.com/$repo.git" "$dir"
elif (( _plugin_needs_update )); then
git -C "$dir" pull --quiet &
fi fi
done fpath=("$dir" $fpath)
(( _needs_update )) && wait source "$dir/${dir##*/}.plugin.zsh" 2>/dev/null
}
fpath=("$_plugins/zsh-completions/src" $fpath) ensure_plugin zsh-users/zsh-completions
ensure_plugin zsh-users/zsh-autosuggestions
ensure_plugin romkatv/zsh-no-ps2
(( _plugin_needs_update )) && wait
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ffffff,bg=cyan,bold,underline" ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ffffff,bg=cyan,bold,underline"
source "$_plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "$_plugins/zsh-no-ps2/zsh-no-ps2.plugin.zsh"
# line editing widgets # line editing widgets
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search bracketed-paste-magic autoload -Uz up-line-or-beginning-search down-line-or-beginning-search bracketed-paste-magic