From d7046e0511e8de2fb472b989de11ea8b2116aa56 Mon Sep 17 00:00:00 2001 From: Robby Russell Date: Fri, 4 Dec 2026 03:12:50 -0800 Subject: [PATCH] feat(cli): validate the plugins list in `omz diagnose` (#14306) Co-authored-by: Carlo Sala --- README.md | 3 ++- functions/omz | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a0545bfe0..491fd7f98 100644 --- a/README.md +++ b/README.md @@ -562,7 +562,8 @@ omz diagnose It runs a few quick checks and tells you what to fix — for example, it will warn you when your locale is not UTF-8, which is a common cause of duplicated characters at the prompt -(see the [FAQ](https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#i-see-duplicate-typed-characters-after-i-complete-a-command)). +(see the [FAQ](https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#i-see-duplicate-typed-characters-after-i-complete-a-command)), +and it validates your `plugins=(...)` list, suggesting the closest name for any plugin it can't find. For a full report suitable for attaching to a bug report, use `omz_diagnostic_dump`. diff --git a/functions/omz b/functions/omz index dcb901ace..aabf8cbb2 100644 --- a/functions/omz +++ b/functions/omz @@ -78,14 +78,64 @@ function _omz::diagnose { codeset="$(locale charmap 2>/dev/null)" fi + local ret=0 + if [[ "${codeset:l}" = (utf-8|utf8) ]]; then _omz::log info "locale charmap is UTF-8" else _omz::log warn "your locale is not UTF-8 (charmap: ${codeset:-unknown})" _omz::log info "non-UTF-8 locales may cause glitches in completions and international characters" _omz::log info "consider setting a UTF-8 locale, e.g.: export LANG=C.UTF-8" + ret=1 + fi + + _omz::diagnose::plugins || ret=1 + return $ret +} + +function _omz::diagnose::plugins { + # Validate the plugins array: flag entries with no matching plugin folder, + # and suggest the closest plugin name (up to 2 typos) for each one. + setopt localoptions extendedglob + + local plugin base distance candidate suggestion found=0 + local -a missing + for plugin ($plugins); do + if is_plugin "$ZSH_CUSTOM" "$plugin" || is_plugin "$ZSH" "$plugin"; then + (( ++found )) + continue + fi + missing+=("$plugin") + done + + for plugin ($missing); do + suggestion= + # Check both roots at each distance, with custom plugins first for ties. + for distance in 1 2; do + for base in "$ZSH_CUSTOM" "$ZSH"; do + for candidate in \ + "$base"/plugins/(#a$distance)${(b)plugin}(#qN-/); do + if is_plugin "$base" "${candidate:t}"; then + suggestion=${candidate:t} + break 3 + fi + done + done + done + if [[ -n "$suggestion" ]]; then + _omz::log warn "plugin '$plugin' not found (did you mean '$suggestion'?)" \ + omz::diagnose + else + _omz::log warn "plugin '$plugin' not found" omz::diagnose + fi + done + + if (( $#missing )); then + _omz::log info "$found of ${#plugins} plugins found" omz::diagnose return 1 fi + (( $#plugins )) && _omz::log info "all ${#plugins} plugins found" omz::diagnose + return 0 } function _omz::help {