Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lint scripts for ledger
ledger balance --depth 1 ^Equity:Budget ^Budget \
| tail -n 1 \
| grep --quiet "^ *0 *$"
ledger balance --depth 1 ^Assets ^Liabilities ^Equity:Budget \
| tail -n 1 \
| grep --quiet "^ *0 *$"
# The amounts of the 2 accounts should be the same
ledger balance --empty --balance-format "%(display_total)\n" ^Budget:Food:MealVouchers ^Assets:MealVouchers \
| head -n 2 \
| uniq \
| wc --lines \
| grep --quiet "^1$"
ledger balance --balance-format "%(display_total)\n" Budget: | grep --quiet "^-"
if [[ (${PIPESTATUS[0]} -eq 0) && (${PIPESTATUS[1]} -eq 1) ]]; then
exit 0
else
exit 1
fi
#!/usr/bin/env bash
set -e
empty=0
# Compute the sum of all uncleared transactions on the Assets:Check:Others account
sum_uncleared=$(ledger register --empty --uncleared --subtotal --amount-data Assets:Check:Others \
| cut --fields=2 --delimiter=' ')
if [[ "$sum_uncleared" = '' ]]; then
empty=1
sum_uncleared=0
fi
account_amount=$(ledger balance --empty --balance-format "%(display_total)\n" Assets:Check:Others)
if [[ ($account_amount -eq 0) && ($empty -eq 0) ]]; then
echo "Assets:Check:Others account is 0 but not all related transactions are checked"
exit 1
fi
if [[ "$sum_uncleared" -ne "$account_amount" ]]; then
echo "The sum of uncleared Assets:Check:Others transactions is different from amount of this account"
echo "Sum of uncleared transactions = '$sum_uncleared'"
echo "Amount = '$account_amount'"
exit 1
fi
exit 0
empty=0
# Compute the sum of all uncleared transactions on the Liabilities:Check account
sum_uncleared=$(ledger register --empty --uncleared --subtotal --amount-data Liabilities:Check \
| cut --fields=2 --delimiter=' ')
if [[ "$sum_uncleared" = '' ]]; then
empty=1
sum_uncleared=0
fi
account_amount=$(ledger balance --empty --balance-format "%(display_total)\n" Liabilities:Check | tail -n 1)
if [[ ($account_amount -eq 0) && ($empty -eq 0) ]]; then
echo "Liabilities:Check account is 0 but not all related transactions are checked"
exit 1
fi
if [[ "$sum_uncleared" -ne "$account_amount" ]]; then
echo "The sum of uncleared Liabilities:Check transactions is different from amount of this account"
echo "Sum of uncleared transactions = '$sum_uncleared'"
echo "Amount = '$account_amount'"
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment