diff options
| author | Zach DeCook <zachdecook@librem.one> | 2026-09-11 21:18:48 -0400 |
|---|---|---|
| committer | Zach DeCook <zachdecook@librem.one> | 2026-09-11 21:18:48 -0400 |
| commit | b8c775557eb3c150b448f9801639dadad1733133 (patch) | |
| tree | d68863d7f37ab61cda34e0c73945ca5e441b7388 /budget.sh | |
| parent | b1c11ecfd4f9b6afffcfadc781de6c62972c1bac (diff) | |
| download | hledger-zachster.tar.gz | |
Diffstat (limited to 'budget.sh')
| -rwxr-xr-x | budget.sh | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/budget.sh b/budget.sh index 0c3e2fb..55db3e3 100755 --- a/budget.sh +++ b/budget.sh @@ -14,12 +14,17 @@ category() { category="$1" budget="$2" amount="$(printf "%s" "$output" | grep "$category" | tr -d ',' | grep -o '[0-9.]*')" - #if test -z $amount; then - printf "%s\t%.2f\t%f\n" "$category" "$amount" "$(python3 -c 'print('$amount' / '$budget')')" - #else - # printf "%s not found.\n" "$category" >/dev/stderr - #fi + if test -n "$amount"; then + monthlyprogress="$(python3 -c 'print('$(date +%d)' / '$(daysthismonth)')')" + overunder="$(python3 -c 'print(('$budget' * '$monthlyprogress') - '$amount')')" + printf "%s\t%.2f\t%f\t%.2f\n" "$category" "$amount" "$(python3 -c 'print('$amount' / '$budget')')" "$overunder" + else + printf "%s not found.\n" "$category" >/dev/stderr + fi +} +daysthismonth() { + python3 -c 'from datetime import date; print([0,31,28,31,30,31,30,31,31,30,31,30,31][date.today().month])' } category dining 250 @@ -33,4 +38,4 @@ category utilities 625 category charity 450 category fees 0.01 output="$(date +%d) date" -category date 31 +category date $(daysthismonth) |
