summaryrefslogtreecommitdiff
path: root/bin/myhledger
blob: cf73eefa787938f4aa8755ca3360537e9bc43d7f (plain)
  1. #!/bin/sh
  2. # use hledger with piles of journal chunks
  3. #
  4. # Example usage:
  5. #
  6. ## Check expenses against bank account
  7. # myhledger register liabilities:payable -B --date2 -p "from 2011"
  8. #
  9. # myhledger balance -p "every 6 months in 2012" --date2
  10. # myhledger balance -p "from 2012-07 to 2013"
  11. # myhledger reg :kp
  12. # myhledger reg desc:012001
  13. set -e
  14. basedir="${basedir:-data}"
  15. years="${years:-$(find "$basedir" -mindepth 1 -maxdepth 1 -type d -regex '.*/[0-9]+' -printf '%f\n')}"
  16. journal() {
  17. set -e
  18. cd "$basedir"
  19. for year in $years; do
  20. cat defaults.ledger 2> /dev/null || true
  21. cat $year/primo.ledger 2> /dev/null || true
  22. cat defaults.ledger 2> /dev/null || true
  23. cat $year/assets/*.ledger 2> /dev/null || true
  24. cat defaults.ledger 2> /dev/null || true
  25. cat $year/income/*.ledger 2> /dev/null || true
  26. cat defaults.ledger 2> /dev/null || true
  27. cat $year/expenses/*.ledger 2> /dev/null || true
  28. cat $year/ultimo.ledger 2> /dev/null || true
  29. done
  30. }
  31. journal | hledger -f- "$@"