mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-12-04 14:19:04 +01:00
feat(cli): validate the plugins list in omz diagnose (#14306)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
This commit is contained in:
1 parent
5b2db7b495
commit
d7046e0511
2 files changed
+52
-1
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user