Last active
June 29, 2020 14:39
-
-
Save DamienCassou/703365e3385c4974241728293fd2e3f2 to your computer and use it in GitHub Desktop.
Lint scripts for ledger
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
ledger balance --depth 1 ^Equity:Budget ^Budget \ | |
| tail -n 1 \ | |
| grep --quiet "^ *0 *$" |
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
ledger balance --depth 1 ^Assets ^Liabilities ^Equity:Budget \ | |
| tail -n 1 \ | |
| grep --quiet "^ *0 *$" |
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
# 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$" |
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
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 |
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
#!/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 |
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
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