On Sun, Jan 03, 2016 at 05:40:57AM -0800, Mark Scannell wrote:
> As our finances are gradually being treated as one, I'd like to be
> able to have Assets -> mine, Assets -> hers, Assets -> ours, Expenses
> -> mine|hers|ours, etc.
FWIW I'm in a similar situation, but I've decided to only separate by
owners the Assets hierarchy, and only where's relevant (e.g., bank
accounts that formally belong to a single person). But I haven't
separated the Expenses hierarchy, because I considered that would be
overkill. Instead, I'm using an "Author: " tag to separate transactions
by person. I'm fairly happy with the result, but I'll gladly hear about
different experiences.
> A simple regex substitution works fine, so the ledger print | sed -e '//' |
> ledger -f - type of solution can work.
We've discussed this in the past IIRC, and the general feeling was that
it'd be nice to have a grammar-aware tool to rename accounts
consistently. But also that there is no such tool right now, and
therefore people are using various sed-based workarounds. My own scripts
to that end are attached. (They're provably incomplete/incorrect in
various corner cases, but they work well enough for me, and try hard to
preserve the right amount of horizontal spacing, which was a must for
me.)
Cheers.
--
Stefano Zacchiroli . . . . . . . [email protected] . . . . o . . . o . o
Maître de conférences . . . . . http://upsilon.cc/zack . . . o . . . o o
Former Debian Project Leader . . . . . @zacchiro . . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »
--
---
You received this message because you are subscribed to the Google Groups
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/perl -w
# Copyright (C) 2014 Stefano Zacchiroli <[email protected]>
# License: GNU General Public License (GPL), version 3 or above
# parse current "git diff" and determine ledger account renames
use strict;
use Carp::Assert;
open(GIT, "git diff |");
my @del_accts = ();
my @add_accts = ();
while (my $line = <GIT>) {
if ($line =~ /^-account\s+(.*)$/) {
push @del_accts, $1;
} elsif ($line =~ /^\+account\s+(.*)$/) {
push @add_accts, $1;
} elsif (@del_accts) {
assert($#del_accts == $#add_accts,
"even number of added/removed accounts");
for (my $i = 0 ; $i <= $#del_accts ; $i++) {
print $del_accts[$i], "\t->\t", $add_accts[$i], "\n";
}
@del_accts = ();
@add_accts = ();
}
}
close(GIT);
#!/usr/bin/perl
# Copyright (C) 2014 Stefano Zacchiroli <[email protected]>
# License: GNU General Public License (GPL), version 3 or above
use strict;
while (my $line = <>) {
$line =~ s/\s+$//;
print $line, "\n";
}
#!/bin/bash
# Copyright (C) 2014 Stefano Zacchiroli <[email protected]>
# License: GNU General Public License (GPL), version 3 or above
sed_flags="--follow-symlink --regexp-extended"
if [ -z "$1" -o -z "$2" -o -z "$3" ] ; then
echo "Usage: $0 OLD_ACCT_NAME NEW_ACCT_NAME LEDGER_FILE..."
exit 1
fi
old_name="$1"
new_name="$2"
shift 2
old_len=${#old_name}
new_len=${#new_name}
if [ $old_len -lt $new_len ] ; then
sed $sed_flags -i "s/^( *)$(printf "%-${new_len}s"
"$old_name")/\\1${new_name}/" "$@"
sed $sed_flags -i "s/^( *)${old_name} *$/\\1${new_name}/" "$@"
elif [ $old_len -gt $new_len ] ; then
new_name=$(printf "%-${old_len}s" "$new_name")
sed $sed_flags -i "s/^( *)${old_name}( |$)/\\1${new_name}\\2/" "$@"
fi
for f in "$@" ; do
bin/normalize-spaces "$f" | sponge "$f"
done
#!/bin/bash
LEDGERS=$(bin/ls-ledgers)
MAPPING=".icsv2ledgerrc-mapping"
bin/diff-accounts | \
while IFS=$'\t' read old_acct _sep new_acct ; do
for l in $LEDGERS ; do
bin/rename-account "$old_acct" "$new_acct" "$l"
done
sed -ri "s/,${old_acct}(,|$)?/,${new_acct}\\1/" "$MAPPING"
done