提交 9d85dd55 authored 作者: Andy's avatar Andy

123

上级 b5b004fc
差异被折叠。
差异被折叠。
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
# 如何删除GIT中的.DS_Store
# (https://www.jianshu.com/p/fdaa8be7f6c3)
#!/bin/bash
# 遍历当前目录及子目录,格式化所有 *.env 文件(原地覆盖)
find . -type f -name "*.env" | while read -r file; do
echo "📂 格式化: $file"
tmpfile=$(mktemp)
# 计算 KEY 的最大长度
max_len=$(grep -vE '^\s*#|^\s*$' "$file" | cut -d= -f1 | awk '{print length}' | sort -nr | head -1)
# 格式化
while IFS= read -r line; do
if [[ "$line" =~ ^[[:space:]]*# || -z "$line" ]]; then
echo "$line" >>"$tmpfile"
else
# 去除左右空格,并严格分割 key/value
key=$(echo "$line" | sed -E 's/^[[:space:]]*([^=[:space:]]+)[[:space:]]*=.*$/\1/')
value=$(echo "$line" | sed -E 's/^[^=]*=[[:space:]]*(.*)$/\1/')
# printf "%-${max_len}s = %s\n" "$key" "$value" >>"$tmpfile"
echo "${key}=${value}" >>"$tmpfile"
fi
done <"$file"
mv "$tmpfile" "$file"
done
echo "✅ 所有 *.env 文件格式化完成!"
# ================================
# 项目维护脚本
# ================================
# 在任意目录下执行,格式化当前目录及子目录 .env 后缀文件
format-envs:
chmod +x format-envs.sh
./format-envs.sh
# 清理 DS_Store 文件(macOS 专用)
# 在任意目录下执行,清理当前目录及子目录
clean:
find . -name ".DS_Store" -type f -print -delete
# 使用 shfmt 格式化所有 .sh 文件
shfmt:
shfmt -w .
# 一键执行全部任务
all: clean format-envs shfmt
@echo "✅ 所有任务已完成:clean + format-envs + shfmt"
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论