aledger 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # BSD 3-Clause 2023 by Kevin Bloom.
  3. AWK_PATH=./
  4. ledger_path=${AWK_PATH}ledge.awk
  5. balance_path=${AWK_PATH}balance.awk
  6. final_path=${AWK_PATH}final.awk
  7. register_path=${AWK_PATH}register.awk
  8. reg=${AWK_PATH}reg_values.awk
  9. command=$1
  10. shift
  11. case $command in
  12. balance)
  13. # TODO: probably should try to do this more efficiently since this is sorting twice
  14. for a in "$@"
  15. do
  16. case $found in
  17. 1)
  18. start=$a
  19. found=0
  20. continue
  21. ;;
  22. 2)
  23. end=$a
  24. found=0
  25. continue
  26. ;;
  27. esac
  28. case "$a" in
  29. --start)
  30. found=1
  31. ;;
  32. --end)
  33. found=2
  34. ;;
  35. *)
  36. file=$a
  37. ;;
  38. esac
  39. done
  40. awk -v start="$start" -v end="$end" -f $balance_path $file | sort | awk -f $ledger_path | sort | awk -f $final_path
  41. ;;
  42. register)
  43. for a in "$@"
  44. do
  45. case $found in
  46. 1)
  47. start=$a
  48. found=0
  49. continue
  50. ;;
  51. 2)
  52. end=$a
  53. found=0
  54. continue
  55. ;;
  56. esac
  57. case "$a" in
  58. --monthly)
  59. type="monthly"
  60. ;;
  61. --weekly)
  62. type="weekly"
  63. ;;
  64. --start)
  65. found=1
  66. ;;
  67. --end)
  68. found=2
  69. ;;
  70. *)
  71. file=$a
  72. ;;
  73. esac
  74. done
  75. awk -v type="$type" -v start_date="$start" -v end_date="$end" -f $register_path $file | sort | awk -f $reg
  76. ;;
  77. *)
  78. echo "Unknown command."
  79. ;;
  80. esac