Files
bash-script/justfile
AhFei abfd83ac99
All checks were successful
ci/woodpecker/push/ci-test Pipeline was successful
更新 justfile
2026-03-30 14:09:41 +08:00

50 lines
1.7 KiB
Makefile
Raw Permalink 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)
# 列出所有已合并到当前分支(这里指定了 main 分支)的本地分支,过滤掉当前分支(*)和 main、develop 节点,避免删除它们,一次安全地删除剩余的每个分支
@ciaclean:
git branch --merged origin/main | grep -vE "^\s*(\*|main|develop)" | xargs -n 1 git branch -d
# 统计代码量(支持文件名包含空格)
cloc range="":
cd {{root}} && python lib/generated/time_taken_sum.py && echo "\n"
cd {{invocation_directory()}} && git ls-files -z \
{{ 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