diff options
author | Jonas Smedegaard <dr@jones.dk> | 2014-07-03 12:42:03 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2014-07-03 18:15:36 +0200 |
commit | 12fd497b2ca29a6a7f316e577e556608cae65b4b (patch) | |
tree | b0b96a9ee81343630b937d64b864c1347860a57d /bin/myhledger | |
parent | 93a01e816878eb54f45d22f6464f6a29aa7a24fa (diff) |
Restructure invoices/{invoice}.ledger → {year}/income/{customer}.ledger.
Diffstat (limited to 'bin/myhledger')
-rwxr-xr-x | bin/myhledger | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/bin/myhledger b/bin/myhledger index f0da9dc..f35601e 100755 --- a/bin/myhledger +++ b/bin/myhledger @@ -11,23 +11,20 @@ set -e -defaultbasedir="$HOME/Doc/Jones/ledger" - -if [ -n "$basedir" ]; then - : -elif [ -d invoices ] && [ -d receipts ]; then - basedir=. -elif [ -d ../invoices ] && [ -d ../receipts ]; then - basedir=.. -else - basedir="$defaultbasedir" -fi +basedir="${basedir:-data}" +years="${years:-$(find "$basedir" -mindepth 1 -maxdepth 1 -type d -regex '.*/[0-9]+' -printf '%f\n')}" journal() { - cat $basedir/bank/*.ledger 2> /dev/null || true - cat $basedir/invoices/*.ledger 2> /dev/null || true - cat $basedir/receipts/*.ledger 2> /dev/null || true - cat $basedir/taxes/*.ledger 2> /dev/null || true + set -e + cd "$basedir" + cat *.ledger 2> /dev/null || true + for year in $years; do + cat $year/*.ledger 2> /dev/null || true + cat $year/income/*.ledger 2> /dev/null || true + done + cat ../bank/*.ledger 2> /dev/null || true + cat ../receipts/*.ledger 2> /dev/null || true + cat ../taxes/*.ledger 2> /dev/null || true } journal | hledger -f- "$@" |