From a7e11e85e51ed47a3ffabdee0e34c214b7960ca5 Mon Sep 17 00:00:00 2001 From: FlintyLemming Date: Fri, 19 Dec 2025 14:02:17 +0800 Subject: [PATCH] add fish config --- fish/add-on.fish | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/fish/add-on.fish b/fish/add-on.fish index d0436e8..8ecd03d 100644 --- a/fish/add-on.fish +++ b/fish/add-on.fish @@ -54,12 +54,24 @@ function restore_cursor --on-event fish_postexec tput cnorm end -# 检查当前的 LANG 是否包含 UTF-8(忽略大小写),修复 nano 无法输入中文的问题 +# --- 自动化 Locale 修复逻辑 --- +# 只有在当前环境不支持 UTF-8 时才介入,修复例如 nano 无法输入中文的问题 if not string match -qi "*UTF-8" "$LANG" - # 如果当前没有设置或者不是 UTF-8,则尝试设置为 zh_CN.UTF-8 - # 如果你更偏好英文界面但要中文输入,这里也可以写 en_US.UTF-8 - set -gx LANG zh_CN.UTF-8 - set -gx LC_ALL zh_CN.UTF-8 + # 定义尝试顺序:C.UTF-8 (最通用) -> en_US.UTF-8 (最标准) -> 其他已安装的 UTF-8 + if locale -a | string match -q "C.utf8" + set -gx LANG C.UTF-8 + set -gx LC_ALL C.UTF-8 + else if locale -a | string match -qi "en_US.utf8" + set -gx LANG en_US.UTF-8 + set -gx LC_ALL en_US.UTF-8 + else + # 如果以上都没有,自动寻找系统里任何一个可用的 UTF-8 语言包 + set -l any_utf8 (locale -a | string match -ri '.*\.utf8' | head -n 1) + if test -n "$any_utf8" + set -gx LANG $any_utf8 + set -gx LC_ALL $any_utf8 + end + end end abbr -a port 'sudo ss -tulnp | grep'