Ledger-cli alias for a Virtual Account

I'm new to Ledger and have set up an envelope budget using virtual accounts as described in this blog post

For most of my real accounts, I have been able to set up aliases to shorthand my postings, but if I try to do this with my virtual accounts (to simplify transferring money between budget categories) Ledger errors out.

This works:

alias Checking=Assets:Checking

This does not:

alias Virtual Checking=[Assets:Checking]

The error when I attempt to post a transaction using the Virtual Ally Checking alias is:

Error: Posting with null amount's account may be misspelled:
    "[Assets:Checking]"

Is it possible to have an alias to a virtual account defined? If so, how would I go about doing it?

Thanks!

9 comments · 100% upvoted · other discussions

comments

PanPipePlaya

What happens if you use the working Checking alias with virtual-account square brackets at time-of-use?

NeilHummus [OP]

This worked! Thank you!

tbm

alias Virtual Checking=[Assets:Checking]

This doesn't work because [...] is not a valid account name.

You have to do:

alias Checking=Assets:Checking                                                                                                                            

and then use

[Checking]
NeilHummus [OP]

Yupp, I was incorrectly thinking of aliases like #defines in C/C++, and assuming it just grabbed whatever text on the left and replaced it with what's on the right.

cottagepainter

Great blog post link! This seems to me like something that you can't do. In my experience so far, ledger has so many little features and they don't always combine in the ways you would want them to. You might consider trying this in hledger which is normally more consistant.

NeilHummus [OP]

That blog post is the only reason I'm trying out Ledger in the first place, as a refugee from YNAB's recent price increase. The virtual-account style budgeting seems to get me exactly what I need.

I'll need to do some extra digging on hledger. A brief test with hledger shows that my ledger book is not compatible with hledger as-is, so I'd need to do some research to figure out why.

cottagepainter

Assuming your good with a command-line, try running you book through

hledger -f - print

hledger can parse most, but not all, of ledger's syntax. It will output a book you can use with hledger and most likely with ledger as well.

For me, i maintain two copies of my book, one for ledger and one for hledger. They are both pretty much the same except i use ledger's expression matching in my automatic and periodic transactions. Other then that, they are the same.

I manage the construction of these two books with a makefile and then i have a shell script led to interface with them, selecting hledger or ledger depending on which functions i want to use. So far its working great!

simonmic

hledger won't do it either - account aliases are intended only to rewrite account names, and parentheses/brackets aren't part of the account name. Using them in the journal entry as PanPipePlaya suggests is the way. (Also avoids semantic problems like aliasing to [] but writing () in the journal entry...)

NeilHummus [OP]

That's good to know, thanks for the info. I'm finding myself partial to PanPipePlaya's suggested approach anyway now (vs. what I was trying to do initially), since it's easier to quickly visually distinguish between real transactions and ones that are just moving budgeted funds around.