#!/bin/bash # 新增自动修复功能 find . -type f -not -path './.git/*' -exec sh -c ' file="$1" if file -b --mime-encoding "$file" | grep -qv binary; then # 自动修复CRLF if grep -qP '\r$' "$file"; then sed -i 's/\r$//' "$file" echo "🛠️ 已修复 $file" fi # 验证UTF-8编码 if ! iconv -f UTF-8 -t UTF-8 "$file" &>/dev/null; then echo "❌ $file 存在非法UTF-8字符,需手动处理" exit 1 fi fi ' sh {} \;