Skip to content

Commit 9a165b3

Browse files
committed
ZSH: Add data-driven plugin system with ignore list, migrate autosuggestions
Plugins are defined in zsh_plugins.yaml and pulled as git-repo chezmoi externals into ~/.config/zsh/plugins/. A plug:: namespace provides load, is_loaded, and an ignore list (plugins_ignore) for temporarily disabling plugins locally. All plug:: state is cleaned up after startup via dot::defer. Replaces the old single-file autosuggestions external with the new plugin system. Autosuggestions now uses (history completion) strategy.
1 parent 043d27f commit 9a165b3

File tree

7 files changed

+81
-5
lines changed

7 files changed

+81
-5
lines changed

home/.chezmoidata/zsh_plugins.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ZSH plugins: downloaded as chezmoi externals, loaded by load_plugin
2+
# Fields:
3+
# repo: GitHub owner/repo (required)
4+
# description: what the plugin does
5+
# name: (optional) plugin directory name, defaults to repo name
6+
# source: (optional) file to source, defaults to <name>.plugin.zsh
7+
zsh_plugins:
8+
- repo: zsh-users/zsh-autosuggestions
9+
description: "Fish-like autosuggestions for zsh"

home/.chezmoiexternals/zsh_autosuggestions.toml

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{- range .zsh_plugins -}}
2+
{{ $name := default (base .repo) (index . "name") }}
3+
[".config/zsh/plugins/{{ $name }}"]
4+
type = "git-repo"
5+
url = "https://github.com/{{ .repo }}.git"
6+
{{ end -}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Plugins listed here (one per line) will not be loaded.
2+
# This file is not overwritten by chezmoi — local changes are preserved.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Plugin loader with local ignore list support
2+
#
3+
# Reads ~/.config/zsh/plugins_ignore once into an associative array.
4+
# plug::load checks against it and sources the plugin if not ignored.
5+
# plug::is_loaded checks if a plugin was successfully loaded.
6+
7+
typeset -A _plug_ignore=()
8+
typeset -A _plug_loaded=()
9+
typeset -i _plug_ignore_ready=0
10+
11+
_plug_load_ignore_list() {
12+
_plug_ignore_ready=1
13+
local ignore_file=~/.config/zsh/plugins_ignore
14+
[[ -f $ignore_file ]] || return
15+
local line
16+
while IFS= read -r line; do
17+
# Skip comments and blank lines
18+
[[ -z $line || $line == \#* ]] && continue
19+
_plug_ignore[$line]=1
20+
done < "$ignore_file"
21+
}
22+
23+
plug::load() {
24+
local name=$1
25+
local source_file=${2:-${name}.plugin.zsh}
26+
local plugin_dir=~/.config/zsh/plugins/$name
27+
28+
# Load ignore list on first call
29+
if (( ! _plug_ignore_ready )); then
30+
_plug_load_ignore_list
31+
fi
32+
33+
# Skip ignored plugins
34+
if (( ${+_plug_ignore[$name]} )); then
35+
return
36+
fi
37+
38+
local full_path=$plugin_dir/$source_file
39+
if [[ -f $full_path ]]; then
40+
source "$full_path"
41+
_plug_loaded[$name]=1
42+
fi
43+
}
44+
45+
plug::is_loaded() {
46+
(( ${+_plug_loaded[$1]} ))
47+
}
48+
49+
dot::defer "unset _plug_ignore _plug_loaded _plug_ignore_ready"
50+
dot::defer "unfunction _plug_load_ignore_list plug::load plug::is_loaded"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Load ZSH plugins
2+
# Generated from .chezmoidata/zsh_plugins.yaml
3+
4+
{{ range .zsh_plugins -}}
5+
{{ $name := default (base .repo) (index . "name") -}}
6+
{{ $source := default (printf "%s.plugin.zsh" $name) (index . "source") -}}
7+
plug::load {{ $name }} {{ $source }}
8+
{{ end -}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Plugin configuration
2+
# Runs after plugins are loaded (006), uses plug::is_loaded for conditionals
3+
4+
if plug::is_loaded zsh-autosuggestions; then
5+
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
6+
fi

0 commit comments

Comments
 (0)