From 109270911c2c5a1616161c8476d1552bd9130efd Mon Sep 17 00:00:00 2001 From: Morningstar202604 <320475654+Morningstar202604@users.noreply.github.com> Date: Wed, 25 Nov 2026 03:28:01 +0800 Subject: [PATCH] feat(cli): add omz diagnose locale check (#14140) * feat(core): add `omz diagnose` locale check Reports whether the runtime locale is UTF-8, using the CODESET parameter of the zsh/langinfo module that lib/functions.zsh already loads at startup, with a `locale charmap` fallback when the module is unavailable. Non-UTF-8 charsets cause completion glitches such as duplicated characters at the prompt. This replaces the startup warning proposed in the earlier iteration: per maintainer feedback the check belongs in `omz diagnose` so that no shell startup cost is paid and it only surfaces when the user is already debugging their setup. I used AI to draft and rework this change. * docs: document omz diagnose in README Add a Diagnostics section below the update instructions describing `omz diagnose` and pointing at `omz_diagnostic_dump` for full reports. I used AI to draft this change. --- README.md | 14 ++++++++++++++ lib/cli.zsh | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/README.md b/README.md index a443e1f10..a0545bfe0 100644 --- a/README.md +++ b/README.md @@ -552,6 +552,20 @@ omz update Magic! 🎉 +## Diagnostics + +If something looks off (glitched characters, completions misbehaving), run: + +```sh +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)). + +For a full report suitable for attaching to a bug report, use `omz_diagnostic_dump`. + ## Uninstalling Oh My Zsh Oh My Zsh isn't for everyone. We'll miss you, but we want to make this an easy breakup. diff --git a/lib/cli.zsh b/lib/cli.zsh index ed4af16ef..a28facb1d 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -24,6 +24,7 @@ function _omz { local -a cmds subcmds cmds=( 'changelog:Print the changelog' + 'diagnose:Run configuration diagnostics' 'help:Usage information' 'plugin:Manage plugins' 'pr:Manage Oh My Zsh Pull Requests' @@ -176,12 +177,36 @@ function _omz::log { ## User-facing commands +function _omz::diagnose { + # Check the runtime locale: non-UTF-8 charsets are known to cause glitches + # such as duplicated characters at the prompt after completions. + # https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#i-see-duplicate-typed-characters-after-i-complete-a-command + # + # `lib/functions.zsh` loads the zsh/langinfo module at startup, so the + # CODESET parameter is already available without any subprocess; only fall + # back to `locale charmap` when that module is unavailable (zsh built without it). + local codeset="${langinfo[CODESET]:-}" + if [[ -z "$codeset" ]] && (( $+commands[locale] )); then + codeset="$(locale charmap 2>/dev/null)" + fi + + 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" + return 1 + fi +} + function _omz::help { cat >&2 < [options] Available commands: + diagnose Run configuration diagnostics help Print this help message changelog Print the changelog plugin Manage plugins