From 12fd497b2ca29a6a7f316e577e556608cae65b4b Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Thu, 3 Jul 2014 12:42:03 +0200 Subject: Restructure invoices/{invoice}.ledger → {year}/income/{customer}.ledger. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/myhledger | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'bin') 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- "$@" -- cgit v1.2.3