Files
bash-script/justfile
AhFei 6f9ab0f7da
All checks were successful
ci/woodpecker/push/ci-test Pipeline was successful
改进 cloc
2026-01-29 12:50:47 +08:00

48 lines
1.4 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 常用配方: https://git.cufah.cloud/ahfei/bash-script/raw/branch/main/justfile
# === 全局变量 ===
root := justfile_directory()
machine_ip := `ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1`
# === 常用配方 ===
# 创建一个空 commit ,带提交信息模板
@new:
git commit --allow-empty --edit --file={{root}}/.gitmessage
@forget:
if git diff --quiet HEAD HEAD~1; then \
git reset --soft HEAD~1 && echo "✅ 空提交已删除"; \
fi
# 将所有文件 amend若取消则将暂存区文件移出
@amend:
cd "{{root}}" && git add . && git commit --amend || (git restore --staged . && false)
# 统计代码量(支持文件名包含空格)
cloc range="":
cd {{invocation_directory()}} && git ls-files -z \
| grep -z -v -E '\.(g|freezed)\.dart$' \
{{ if range != "all" { "| grep -z -v '^test/'" } else { "" } }} \
| xargs -0 cloc
# === just 管理命令 ===
import? "justfile.local"
bashrc := "$HOME/.bashrc"
# 设置 just 的命令补全
@setup-completions:
# 检查是否已经存在补全命令
cmd="eval \"\$(just --justfile {{justfile()}} --completions bash)\""; \
if ! grep -Fxq "$cmd" "{{bashrc}}"; then \
echo '添加 just 补全到 {{bashrc}}'; \
echo $cmd >> "{{bashrc}}"; \
else \
echo "补全命令已存在 {{bashrc}},无需重复添加"; \
echo "执行命令 source {{bashrc}} ,使之生效"; \
fi