GitHub
Account aliases

Account aliases

A bank’s export often names accounts in its own words. A Morgan Stanley statement says PW Roth IRA - 3077 where your journal says assets:morganstanley:pw-roth-ira. A rules file that copies that column into the account (account1 %acct) writes the bank’s words straight into your books.

An hledger alias directive fixes the name:

alias PW Roth IRA - 3077 = assets:morganstanley:pw-roth-ira

Settings → Account Aliases lists and edits the alias lines in your journal. Ledgeline passes them to hledger when it imports a statement.

Settings → Account Aliases with two plain aliases and one regex alias

Why Ledgeline forwards your aliases

hledger applies an alias directive when it reads a journal. It does not apply one to a CSV being imported. An alias line in your journal therefore has no effect on hledger import, and the account arrives unmapped. The --alias command-line option does reach the CSV.

So Ledgeline reads the alias lines from your journal and passes each one to hledger as --alias on every import. You write the mapping once, in hledger’s own syntax, and it works for imports too.

Ledgeline does not rewrite account names anywhere else. The journal view and the reports show account names exactly as your transactions spell them. hledger applies your aliases itself when it reads the journal from a terminal, so a report there can show a mapped name where Ledgeline shows the original. Ledgeline makes one narrow exception for QuickBooks imports.

Using the editor

The tab shows the root journal, plus any other file that already holds alias lines. When there is more than one, pick the file from the row of buttons above the list.

Each alias has two fields, “What the bank calls it” and “Your account”, and a regular expression box. Leave the box clear for a plain alias. A plain alias matches the whole account name, or a leading part of it that ends at a :. alias a = b renames a and a:sub and leaves abc alone. Tick the box for hledger’s /REGEX/ = replacement form.

You can’t reorder aliases. hledger tries them in order, so moving one can change which alias wins, and the editor keeps their order as written.

A row can carry three badges:

BadgeMeaning
not used for importsLedgeline will not pass this alias to an import. The row says why
read-onlyLedgeline will not rewrite this line. The row shows it as written, with the reason
regular expressionA /REGEX/ alias

Aliases that are not used for imports

An alias stays in your journal and on screen, but Ledgeline doesn’t pass it to an import, when:

Ledgeline passes on every alias that end aliases doesn’t close, whichever file it is in.

Lines the editor won’t rewrite

The editor shows some alias lines read-only, because rewriting them would mean guessing what their author meant.

ReasonExampleWhy
It contains ; or #alias a = b ; notehledger reads this as an account literally named b ; note. It is not a comment
One side is emptyalias a =There is nothing to rewrite
A delimiter inside the patternalias a=b = c, or \/ in a regexhledger splits at the first =, so the line doesn’t say what it seems to. Re-escaping it would be a guess
A control character, or too longLedgeline won’t write those bytes

The same rules apply to what you type. The editor tells you, before you save, if a pattern or account:

Seeing what an alias did to an import

When you import a statement on New Transactions, the preview reports which accounts your aliases rewrote, with each rename next to the alias that caused it when Ledgeline can tell which one did. Ledgeline measures this by running the same import once without aliases and comparing the results, so the list comes from hledger itself. When no alias matched anything in the statement, the preview hides the section.

Matching the command line with hledger.conf

Because Ledgeline passes your aliases to hledger and a plain hledger import in a terminal does not, the same statement can land under different account names depending on which tool you used. The import preview checks for this. When the two would disagree, it says so: “Run from the command line, this same import would file N accounts differently”. It lists each account as a terminal would file it, next to the account Ledgeline uses.

The fix is an hledger.conf file beside your journal. hledger reads --alias options from that file on every command, including import. The notice shows the exact lines it would add, and a button installs them. The button reads “Create hledger.conf beside your journal” when there is no config yet, or “Add these to …” when there is one. Ledgeline:

Spaces in hledger.conf

hledger splits each line of a config file at spaces and ignores quotes, so there is no way to write a space in an option. --alias=PW Roth IRA - 3077=… breaks, quoted or not.

Ledgeline works around this when it writes the file:

A converted alias can match slightly more than the original. A . matches any character, not only a space, and hledger’s regex aliases ignore case where plain ones don’t. That is why the notice shows you the lines before it writes them.

QuickBooks mappings

The QuickBooks Journal import asks you to map each QuickBooks account to one of yours. Each mapping you enter there is saved as a plain alias line, through the same save this tab uses, so it appears here afterwards. You can edit or delete it like any other alias. A mapping on a parent account also covers its QuickBooks sub-accounts.

This is the one place Ledgeline applies an alias itself, because a QuickBooks Journal export can’t go through hledger import. It only uses plain aliases there. A regular expression alias never maps a QuickBooks account, and the import reports the account as unmapped instead.

For the full reasoning behind these rules, and the hledger behaviour each one was checked against, see Account aliases in the import internals.