48 lines
1.4 KiB
Makefile
48 lines
1.4 KiB
Makefile
# 常用配方: 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
|