hledger/MANUAL.md

1479 lines
54 KiB
Markdown
Raw Normal View History

2010-05-20 20:46:30 +04:00
---
2010-12-12 20:51:04 +03:00
title: hledger user manual
2010-05-20 20:46:30 +04:00
---
2010-12-12 20:51:04 +03:00
# User manual
2010-05-20 20:46:30 +04:00
2012-05-29 22:34:33 +04:00
Version: 0.18
2012-03-25 00:54:08 +04:00
2011-08-26 02:58:05 +04:00
## Introduction
2010-05-20 20:46:30 +04:00
2012-03-25 00:54:08 +04:00
[hledger](http://hledger.org) is a program for tracking money, time, or
any other commodity, using a simple, editable file format and the powerful
principles of double-entry accounting. It was inspired by
[ledger](http://ledger-cli.org). hledger is Free Software released under
GPL version 3 or later.
2010-05-20 20:46:30 +04:00
hledger's basic function is to read a plain text file describing (eg)
financial transactions, and quickly generate useful reports via the
command line. It can also help you record transactions, or (via add-ons)
provide a local web interface for editing, or publish live financial data
on the web.
2010-05-20 20:46:30 +04:00
You can use it to, eg:
2010-05-20 20:46:30 +04:00
2010-11-19 03:00:41 +03:00
- track spending and income
- track unpaid or due invoices
- track time and report by day/week/month/project
- get accurate numbers for client billing and tax filing
2010-05-20 20:46:30 +04:00
## Installing
2010-07-25 02:10:21 +04:00
2012-03-25 00:54:08 +04:00
hledger works on linux, mac and windows. You can fund ready-to-run
binaries of the latest release - see the [download page](DOWNLOAD.html).
2010-07-25 02:10:21 +04:00
2012-03-25 00:54:08 +04:00
Otherwise, build the latest release from Hackage using cabal-install.
2012-05-29 22:34:33 +04:00
Ensure you have [GHC](http://hackage.haskell.org/ghc/) 7.0 or greater or
the [Haskell Platform](http://hackage.haskell.org/platform/) installed,
then:
2010-07-25 02:10:21 +04:00
$ cabal update
$ cabal install hledger
2010-07-25 02:10:21 +04:00
2012-03-30 02:09:54 +04:00
To also install the web interface, do:
2010-07-25 02:10:21 +04:00
2012-05-29 22:34:33 +04:00
$ cabal install hledger hledger-web
2012-03-25 00:54:08 +04:00
To build the latest [development version](DEVELOPMENT.html) do:
2010-07-25 02:10:21 +04:00
$ cabal update
$ darcs get --lazy http://joyful.com/darcsden/simon/hledger
$ cd hledger
2012-03-25 00:54:08 +04:00
$ make install (or do cabal install inside hledger-lib/, hledger/ etc.)
2012-03-25 00:54:08 +04:00
Some add-on packages are available on Hackage:
[hledger-vty](http://hackage.haskell.org/package/hledger-vty),
[hledger-chart](http://hackage.haskell.org/package/hledger-chart),
[hledger-interest](http://hackage.haskell.org/package/hledger-interest).
These are without an active maintainer, and/or platform-specific, so installing them may be harder.
Note to use non-ascii characters in journal files, you must have a [suitable locale configured](#locale).
Trouble with any of the above ? Please proceed to [Troubleshooting](#troubleshooting).
2010-12-13 01:37:23 +03:00
2011-08-28 23:42:39 +04:00
## Usage
2010-05-20 20:46:30 +04:00
Basic usage is:
2010-05-20 20:46:30 +04:00
2011-08-28 23:42:39 +04:00
$ hledger COMMAND [OPTIONS] [ARGS]
2011-08-28 23:42:39 +04:00
Most [commands](#commands) query or operate on a
[journal file](#the-journal-file), which by default is `.hledger.journal`
in your home directory. You can specify a different file with the `-f`
option or `LEDGER_FILE` environment variable, or standard input with `-f
-`.
2011-08-28 23:42:39 +04:00
Options are similar across most commands, with some variations; use
`hledger COMMAND --help` for details. Most options must appear somewhere
after COMMAND, not before it. The `-f` option can appear anywhere.
Arguments are also command-specific, but usually they are
[filter patterns](#filter-patterns) which select a subset of the journal,
eg transactions in a certain account.
2010-05-20 20:46:30 +04:00
To create an initial journal, run `hledger add` and follow the prompts to
enter some transactions. Or, save this
2010-12-11 00:50:36 +03:00
[sample file](http://joyful.com/repos/hledger/data/sample.journal) as
2011-08-28 23:42:39 +04:00
`.hledger.journal` in your home directory. Now try commands like these:
2010-05-20 20:46:30 +04:00
2011-08-28 23:42:39 +04:00
$ hledger # show available commands
$ hledger add # add more transactions to the journal file
2010-07-25 02:10:21 +04:00
$ hledger balance # all accounts with aggregated balances
2011-08-28 23:42:39 +04:00
$ hledger balance --help # show help for balance command
$ hledger balance --depth 1 # only top-level accounts
$ hledger register # show a register of postings from all transactions
$ hledger reg income # show postings to/from income accounts
$ hledger reg checking # show postings to/from checking account
$ hledger reg desc:shop # show postings with shop in the description
2011-08-28 23:50:33 +04:00
$ hledger activity # show transactions per day as a bar chart
2010-12-09 03:35:14 +03:00
2011-08-28 23:42:39 +04:00
## The journal file
hledger normally reads data from a plain text file in hledger journal
format. hledger can read some [other file formats](#other-file-formats)
as well, but first we'll discuss hledger's journal format. Note this is
compatible subset of
[c++ ledger's journal format](http://ledger-cli.org/3.0/doc/ledger3.html#Journal-Format),
so hledger can work with many c++ ledger journal files as well.
The journal file is so called because it represents a standard accounting
2011-08-28 23:42:39 +04:00
[general journal](http://en.wikipedia.org/wiki/General_journal). It
contains a number of transaction entries, each describing a transfer of
money (or any commodity) between two or more named accounts, in a simple
format readable by both hledger and humans.
2011-01-21 06:45:47 +03:00
You can use hledger without learning any more about this file; just use
2011-08-28 23:42:39 +04:00
the [add](#add) or [web](#web) commands. Many users, though, also edit the
journal file directly with a text editor, perhaps assisted by the helper
2011-10-01 21:14:11 +04:00
modes for emacs or vi. Note the file uses unix line endings on all
platforms.
2011-01-21 06:45:47 +03:00
hledger's file format aims to be [compatible](#file-format-compatibility)
with c++ ledger, so you can use both tools on your journal.
Here's an example:
; A sample journal file. This is a comment.
2008/01/01 income ; <- transaction's first line starts in column 0, contains date and description
assets:bank:checking $1 ; <- posting lines start with whitespace, each contains an account name
income:salary $-1 ; followed by at least two spaces and an amount
2008/06/01 gift
assets:bank:checking $1 ; <- at least two postings in a transaction
income:gifts $-1 ; <- their amounts must balance to 0
2008/06/02 save
assets:bank:saving $1
assets:bank:checking ; <- one amount may be omitted; here $-1 is inferred
2008/06/03 eat & shop ; <- description can be anything
expenses:food $1
expenses:supplies $1 ; <- this transaction debits two expense accounts
assets:cash ; <- $-2 inferred
2008/12/31 * pay off ; <- an optional * after the date means "cleared" (or anything you want)
liabilities:debts $1
assets:bank:checking
2011-01-21 06:45:47 +03:00
### Transactions
2011-01-21 06:45:47 +03:00
Each transaction begins with a date in column 0, followed by an optional
description, then two or more postings (of some amount to some account),
each on their own line.
2011-01-21 06:45:47 +03:00
The posting amounts within a transaction must always balance, ie add up to
0. You can leave one amount blank and it will be inferred.
### Account names
Account names typically have several parts separated by a full colon, from
which hledger derives a hierarchical chart of accounts. They can be
anything you like, but in finance there are traditionally five top-level
accounts: `assets`, `liabilities`, `income`, `expenses`, and `equity`.
Account names may contain single spaces, eg: `assets:accounts receivable`.
### Amounts
After the account name, separated by ***two or more*** spaces, there is
2010-12-09 03:33:35 +03:00
usually an amount. This is a number, optionally with a currency symbol or
commodity name on either the left or right. Commodity names which contain
2011-01-21 06:45:47 +03:00
more than just letters should be enclosed in double quotes.
Negative amounts usually have the minus sign next to the number: `$-1`.
Or it may go before the symbol: `-$1`.
hledger supports flexible decimal points and digit group separators so you
can use your country's convention. Numbers can use either a period (`.`)
or a comma (`,`) as decimal point. They can also have digit group
separators at any position (eg thousands separators) which can be comma or
period - whichever one you did not use as a decimal point. If you use
digit group separators, you must also include a decimal point in at least
one number in the same commodity, so that hledger knows which character is
which. Eg, write `$1,000.00` or `$1.000,00`.
2011-01-21 06:45:47 +03:00
### Commodity display settings
Based on how you format amounts, hledger will infer canonical display
settings for each commodity, and use them consistently when displaying
amounts in that commodity. These settings include:
- the position and spacing of the currency/commodity symbol
- the digit group separator character and digit group sizes, if any
- the decimal point character
- the number of decimal places
The canonical display settings are generally those used in the first
amount seen, and the number of decimal places is the highest used in all
amounts, in the given commmodity.
[Default commodity directives](#default-commodity) can also influence the
canonical display settings.
2010-12-09 03:35:14 +03:00
### Simple dates
Within a journal file, transaction dates always follow a year/month/day
format, although several different separator characters are accepted. Some
examples:
> `2010/01/31`, `2010/1/31`, `2010-1-31`, `2010.1.31`
Writing the year is optional if you set a default year with a Y directive.
This is a line containing `Y` and the year; it affects subsequent
transactions, like so:
Y2009
12/15 ; equivalent to 2009/12/15
...
Y2010
1/31 ; equivalent to 2010/1/31
...
### Actual & effective dates
Most of the time, a simple transaction date is all you need. However
real-life transactions sometimes involve more than one date. For example,
you buy a movie ticket on friday with a debit card, and the transaction is
charged to your bank account on monday. Or you write a cheque to someone
and they deposit it weeks later.
When you don't care about this, just pick one date for your journal
transaction; either will do. But when you want to model reality more
accurately (eg: to match your daily bank balance), write both dates,
separated by an equals sign. Following ledger's convention, the *actual
date* (or "bank date") goes on the left, and is used by default, the
*effective date* (or "your date") goes on the right, and is used when the
`--effective` flag is provided. Here are some mnemonics to prevent confusion:
2010-12-09 03:35:14 +03:00
- ACTUAL=EFFECTIVE. The actual date is (by definition) the one on the left. A before E.
- BANKDATE=MYDATE. You can usually think "actual is bank's, effective is mine".
2010-12-09 03:35:14 +03:00
- LATER=EARLIER. The effective date is usually the chronologically earlier one.
- "The cheque took EFFECT then, but ACTUALLY cleared weeks later."
2010-12-09 03:35:14 +03:00
Example:
; ACTUAL=EFFECTIVE
; The effective date's year is optional, defaulting to the actual date's
2010-12-09 03:35:14 +03:00
2010/2/23=2/19 movie ticket
expenses:cinema $10
assets:checking
$ hledger register checking
2010/02/23 movie ticket assets:checking $-10 $-10
$ hledger register checking --effective
2010/02/19 movie ticket assets:checking $-10 $-10
### Comments
2011-09-17 10:46:47 +04:00
A semicolon in the journal file marks the start of a comment. You can
write general comments between transactions like so:
; a comment line. Whitespace before the ; is allowed.
Or, you can write transaction- or posting-specific comments following the
transaction's first line or the posting, on the same line and/or the
immediately following lines (indented). Some examples:
2012/5/14 a transaction ; a transaction comment
; another comment for this transaction
posting1 ; a comment for posting 1
posting2
; a comment for posting 2
; another one
A "metadata comment" is a comment containing a metadata key-value pair (tag), explained in the next section.
### Tags (metadata)
You can attach any extra data you like to transactions and postings, as
key-value pairs within a transaction or posting comment. Ledger calls
these metadata, in hledger land I like to call them tags; they are the
same thing. Here's how they work in hledger: the format is
; NAME: VALUE
where NAME is a word with no spaces in it and VALUE is the rest of the
line, with leading and trailing whitespace trimmed (and it can be empty).
In the example below, the transaction has a `purpose` tag with value
`research`, and the expenses:cinema posting has the `fun` and `outing`
tags.
2011-09-17 10:46:47 +04:00
1/1 movie ticket
; purpose: research
expenses:cinema $10
; fun:
; outing:
assets:checking
Filtering reports by tag is work in progress. For the moment, you can
match transactions or postings' tag values by adding `tag NAME=VALUE` on
the command line. Limitations: VALUE must be exact, you can't test for a
tag's existence, postings don't inherit their transaction's tags and this
isn't supported in the web interface yet.
2011-09-17 10:46:47 +04:00
2010-12-09 03:35:14 +03:00
### Default commodity
You can set a default commodity or currency with a D directive. This will
be used for any subsequent amounts which have no commodity symbol.
2010-12-09 03:35:14 +03:00
; default commodity: british pound, comma thousands separator, two decimal places
D £1,000.00
2010/1/1
a 2340 ; no commodity symbol, will use the above
b
If such an amount is the first seen in that commodity, the canonical
[commodity display settings](#commodity-display-settings) will also be
taken from the directive.
2010-12-09 03:35:14 +03:00
### Prices
#### Transaction prices
2010-12-09 03:35:14 +03:00
When recording an amount, you can also record its price in another
2012-02-23 19:28:01 +04:00
commodity. This documents an exchange rate that was applied within
this transaction (or to be precise, within the posting). There are
three ways to specify a transaction price:
2010-12-09 03:35:14 +03:00
1. Write the unit price (exchange rate) explicitly as `@ UNITPRICE` after the amount:
2009/1/1
assets:foreign currency €100 @ $1.35 ; one hundred euros at $1.35 each
2011-12-09 03:26:10 +04:00
assets:cash
2010-12-09 03:35:14 +03:00
2. Or write the total price for this amount as `@@ TOTALPRICE`:
2011-12-09 03:26:10 +04:00
2009/1/1
assets:foreign currency €100 @@ $135 ; one hundred euros at $135 for the lot
2011-12-09 03:26:10 +04:00
assets:cash
2010-12-09 03:35:14 +03:00
3. Or fully specify all posting amounts using exactly two commodities:
2010-12-09 03:35:14 +03:00
2009/1/1
assets:foreign currency €100 ; one hundred euros
assets:cash $-135 ; exchanged for $135
2010-12-09 03:35:14 +03:00
You can use the `--cost/-B` flag with reporting commands to see such
amounts converted to their price's commodity. Eg, using any of the above
examples we get:
2010-12-09 03:35:14 +03:00
$ hledger print --cost
2009/01/01
assets:foreign currency $135.00
assets $-135.00
#### Historical prices
2010-12-09 03:35:14 +03:00
You can also record a series of historical prices for a commodity using P
directives. Typically these are used to record daily market prices or
exchange rates. ledger uses them to calculate market value with -V, but
hledger currently ignores them. They look like this:
<!-- (A time and numeric time zone are allowed but ignored, like ledger.) -->
2010-12-09 03:35:14 +03:00
; Historical price directives look like: P DATE COMMODITYSYMBOL UNITPRICE
; These say the euro's exchange rate is $1.35 during 2009 and
; $1.40 from 2010/1/1 on.
P 2009/1/1 € $1.35
P 2010/1/1 € $1.40
2010-12-09 03:35:14 +03:00
### Including other files
You can pull in the content of additional journal files, by writing lines like this:
!include path/to/file.journal
The `!include` directive may only be used in journal files, and currently
it may only include other journal files (eg, not timelog files.)
### Default parent account
You can specify a parent account which will be prepended to all accounts
within a section of the journal. Use the `!account` directive like so:
!account home
2010/1/1
food $10
cash
!end
If `!end` is omitted, the effect lasts to the end of the file.
The above is equivalent to:
2010/01/01
home:food $10
home:cash $-10
Included files are also affected, eg:
!account business
!include biz.journal
!end
!account personal
!include personal.journal
!end
### Account aliases
You can define account aliases to rewrite certain account names (and their subaccounts).
2011-08-05 05:09:46 +04:00
This tends to be a little more reliable than post-processing with sed or similar.
The directive is `alias ORIG = ALIAS`, where ORIG and ALIAS are full account names.
2011-08-05 04:05:39 +04:00
To forget all aliases defined to this point, use `end aliases`.
Here's an example: say a sole proprietor has a personal.journal:
1/1
expenses:food $1
assets:cash
and a business.journal:
1/1
expenses:office supplies $1
assets:business checking
Here each entity has a simple journal with its own simple chart of
accounts. But at tax reporting time, we need to view these as a single
entity. So in unified.journal we adjust the personal account names to fit
within the business chart of accounts:
alias expenses = equity:draw:personal
alias assets:cash = assets:personal cash
include personal.journal
end aliases
include business.journal
giving:
$ hledger -f unified.journal print
2011/01/01
equity:draw:personal:food $1
assets:personal cash $-1
2011/01/01
expenses:office supplies $1
assets:business checking $-1
2011-08-05 04:05:39 +04:00
You can also specify aliases on the command line. This could be useful to
rewrite account names when sharing a report with someone else, such as
your accountant:
$ hledger --alias 'my earning=income:business'
Command-line alias options are applied after any alias directives in the
journal. At most one alias directive and one alias option will be applied
to each account name.
## Other file formats
2011-08-28 19:56:31 +04:00
In addition to the usual [journal files](#the-journal-file), hledger can
read [timelog files](#timelog-reporting). hledger 0.18 can also read
[CSV](http://en.wikipedia.org/wiki/Comma-separated_values) files natively
(the old `convert` command is no longer needed.)
2010-05-20 20:46:30 +04:00
An arbitrary CSV file does not provide enough information to be parsed as
2012-03-25 01:28:50 +04:00
a journal. So when reading CSV, hledger looks for an additional
[rules file](#the-rules-file), which identifies the CSV fields and assigns
accounts. For reading `FILE.csv`, hledger uses `FILE.rules` in the same
directory, auto-creating it if needed. You should configure the rules file
to get the best data from your CSV file. You can specify a different rules
file with `--rules-file` (useful when reading from standard input).
An example - sample.csv:
sample.csv:
"2012/3/22","TRANSFER TO SAVINGS","-10.00"
"2012/3/23","SOMETHING ELSE","5.50"
sample.rules:
2010-05-20 20:46:30 +04:00
date-field 0
description-field 1
amount-field 2
currency $
2011-09-26 21:39:34 +04:00
base-account assets:bank:checking
2011-09-28 04:30:40 +04:00
SAVINGS
2010-05-20 20:46:30 +04:00
assets:bank:savings
the resulting journal:
2010-05-20 20:46:30 +04:00
$ hledger -f sample.csv print
using conversion rules file sample.rules
2012/03/22 TRANSFER TO SAVINGS
assets:bank:savings $10.00
assets:bank:checking $-10.00
2011-09-26 21:39:34 +04:00
2012/03/23 SOMETHING ELSE
income:unknown $-5.50
assets:bank:checking $5.50
2011-09-26 21:39:34 +04:00
### The rules file
2011-09-26 21:39:34 +04:00
A rules file consists of the following optional directives, followed by
account-assigning rules. (Tip: rules file parse errors are not the
greatest, so check your rules file format if you're getting unexpected
results.)
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`account-field`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
> If the CSV file contains data corresponding to several accounts (for
> example - bulk export from other accounting software), the specified
> field's value, if non-empty, will override the value of `base-account`.
2010-05-20 20:46:30 +04:00
2011-09-28 04:30:40 +04:00
`account2-field`
2011-09-28 04:30:40 +04:00
> If the CSV file contains fields for both accounts in the transaction,
> you can use this in addition to `account-field`. If `account2-field` is
> unspecified, the [account-assigning rules](#account-assigning-rules) are
> used.
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`amount-field`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
> This directive specifies the CSV field containing the transaction
> amount. The field may contain a simple number or an hledger-style
> [amount](#amounts), perhaps with a [price](#prices). See also
> `amount-in-field`, `amount-out-field`, `currency-field` and
> `base-currency`.
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`amount-in-field`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`amount-out-field`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
> If the CSV file uses two different columns for in and out movements, use
> these directives instead of `amount-field`. Note these expect each
> record to have a positive number in one of these fields and nothing in
> the other.
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`base-account`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
> A default account to use in all transactions. May be overridden by
> `account1-field` and `account2-field`.
2011-09-28 04:30:40 +04:00
`base-currency`
2010-05-20 20:46:30 +04:00
2011-09-28 04:30:40 +04:00
> A default currency symbol which will be prepended to all amounts.
> See also `currency-field`.
2010-05-20 20:46:30 +04:00
2011-09-28 04:30:40 +04:00
`code-field`
2010-05-20 20:46:30 +04:00
2011-09-28 04:30:40 +04:00
> Which field contains the transaction code or check number (`(NNN)`).
2011-01-22 12:37:25 +03:00
2011-09-28 04:30:40 +04:00
`currency-field`
2011-06-03 05:13:00 +04:00
2011-09-28 04:30:40 +04:00
> The currency symbol in this field will be prepended to all amounts. This
> overrides `base-currency`.
2011-09-28 04:30:40 +04:00
`date-field`
2010-05-20 20:46:30 +04:00
2011-09-28 21:12:51 +04:00
> Which field contains the transaction date. A number of common
> four-digit-year date formats are understood by default; other formats
> will require a `date-format` directive.
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`date-format`
2011-09-26 21:39:34 +04:00
2011-09-28 21:12:51 +04:00
> This directive specifies one additional format to try when parsing the
> date field, using the syntax of Haskell's
> [formatTime](http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:formatTime).
> Eg, if the CSV dates are non-padded D/M/YY, use:
2011-09-28 04:30:40 +04:00
>
2011-09-28 21:12:51 +04:00
> date-format %-d/%-m/%y
2011-09-28 04:30:40 +04:00
>
2011-09-28 21:12:51 +04:00
> Note custom date formats work best when hledger is built with version
> 1.2.0.5 or greater of the [time](http://hackage.haskell.org/package/time) library.
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`description-field`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
> Which field contains the transaction's description. This can be a simple
2011-09-28 21:12:51 +04:00
> field number, or a custom format combining multiple fields, eg:
2011-09-28 04:30:40 +04:00
>
2011-09-28 21:12:51 +04:00
> description-field %(1) - %(3)
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`effective-date-field`
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
> Which field contains the transaction's [effective date](#actual-effective-dates).
2011-09-26 21:39:34 +04:00
2011-09-28 04:30:40 +04:00
`status-field`
2010-05-20 20:46:30 +04:00
2011-09-28 04:30:40 +04:00
> Which field contains the transaction cleared status (`*`).
Account-assigning rules select an account to transfer to based on the
description field (unless `account2-field` is used.) Each
account-assigning rule is a paragraph consisting of one or more
2011-09-28 04:30:40 +04:00
case-insensitive regular expressions), one per line, followed by the
account name to use when the transaction's description matches any of
these patterns. Eg:
2011-09-28 04:30:40 +04:00
WHOLE FOODS
SUPERMARKET
expenses:food:groceries
2011-09-28 04:30:40 +04:00
If you want to clean up messy bank data, you can add `=` and a replacement
pattern, which rewrites the matched part of the description. (To rewrite
the entire description, use `.*PAT.*=REPL`). You can also refer to matched
groups in the usual way with `\0` etc. Eg:
2011-09-28 04:30:40 +04:00
BLKBSTR=BLOCKBUSTER
expenses:entertainment
2011-09-28 04:30:40 +04:00
Lines beginning with `;` or `#` are ignored - just don't use them in the
middle of an account-assigning rule.
## Commands
hledger provides a number of subcommands, in the style of git or darcs.
Run `hledger` with no arguments to see a list. Most are built in to the
core hledger package, while [add-on commands](#add-on-commands) will
appear if you install additional hledger-* packages. You can also install
your own subcommands by putting programs or scripts named `hledger-NAME`
in your PATH.
### Misc commands
Here are some miscellaneous commands you might use to get started:
#### add
The add command prompts interactively for new transactions, and appends
them to the journal file. Each transaction is appended when you complete
it by entering `.` (period) at the account prompt. Enter control-D or
control-C when you are done.
The add command tries to be helpful, providing:
- Sensible defaults
- History awareness: if there are existing transactions approximately
matching the description you enter, they will be displayed and the best
match will provide defaults for the other fields. If you specify
[filter pattern(s)](#filter-patterns) on the command line, only matching
transactions will be considered as history.
- Readline-style input: during data entry, the usual editing keys should
work.
- Auto-completion for account names: while entering account names, the tab
key will auto-complete as far as possible, or list the available
options.
- Default commodity awareness: if the journal has a
[default commodity directive](#default-commodity), that will be applied
to any bare numbers entered.
Examples:
$ hledger add
$ hledger -f home.journal add equity:bob
2011-08-28 19:56:31 +04:00
#### test
2012-03-25 01:28:50 +04:00
This command runs hledger's built-in unit tests and displays a quick
report. A pattern can be provided to filter tests by name. It's mainly
used in development, but it's also nice to be able to check hledger for
smoke at any time.
2011-08-28 19:56:31 +04:00
Examples:
$ hledger test
$ hledger test -v balance
2010-11-19 01:20:45 +03:00
2011-08-28 19:56:31 +04:00
### Reporting commands
2010-11-19 01:20:45 +03:00
2011-08-28 19:56:31 +04:00
These are the commands for querying your ledger.
#### balance
The balance command displays accounts and their balances, indented to show the account hierarchy.
2010-11-19 01:20:45 +03:00
Examples:
2011-08-28 19:56:31 +04:00
$ hledger balance
$ hledger balance food -p 'last month'
2010-11-19 01:20:45 +03:00
2011-08-28 19:56:31 +04:00
A final total is displayed, use `--no-total` to suppress this. Also, the
`--depth N` option shows accounts only to the specified depth, useful for
an overview:
$ for y in 2006 2007 2008 2009 2010; do echo; echo $y; hledger -f $y.journal balance ^expenses --depth 2; done
With `--flat`, a non-hierarchical list of full account names is displayed
instead. This mode shows just the accounts actually contributing to the
balance, making the arithmetic a little more obvious to non-hledger users.
In this mode you can also use `--drop N` to elide the first few account
name components. Note `--depth` doesn't work too well with `--flat` currently;
it hides deeper accounts rather than aggregating them.
#### print
2010-11-19 01:20:45 +03:00
The print command displays full transactions from the journal file, tidily
formatted and showing all amounts explicitly. The output of print is
always a valid hledger journal.
hledger's print command also shows all unit prices in effect, or (with
-B/--cost) shows cost amounts.
Examples:
$ hledger print
$ hledger print employees:bob | hledger -f- register expenses
2011-08-28 19:56:31 +04:00
#### register
2010-11-19 01:20:45 +03:00
The register command displays postings, one per line, and their running total.
With no [filter patterns](#filter-patterns), this is not all that different from [print](#print):
$ hledger register
More typically, use it to see a specific account's activity:
$ hledger register assets:bank:checking
2010-05-20 20:46:30 +04:00
2010-11-19 01:20:45 +03:00
The `--depth` option limits the amount of sub-account detail displayed:
$ hledger register assets:bank:checking --depth 2
With a [reporting interval](#reporting-interval) it shows aggregated
summary postings within each interval:
$ hledger register --monthly rent
$ hledger register --monthly -E food --depth 4
2011-08-28 23:50:33 +04:00
#### activity
2010-11-19 01:20:45 +03:00
2011-08-28 23:50:33 +04:00
The activity command displays a quick textual bar chart showing
2011-08-28 19:56:31 +04:00
transaction counts by day, week, month or other reporting interval.
2010-11-19 01:20:45 +03:00
Examples:
2011-08-28 23:50:33 +04:00
$ hledger activity -p weekly dining
2010-11-19 01:20:45 +03:00
#### incomestatement
This is intended to display a standard-looking
[income statement](http://en.wikipedia.org/wiki/Income_statement). Currently
it is similar to doing `hledger balance '^(income|expenses?|profits?|loss(es)?)(:|$)'`.
#### balancesheet
This is intended to display a standard-looking
[balance sheet](http://en.wikipedia.org/wiki/Balance_sheet). Currently
it is similar to doing `hledger balance '^(assets?|liabilit(y|ies)|equity)(:|$)'`.
2011-08-28 19:56:31 +04:00
#### stats
2010-05-20 20:46:30 +04:00
2011-08-28 19:56:31 +04:00
The stats command displays summary information for the whole journal, or
a matched part of it.
2010-05-20 20:46:30 +04:00
Examples:
2011-08-28 19:56:31 +04:00
$ hledger stats
$ hledger stats -p 'monthly in 2009'
2010-05-20 20:46:30 +04:00
2011-08-28 19:56:31 +04:00
### Add-on commands
2010-11-19 01:20:45 +03:00
2010-12-06 01:25:49 +03:00
The following extra commands will be available if they have been
2011-08-28 23:42:39 +04:00
[installed](#installing) (run `hledger` by itself to find out):
2010-11-19 01:20:45 +03:00
2011-08-28 19:56:31 +04:00
#### web
2010-11-19 01:20:45 +03:00
2012-03-25 01:28:50 +04:00
The web command (provided by the hledger-web package) runs a web
2011-09-28 04:54:30 +04:00
server providing a web-based user interface
([release demo](http://demo.hledger.org),
2011-09-28 04:54:30 +04:00
[latest demo](http://demo.hledger.org:5001)). The web UI provides
reporting, including a more useful account register view, and also data
entry and editing.
2010-11-19 01:20:45 +03:00
2011-08-28 19:56:31 +04:00
web-specific options:
2010-12-09 03:35:14 +03:00
--port=N serve on tcp port N (default 5000)
--base-url=URL use this base url (default http://localhost:PORT)
If you want to visit the web UI from other machines, you'll need to use
this option to fix the hyperlinks. Just give your machine's host name or
ip address instead of localhost. This option is also lets you conform to a
custom url scheme when running hledger-web behind a reverse proxy as part
of a larger site. Note that the PORT in the base url need not be the same
as the `--port` argument.
2011-09-28 04:54:30 +04:00
Warning: unlike other hledger commands, `web` can alter existing journal
data, via the edit form. A numbered backup of the file will be saved on
each edit, normally (ie if file permissions allow, disk is not full, etc.)
Also, there is no built-in access control. So unless you run it behind an
2011-08-28 23:42:39 +04:00
authenticating proxy, any visitor to your server will be able to see and
overwrite the journal file (and included files.)
2011-09-28 04:54:30 +04:00
hledger-web disallows edits which would leave the journal file not in
2012-03-25 01:28:50 +04:00
valid [journal format](#the-journal-file). If the file becomes unparseable
by other means, hledger-web will show an error until the file has been
fixed.
2010-12-07 12:59:18 +03:00
Examples:
2010-12-07 10:18:15 +03:00
2010-12-07 12:59:18 +03:00
$ hledger-web
$ hledger-web -E -B --depth 2 -f some.journal
$ hledger-web --port 5010 --base-url http://some.vhost.com --debug
2010-12-07 10:18:15 +03:00
2012-03-25 01:28:50 +04:00
#### vty
The vty command (provided by the hledger-vty package) starts a simple
curses-style (full-screen, text) user interface, which allows interactive
navigation of the print/register/balance reports. This lets you browse
around and explore your numbers quickly with less typing.
vty-specific options:
--debug-vty run with no terminal output, showing console
Examples:
$ hledger vty
$ hledger vty -BE food
#### chart
The chart command (provided by the hledger-chart package) saves an image
file, by default "hledger.png", showing a basic pie chart of your top
account balances. Note that positive and negative balances will not be
displayed together in the same chart; any balances not matching the sign
of the first one will be ignored.
chart-specific options:
-o/--chart-output=IMGFILE output filename (default: hledger.png)
You can specify a different output file name with -o/--output. The data
currently will always be in PNG format.
--chart-items=N number of accounts to show (default: 10)
The number of top accounts to show (default is 10).
--chart-size=WIDTHxHEIGHT image size (default: 600x400)
You can adjust the image resolution with --size=WIDTHxHEIGHT (in pixels).
To show only accounts above a certain depth, use the --depth option;
otherwise the chart can include accounts of any depth. When a parent and
child account both appear in a chart, the parent's balance will be
exclusive of the child's.
Examples:
$ hledger chart assets --depth 2
$ hledger chart liabilities --depth 2
$ hledger chart ^expenses -o balance.png --size 1000x600 --items 20
$ for m in 01 02 03 04 05 06 07 08 09 10 11 12; do hledger chart -p 2009/$m ^expenses --depth 2 -o expenses-2009$m.png --size 400x300; done
2011-08-28 23:42:39 +04:00
## Reporting options
2010-05-20 20:46:30 +04:00
2011-08-28 23:42:39 +04:00
The following additional features and options allow for fine-grained
reporting. They are common to most commands, where applicable.
2010-11-19 00:44:01 +03:00
2010-12-09 03:35:14 +03:00
### Filter patterns
2010-05-20 20:46:30 +04:00
Most commands accept one or more filter pattern arguments after the
command name, to select a subset of transactions or postings. There are
two kinds of pattern:
- an account pattern, which is a regular expression. This is
matched against postings' accounts. Optionally, it may be prefixed
with `not:` in which case the match is negated.
- a description pattern, like the above but prefixed with
`desc:`. This is matched against transactions' descriptions. Note,
when negating a desc: pattern, not: goes last, eg:
`desc:not:someregexp`.
2012-05-15 21:30:14 +04:00
<!--
New:
Most commands accept one or more filter pattern arguments after the
command name, to select a subset of the data. There are several kinds
of filter pattern:
- `acct:ACCTREGEX` - match account names by regular expression
- `desc:DESCREGEX` - match transaction descriptions by regular expression
- `tag:TAGNAMEREGEX[:TAGVALUEREGEX]` - match a [tag](#tags) name, and
optionally the value, by regular expression
- `TAGNAME:[TAGVALUEREGEX]` - match a tag name exactly, and optionally
the value by regular expression.
- `ACCTREGEX` - match account names by regular expression
Later:
- `status:[*]`
- `code:CODEREGEX`
- `date:DATEEXPR`
- `edate:DATEEXPR`
- `type:regular|virtual|balancedvirtual`
- `comment:COMMENTREGEX`
- `amount:AMOUNTEXPR`
- `commodity:COMMODITYSYMBOLREGEX`
Any of these can be prefixed with `not:` or `!` to negate the match.
-->
2010-05-20 20:46:30 +04:00
When you specify multiple filter patterns, hledger generally selects the
transactions or postings which match (or negatively match)
> *any of the account patterns* AND
> *any of the description patterns*
The [print](#print) command selects transactions which
> *match any of the description patterns* AND
> *have any postings matching any of the positive account patterns*
> AND
> *have no postings matching any of the negative account patterns*
2010-12-09 03:35:14 +03:00
### Smart dates
2010-05-20 20:46:30 +04:00
2010-12-08 01:50:46 +03:00
Unlike the journal file, hledger's user interface accepts more flexible
"smart dates", for example in the `-b` and `-e` options, period
expressions, display expressions, the add command and the web add form.
Smart dates allow some natural english words, will assume 1 where
less-significant date parts are unspecified, and can be relative to
today's date. Examples:
- `2009/1/1`, `2009/01/01`, `2009-1-1`, `2009.1.1` (simple dates)
- `2009/1`, `2009` (these also mean january 1, 2009)
- `1/1`, `january`, `jan`, `this year` (relative dates, meaning january 1 of this year)
- `next year` (january 1, next year)
- `this month` (the 1st of the current month)
- `this week` (the most recent monday)
- `last week` (the monday of the week before this one)
- `today`, `yesterday`, `tomorrow`
Spaces in smart dates are optional, so eg: `-b lastmonth` is valid.
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
### Period expressions
2010-05-20 20:46:30 +04:00
hledger supports flexible "period expressions" with the `-p/--period`
option to select transactions within a period of time (eg in 2009) and/or
with a reporting interval (eg weekly). hledger period expressions are
2010-05-20 20:46:30 +04:00
similar but not identical to c++ ledger's.
2010-12-08 01:50:46 +03:00
Here is a basic period expression specifying the first quarter of 2009.
Note the start date is always included and the end date is always excluded:
2010-05-20 20:46:30 +04:00
-p "from 2009/1/1 to 2009/4/1"
Keywords like "from" and "to" are optional, and so are the spaces. Just
don't run two dates together:
-p2009/1/1to2009/4/1
-p"2009/1/1 2009/4/1"
Dates are [smart dates](#smart-dates), so if the current year is 2009, the
above can also be written as:
-p "1/1 to 4/1"
-p "january to apr"
-p "this year to 4/1"
If you specify only one date, the missing start or end date will be the
2010-07-25 03:54:29 +04:00
earliest or latest transaction in your journal:
2010-05-20 20:46:30 +04:00
-p "from 2009/1/1" (everything after january 1, 2009)
-p "from 2009/1" (the same)
-p "from 2009" (the same)
-p "to 2009" (everything before january 1, 2009)
A single date with no "from" or "to" defines both the start and end date
like so:
-p "2009" (the year 2009; equivalent to "2009/1/1 to 2010/1/1")
-p "2009/1" (the month of jan; equivalent to "2009/1/1 to 2009/2/1")
-p "2009/1/1" (just that day; equivalent to "2009/1/1 to 2009/1/2")
2010-12-09 03:35:14 +03:00
The `-b/--begin` and `-e/--end` options may be used as a shorthand for `-p
'from ...'` and `-p 'to ...'` respectively.
Note, however: a `-p/--period` option in the command line will cause any
`-b`/`-e`/`-D`/`-W`/`-M`/`-Q`/`-Y` flags to be ignored.
2010-07-25 03:54:29 +04:00
2010-12-09 03:35:14 +03:00
### Reporting interval
2010-05-20 20:46:30 +04:00
2010-12-08 01:50:46 +03:00
Period expressions can also begin with (or be) a reporting interval, which
2011-08-28 23:50:33 +04:00
affects commands like [register](#register) and [activity](#activity).
The reporting interval can be `daily`, `weekly`, `monthly`, `quarterly`, `yearly`,
or one of the `every ...` expressions below, optionally followed by `in`.
Examples:
2010-05-20 20:46:30 +04:00
-p "weekly from 2009/1/1 to 2009/4/1"
-p "monthly in 2008"
-p "bimonthly from 2008"
2010-05-20 20:46:30 +04:00
-p "quarterly"
-p "every 2 weeks"
-p "every 5 days from 1/3"
-p "every 15th day of month"
-p "every 4th day of week"
2010-07-25 03:54:29 +04:00
A reporting interval may also be specified with the `-D/--daily`,
`-W/--weekly`, `-M/--monthly`, `-Q/--quarterly`, and `-Y/--yearly`
2010-12-09 03:35:14 +03:00
options. But as noted above, a --period option will override these.
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
### Display expressions
2010-05-20 20:46:30 +04:00
2010-12-08 01:50:46 +03:00
Unlike a [period expression](#period-expressions), which selects the
2010-12-09 03:33:35 +03:00
transactions to be used for calculation, a display expression (specified
with `-d/--display`) selects which transactions will be displayed. This
useful, say, if you want to see your checking register just for this
month, but with an accurate running balance based on all transactions. Eg:
2010-12-08 01:50:46 +03:00
$ hledger register checking --display "d>=[1]"
2010-05-20 20:46:30 +04:00
2010-12-08 01:50:46 +03:00
meaning "make a register report of all checking transactions, but display
2010-12-09 03:35:14 +03:00
only the ones with date on or after the 1st of this month." This the only
kind of display expression we currently support, ie transactions before or
after a given (smart) date.
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
### Depth limiting
2010-05-20 20:46:30 +04:00
With the `--depth N` option, reports will show only the uppermost accounts
in the account tree, down to level N. See the [balance](#balance),
[register](#register) and [chart](#chart) examples.
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
### Timelog reporting
2010-05-20 20:46:30 +04:00
2011-04-23 18:55:51 +04:00
hledger can also read time log files in (a subset of) timeclock.el's
format, containing clock-in and clock-out entries like so:
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
i 2009/03/31 22:21:45 projects:A
o 2009/04/01 02:00:34
2010-12-09 03:35:14 +03:00
hledger treats the clock-in description ("projects:A") as an account name,
and creates a virtual transaction (or several - one per day) with the
appropriate amount of hours. From the time log above, hledger print gives:
2010-12-09 03:35:14 +03:00
2009/03/31 * 22:21-23:59
(projects:A) 1.6h
2010-12-09 03:35:14 +03:00
2009/04/01 * 00:00-02:00
(projects:A) 2.0h
2010-12-09 03:35:14 +03:00
Here is a
[sample.timelog](http://joyful.com/repos/hledger/data/sample.timelog) to
download and some queries to try:
2010-05-24 23:16:16 +04:00
2010-12-09 03:35:14 +03:00
hledger -f sample.timelog balance # current time balances
hledger -f sample.timelog register -p 2009/3 # sessions in march 2009
hledger -f sample.timelog register -p weekly --depth 1 --empty # time summary by week
2010-05-24 23:16:16 +04:00
2011-04-23 18:55:51 +04:00
To generate time logs, ie to clock in and clock out, you could:
2011-01-27 21:40:18 +03:00
2011-04-23 18:55:51 +04:00
- use emacs and the built-in timeclock.el, or
the extended [timeclock-x.el](http://www.emacswiki.org/emacs/timeclock-x.el)
and perhaps the extras in [ledgerutils.el](http://joyful.com/repos/ledgertools/ledgerutils.el)
2011-01-27 21:40:18 +03:00
- at the command line, use these bash aliases:
2011-04-23 18:55:51 +04:00
alias ti="echo i `date '+%Y-%m-%d %H:%M:%S'` \$* >>$TIMELOG"
alias to="echo o `date '+%Y-%m-%d %H:%M:%S'` >>$TIMELOG"
2011-01-27 21:40:18 +03:00
2011-04-23 18:55:51 +04:00
- or use the old `ti` and `to` scripts in the [c++ ledger 2.x repository](https://github.com/jwiegley/ledger/tree/maint/scripts).
2011-01-27 21:40:18 +03:00
These rely on a "timeclock" executable which I think is just the ledger 2 executable renamed.
2010-05-24 23:16:16 +04:00
2011-08-28 19:56:31 +04:00
### Custom output formats
2011-06-21 01:33:26 +04:00
2011-08-28 19:56:31 +04:00
The `--format FMT` option will customize the line format of the balance
command's output (only, for now). `FMT` is a C printf/strftime-style
format string, with the exception that field names are enclosed in
parentheses:
2011-06-21 01:33:26 +04:00
%[-][MIN][.MAX]([FIELD])
If the minus sign is given, the text is left justified. The `MIN` field
specified a minimum number of characters in width. After the value is
injected into the string, spaces is added to make sure the string is at
least as long as `MIN`. Similary, the `MAX` field specifies the maximum
2011-08-28 19:56:31 +04:00
number of characters. The string will be cut if the injected string is too
long.
2011-06-21 01:33:26 +04:00
- `%-(total) ` the total of an account, left justified
- `%20(total) ` The same, right justified, at least 20 chars wide
- `%.20(total) ` The same, no more than 20 chars wide
- `%-.20(total)` Left justified, maximum twenty chars wide
2011-08-28 19:56:31 +04:00
The following `FIELD` types are currently supported:
2011-06-21 01:33:26 +04:00
2011-08-28 19:56:31 +04:00
- `account` inserts the account name
- `depth_spacer` inserts a space for each level of an account's
2011-06-21 01:33:26 +04:00
depth. That is, if an account has two parents, this construct will
2011-08-28 19:56:31 +04:00
insert two spaces. If a minimum width is specified, that much space is
inserted for each level of depth. Thus `%5_`, for an account with four
parents, will insert twenty spaces.
- `total` inserts the total for the account
2011-06-21 01:33:26 +04:00
2011-08-28 19:56:31 +04:00
Examples:
2011-06-21 01:33:26 +04:00
If you want the account before the total you can use this format:
$ hledger balance --format "%20(account) %-(total)"
assets $-1
bank:saving $1
cash $-2
expenses $2
food $1
supplies $1
income $-2
gifts $-1
salary $-1
liabilities:debts $1
--------------------
0
Or, if you'd like to export the balance sheet:
$ hledger balance --format "%(total);%(account)" --no-total
$-1;assets
$1;bank:saving
$-2;cash
$2;expenses
$1;food
$1;supplies
$-2;income
$-1;gifts
$-1;salary
$1;liabilities:debts
The default output format is `%20(total) %2(depth_spacer)%-(account)`
2011-08-28 23:42:39 +04:00
## Appendices
### Compatibility with c++ ledger
2010-05-24 23:16:16 +04:00
2011-05-25 06:32:59 +04:00
hledger mimics a subset of ledger 3.x, and adds some features of its own.
We currently support:
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
- regular journal transactions
- journal format (we should be able to parse most ledger journals)
- timelog format
- multiple commodities
- prices and price history (with non-changing prices)
- virtual postings
- filtering by account and description
- print, register & balance commands
- period expressions quite similar to ledger's
- display expressions containing just a simple date predicate
2011-06-21 01:33:26 +04:00
- basic support (read: incomplete) for display formatting
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
We do not support:
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
- periodic and modifier transactions
- fluctuating prices
2011-06-21 01:33:26 +04:00
- display formats (actually, a small subset is supported)
2010-12-09 03:35:14 +03:00
- budget reports
2010-05-20 20:46:30 +04:00
2011-05-25 06:32:59 +04:00
And we add these commands:
2010-05-20 20:46:30 +04:00
2010-12-09 03:35:14 +03:00
- add
- chart
- vty
- web
2010-05-20 20:46:30 +04:00
2011-08-28 23:42:39 +04:00
#### Implementation
2010-05-20 20:46:30 +04:00
Unlike c++ ledger, hledger is written in the Haskell programming
language. Haskell enables a coding style known as pure lazy functional
programming, which holds the promise of more robust and maintainable
software built with fewer lines of code. Haskell also provides a more
abstracted, portable platform which can make deployment and installation
easier in some cases. Haskell also brings some new challenges such as
managing memory growth.
2011-08-28 23:42:39 +04:00
#### File format compatibility
2010-05-20 20:46:30 +04:00
hledger's file format is mostly identical with that of c++ ledger, with
2011-01-20 04:07:56 +03:00
some features being accepted but ignored (eg, modifier entries and
periodic entries). There are subtle differences in parser behaviour, eg
comments may be permissible in different places. hledger does not allow
separate dates for individual postings, or AMT1=AMT2 or { } syntax.
2010-05-20 20:46:30 +04:00
Generally, it's easy to keep a journal file that works with both hledger
2011-05-25 06:32:59 +04:00
and c++ ledger if you avoid these. Occasionally you'll need to make small
2011-01-20 04:07:56 +03:00
adjustments to restore compatibility for one or the other.
2010-07-24 23:45:18 +04:00
2011-04-23 18:55:51 +04:00
See also:
[other differences](#other-differences),
[usage issues](#usage-issues).
2011-01-14 03:38:54 +03:00
2011-08-28 23:42:39 +04:00
#### Features not supported
2010-05-20 20:46:30 +04:00
c++ ledger features not currently supported include: modifier and periodic
entries, and the following c++ ledger options and commands:
Basic options:
-o, --output FILE write output to FILE
-i, --init-file FILE initialize ledger using FILE (default: ~/.ledgerrc)
-a, --account NAME use NAME for the default account (useful with QIF)
Report filtering:
-c, --current show only current and past entries (not future)
--period-sort EXPR sort each report period's entries by EXPR
-L, --actual consider only actual (non-automated) transactions
-r, --related calculate report using related transactions
--budget generate budget entries based on periodic entries
--add-budget show all transactions plus the budget
--unbudgeted show only unbudgeted transactions
--forecast EXPR generate forecast entries while EXPR is true
-l, --limit EXPR calculate only transactions matching EXPR
-t, --amount EXPR use EXPR to calculate the displayed amount
-T, --total EXPR use EXPR to calculate the displayed total
Output customization:
-n, --collapse Only show totals in the top-most accounts.
-s, --subtotal other: show subtotals
-P, --by-payee show summarized totals by payee
-x, --comm-as-payee set commodity name as the payee, for reporting
--dow show a days-of-the-week report
-S, --sort EXPR sort report according to the value expression EXPR
-w, --wide for the default register report, use 132 columns
--head COUNT show only the first COUNT entries (negative inverts)
--tail COUNT show only the last COUNT entries (negative inverts)
--pager PAGER send all output through the given PAGER program
-A, --average report average transaction amount
-D, --deviation report deviation from the average
-%, --percentage report balance totals as a percentile of the parent
--totals in the "xml" report, include running total
-j, --amount-data print only raw amount data (useful for scripting)
-J, --total-data print only raw total data
-y, --date-format STR use STR as the date format (default: %Y/%m/%d)
-F, --format STR use STR as the format; for each report type, use:
--balance-format --register-format --print-format
--plot-amount-format --plot-total-format --equity-format
--prices-format --wide-register-format
Commodity reporting:
--price-db FILE sets the price database to FILE (def: ~/.pricedb)
-L, --price-exp MINS download quotes only if newer than MINS (def: 1440)
-Q, --download download price information when needed
-O, --quantity report commodity totals (this is the default)
-V, --market report last known market value
-g, --performance report gain/loss for each displayed transaction
-G, --gain report net gain/loss
Commands:
xml [REGEXP]... print matching entries in XML format
equity [REGEXP]... output equity entries for matching accounts
prices [REGEXP]... display price history for matching commodities
entry DATE PAYEE AMT output a derived entry, based on the arguments
2011-08-28 23:42:39 +04:00
#### Other differences
2010-05-20 20:46:30 +04:00
2011-09-23 18:27:26 +04:00
- hledger recognises description and negative patterns by "desc:"
and "not:" prefixes, unlike ledger 3's free-form parser
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger doesn't require a space before command-line option
values, eg either `-f-` or `-f -` is fine
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger's weekly reporting intervals always start on mondays
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger shows start and end dates of the intervals requested,
not just the span containing data
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger always shows timelog balances in hours
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger splits multi-day timelog sessions at midnight
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger doesn't track the value of commodities with varying
price; prices are fixed as of the transaction date
2010-07-24 23:45:18 +04:00
2011-09-23 18:27:26 +04:00
- hledger's output follows the decimal point character, digit grouping,
and digit group separator character used in the journal.
- hledger print shows amounts for all postings, and shows unit prices for
amounts which have them. (This means that it does not currently print
multi-commodity transactions in valid journal format.)
- hledger print ignores the --effective flag, always showing both dates.
ledger print shows only the effective date with --effective, but not
vice versa.
2010-05-20 20:46:30 +04:00
2011-09-23 18:27:26 +04:00
- hledger's default commodity directive (D) sets the commodity for
2011-09-23 18:30:35 +04:00
subsequent commodityless amounts, and sets that commodity's display
settings if such an amount is the first seen. ledger uses D only for
commodity display settings and for the entry command.
2010-12-11 02:50:23 +03:00
2011-09-23 18:27:26 +04:00
- hledger generates a description for timelog sessions, instead of
taking it from the clock-out entry
2011-04-23 18:55:51 +04:00
2011-08-28 23:42:39 +04:00
### Troubleshooting
Sorry you're here! There are a lot of ways things can go wrong. Here are
some known issues and things to try. Please also seek
[support](DEVELOPMENT.html#support) from the
[IRC channel](irc://irc.freenode.net/#ledger),
[mail list](http://list.hledger.org) or
[bug tracker](http://bugs.hledger.org).
#### Installation issues
Starting from the top, consider whether each of these might apply to
you. Tip: blindly reinstalling/upgrading everything in sight probably
won't work, it's better to go in small steps and understand the problem,
or get help.
- **Did you cabal update ?**
If not, `cabal update` and try again.
- **Do you have a new enough version of GHC ?**
2012-05-29 22:34:33 +04:00
Run `ghc --version`. hledger requires GHC 7.0 or greater
(on [some platforms](#5551), 7.2.1 can be helpful).
2011-02-04 07:50:32 +03:00
- **Do you have a new enough version of cabal ?**
Avoid ancient versions. `cabal --version` should report at least
2012-05-29 22:34:33 +04:00
0.10 (and 0.14 is much better). You may be able to upgrade it with:
$ cabal update
$ cabal install cabal-install
- **There might be a dependency or compilation error with a hledger package**
The current hledger release might have an error in its code, or its
package dependencies may have become out of date.
Ask for help, and check the
[recent changes](http://joyful.com/darcsden/simon/hledger/changes) to
see if the [latest development version](#installing) might have a fix.
This issue should be uncommon. It's not always easy to distinguish it
from...
- **cabal can't satisfy the new dependencies due to old installed packages**
Cabal dependency failures become more likely as you install more
packages over time. If you have this problem, there are two easy
workarounds: 1. build hledger in an isolated package environment with
[virthualenv](http://hackage.haskell.org/package/virthualenv) (or
[cabal-dev](http://hackage.haskell.org/package/cabal-dev)), or 2. just
[reset your packages](https://gist.github.com/1185421).
- **An error involving some other package**
Look at the output carefully and identify the problem package(s). Try
installing each one individually, eg `cabal install pkg1`. Look for the
cause of the failure near the end of the output. If necessary, add `-v2`
or `-v3` for more verbose output. Often the problem is that you need to
install some C library that the haskell package depends on, using your
platform's package management system.
- <a name="5551" />**can't load .so/.DLL for: ncursesw (/usr/lib/libncursesw.so: file too short)**
(or similar): cf [GHC bug #5551](http://hackage.haskell.org/trac/ghc/ticket/5551).
Upgrade your GHC to 7.2.1, or try your luck with [this workaround](http://eclipsefp.github.com/faq.html).
- **ExitFailure 11**
See
[http://hackage.haskell.org/trac/hackage/ticket/777](http://hackage.haskell.org/trac/hackage/ticket/777).
This means that a build process has been killed, usually because it grew
too large. This is common on memory-limited VPS's and with GHC 7.4.1.
Look for some memory-hogging processes you can kill, increase your RAM,
or limit GHC's heap size by doing `cabal install ... --ghc-options='+RTS
-M400m'` (400 megabytes works well on my 1G VPS, adjust up or down..)
- <a name="iconv" />**Undefined symbols: ... _iconv ... on OS X**
This kind of error:
Linking dist/build/hledger/hledger ...
Undefined symbols:
"_iconv_close", referenced from:
_hs_iconv_close in libHSbase-4.2.0.2.a(iconv.o)
"_iconv", referenced from:
_hs_iconv in libHSbase-4.2.0.2.a(iconv.o)
"_iconv_open", referenced from:
_hs_iconv_open in libHSbase-4.2.0.2.a(iconv.o)
probably means you are on a mac with macports libraries installed, cf
[http://hackage.haskell.org/trac/ghc/ticket/4068](http://hackage.haskell.org/trac/ghc/ticket/4068).
To work around temporarily, add this --extra-lib-dirs flag:
$ cabal install hledger --extra-lib-dirs=/usr/lib
or permanently, add this to ~/.cabal/config:
extra-lib-dirs: /usr/lib
- **hledger-vty requires curses-related libraries**
On Ubuntu, eg, you'll need the `libncurses5-dev` package. On Windows,
these are not available (unless perhaps via Cygwin.)
- **hledger-chart requires GTK-related libraries**
On Ubuntu, eg, install the `libghc6-gtk-dev` package. See also [Gtk2Hs installation notes](http://code.haskell.org/gtk2hs/INSTALL).
2011-08-28 23:42:39 +04:00
#### Usage issues
Here are some issues you might encounter when you run hledger:
- **hledger fails to parse some valid ledger files**
See [file format compatibility](#file-format-compatibility).
- <a name="locale" />**hledger gives "Illegal byte sequence" or "Invalid or incomplete multibyte or wide character" errors**
hledger, like all GHC executables, requires an appropriate system locale
in order to handle non-ascii data. Eg, it's common for journal files to
contain UTF8-encoded text, and in this case you would need to have a
UTF8-aware locale configured.
Here's an example of setting the locale temporarily, on ubuntu gnu/linux:
$ file my.journal
my.journal: UTF-8 Unicode text # <- the file is UTF8-encoded
$ locale -a
C
en_US.utf8 # <- a UTF8-aware locale is available
POSIX
$ LANG=en_US.utf8 hledger -f my.journal print # <- use it for this command
Here's one way to set it permanently, there may be better ways:
$ echo "export LANG=en_US.UTF-8" >>~/.bash_profile
$ bash --login
If we preferred to use eg `fr_FR.utf8` here, we'd have to install it first:
$ apt-get install language-pack-fr
$ locale -a
C
en_US.utf8
fr_BE.utf8
fr_CA.utf8
fr_CH.utf8
fr_FR.utf8
fr_LU.utf8
POSIX
$ LANG=fr_FR.utf8 hledger -f my.journal print
Note some platforms allow variant locale spellings, but not all
(ubuntu accepts `fr_FR.UTF8`, mac osx requires exactly `fr_FR.UTF-8`).
2011-01-14 03:38:54 +03:00
2011-08-28 23:42:39 +04:00
### Examples and recipes
2010-11-19 00:44:01 +03:00
- Here's a bash function that will run hledger chart and display
the image in your (graphical) emacs:
function chart () {
hledger chart $* && emacsclient -n hledger.png
}
Example:
$ chart food --depth 2 -p jan
See also the [extra](http://joyful.com/repos/hledger/extra) directory.
2011-08-21 00:19:54 +04:00
2011-08-28 23:42:39 +04:00
### Other resources
- The rest of the [hledger.org](http://hledger.org) site.
- The [c++ ledger site](https://github.com/jwiegley/ledger/wiki).
Also the [c++ ledger 2.x manual](http://joyful.com/repos/ledger/doc/ledger.html)
is slightly outdated but informative.
2010-11-19 03:00:41 +03:00
- [Why you need accounting](http://podcastle.org/2009/10/09/pc-miniature-38-accounting-for-dragons)