#!/usr/bin/env bash # Enhanced script to fix Chinese encoding issues in Linux editors (vim, nano)
set -e
echo"🔍 检测 zh_CN.UTF-8 locale..." if ! locale -a | grep -q "zh_CN.utf8"; then echo"⚙️ 未找到 zh_CN.UTF-8,正在生成..." sudo locale-gen zh_CN.UTF-8 sudo dpkg-reconfigure locales else echo"✅ zh_CN.UTF-8 已存在。" fi
echo"⚙️ 设置系统 LANG 为 zh_CN.UTF-8..." sudo update-locale LANG=zh_CN.UTF-8
echo"📝 更新 ~/.bashrc 添加 LANG 和 LC_ALL..." if ! grep -q "LANG=zh_CN.UTF-8" ~/.bashrc; then echo'export LANG=zh_CN.UTF-8' >> ~/.bashrc fi if ! grep -q "LC_ALL=zh_CN.UTF-8" ~/.bashrc; then echo'export LC_ALL=zh_CN.UTF-8' >> ~/.bashrc fi
echo"🛠 配置 vim 支持 UTF-8..." VIMRC=~/.vimrc if ! grep -q "encoding""$VIMRC" 2>/dev/null; then cat >> "$VIMRC" <<EOF set encoding=utf-8 set fileencodings=utf-8,gbk,gb2312 set termencoding=utf-8 EOF fi
echo"🛠 配置 nano 支持 UTF-8..." NANORC=~/.nanorc if ! grep -q "set utf8""$NANORC" 2>/dev/null; then echo"set utf8" >> "$NANORC" fi