Last active
July 31, 2025 08:38
-
-
Save moskytw/37a4b6752743fe3891c98e9d3b43ae04 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
START_DATE="2025-07-01" | |
GIT_TMP=$(mktemp) | |
CCUSAGE_TMP=$(mktemp) | |
# 1. Git 每日 Python 行數(新增+刪除) | |
git log --since="$START_DATE" --pretty=format:'%ad' --date=short --numstat -- '*.py' | | |
awk ' | |
NF==1 { date=$1 } | |
NF==3 { total[date]+=$1+$2 } | |
END { | |
for (d in total) print d "\t" total[d] | |
} | |
' | sort > "$GIT_TMP" | |
# 2. 執行 ccusage JSON 並擷取日期與 totalCost | |
npx ccusage --json | jq -r '.daily[] | "\(.date)\t\(.totalCost)"' | sort > "$CCUSAGE_TMP" | |
# 3. 合併並輸出 | |
echo "" | |
echo "📊 Claude 成本 vs Git Python 行數" | |
echo -e "Date\t\tTotalLines\tCostUSD\t\tLines/USD" | |
JOINED=$(join -t $'\t' "$GIT_TMP" "$CCUSAGE_TMP") | |
if [[ -z "$JOINED" ]]; then | |
echo "⚠️ 無法對齊日期,可能是 git 或 ccusage 沒有交集" | |
else | |
echo "$JOINED" | awk -F'\t' ' | |
{ | |
lines = $2 | |
cost = $3 | |
rate = (cost > 0) ? lines / cost : 0 | |
printf "%-10s\t%-10s\t%-8.2f\t%-10.2f\n", $1, lines, cost, rate | |
}' | |
fi | |
# 清理 | |
rm -f "$GIT_TMP" "$CCUSAGE_TMP" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment