hledger/hledger/doc/commands.m4.md
2017-09-15 10:08:58 -07:00

25 KiB
Raw Blame History

COMMANDS

hledger provides a number of subcommands; hledger with no arguments shows a list.

If you install additional hledger-* packages, or if you put programs or scripts named hledger-NAME in your PATH, these will also be listed as subcommands.

Run a subcommand by writing its name as first argument (eg hledger incomestatement). You can also write one of the standard short aliases displayed in parentheses in the command list (hledger b), or any any unambiguous prefix of a command name (hledger inc).

Here are all the builtin commands in alphabetical order. See also hledger for a more organised command list, and hledger CMD -h for detailed command help.

accounts

Show account names. Alias: a.

--tree
show short account names, as a tree
--flat
show full account names, as a list (default)
--drop=N
in flat mode: omit N leading account name parts

This command lists all account names that are in use (ie, all the accounts which have at least one transaction posting to them). With query arguments, only matched account names are shown.

It shows a flat list by default. With --tree, it uses indentation to show the account hierarchy.

In flat mode you can add --drop N to omit the first few account name components.

Examples:

col3({{ shell({{ $ hledger accounts tree assets bank checking saving cash expenses food supplies income gifts salary liabilities debts }}) }},{{ shell({{ $ hledger accounts drop 1 bank:checking bank:saving cash food supplies gifts salary debts }}) }},{{ shell({{ $ hledger accounts assets🏦checking assets🏦saving assets:cash expenses:food expenses:supplies income:gifts income:salary liabilities:debts }}) }})

activity

Show an ascii barchart of posting counts per interval.

The activity command displays an ascii histogram showing transaction counts by day, week, month or other reporting interval (by day is the default). With query arguments, it counts only matched transactions.

$ hledger activity --quarterly
2008-01-01 **
2008-04-01 *******
2008-07-01 
2008-10-01 **

add

Prompt for transactions and add them to the journal.

--no-new-accounts
dont allow creating new accounts; helps prevent typos when entering account names

Many hledger users edit their journals directly with a text editor, or generate them from CSV. For more interactive data entry, there is the add command, which prompts interactively on the console for new transactions, and appends them to the journal file (if there are multiple -f FILE options, the first file is used.) Existing transactions are not changed. This is the only hledger command that writes to the journal file.

To use it, just run hledger add and follow the prompts. You can add as many transactions as you like; when you are finished, enter . or press control-d or control-c to exit.

Features:

  • add tries to provide useful defaults, using the most similar recent transaction (by description) as a template.
  • You can also set the initial defaults with command line arguments.
  • Readline-style edit keys can be used during data entry.
  • The tab key will auto-complete whenever possible - accounts, descriptions, dates (yesterday, today, tomorrow). If the input area is empty, it will insert the default value.
  • If the journal defines a default commodity, it will be added to any bare numbers entered.
  • A parenthesised transaction code may be entered following a date.
  • Comments and tags may be entered following a description or amount.
  • If you make a mistake, enter < at any prompt to restart the transaction.
  • Input prompts are displayed in a different colour when the terminal supports it.

Example (see the tutorial for a detailed explanation):

shell({{ $ hledger add Adding transactions to journal file /src/hledger/examples/sample.journal Any command line arguments will be used as defaults. Use tab key to complete, readline keys to edit, enter to accept defaults. An optional (CODE) may follow transaction dates. An optional ; COMMENT may follow descriptions or amounts. If you make a mistake, enter < at any prompt to restart the transaction. To end a transaction, enter . when prompted. To quit, enter . at a date prompt or press control-d or control-c. Date [2015/05/22]: Description: supermarket Account 1: expenses:food Amount 1: 10 Account 2: assets:checking Amount 2 [-10.0]: Account 3 (or . or enter to finish this transaction): . 2015/05/22 supermarket expenses:food $10 assets:checking $-10.0

Save this transaction to the journal ? [y]: Saved. Starting the next transaction (. or ctrl-D/ctrl-C to quit) Date [2015/05/22]: $ }})

include({{balance.m4.md}})

balancesheet

Show a balance sheet. Alias: bs.

--change
show balance change in each period, instead of historical ending balances
--cumulative
show balance change accumulated across periods (in multicolumn reports), instead of historical ending balances
-H --historical
show historical ending balance in each period (includes postings before report start date) (default)
--tree
show accounts as a tree; amounts include subaccounts (default in simple reports)
--flat
show accounts as a list; amounts exclude subaccounts except when account is depth-clipped (default in multicolumn reports)
-A --average
show a row average column (in multicolumn mode)
-T --row-total
show a row total column (in multicolumn mode)
-N --no-total
dont show the final total row
--drop=N
omit N leading account name parts (in flat mode)
--no-elide
dont squash boring parent accounts (in tree mode)
--format=LINEFORMAT
in single-column balance reports: use this custom line format

This command displays a simple balance sheet. It currently assumes that you have top-level accounts named asset and liability (plural forms also allowed.)

$ hledger balancesheet
Balance Sheet

Assets:
                 $-1  assets
                  $1    bank:saving
                 $-2    cash
--------------------
                 $-1

Liabilities:
                  $1  liabilities:debts
--------------------
                  $1

Total:
--------------------
                   0

With a reporting interval, multiple columns will be shown, one for each report period. As with multicolumn balance reports, you can alter the report mode with --change/--cumulative/--historical. Normally balancesheet shows historical ending balances, which is what you need for a balance sheet; note this means it ignores report begin dates.

balancesheetequity

Show a balance sheet including equity. Alias: bse.

Other than showing the equity accounts, this command is exactly the same as the command balancesheet. Please refer to it for the available options.

This command displays a balancesheet. It currently assumes that you have top-level accounts named asset, liability and equity (plural forms also allowed.)

$ hledger balancesheetequity
Balance Sheet With Equity

Assets:
                 $-2  assets
                  $1    bank:saving
                 $-3    cash
--------------------
                 $-2

Liabilities:
                  $1  liabilities:debts
--------------------
                  $1

Equity:
		  $1  equity:owner
--------------------
		  $1

Total:
--------------------
                   0

cashflow

Show a cashflow statement. Alias: cf.

--change
show balance change in each period (default)
--cumulative
show balance change accumulated across periods (in multicolumn reports), instead of changes during periods
-H --historical
show historical ending balance in each period (includes postings before report start date), instead of changes during each period
--tree
show accounts as a tree; amounts include subaccounts (default in simple reports)
--flat
show accounts as a list; amounts exclude subaccounts except when account is depth-clipped (default in multicolumn reports)
-A --average
show a row average column (in multicolumn mode)
-T --row-total
show a row total column (in multicolumn mode)
-N --no-total
dont show the final total row (in simple reports)
--drop=N
omit N leading account name parts (in flat mode)
--no-elide
dont squash boring parent accounts (in tree mode)
--format=LINEFORMAT
in single-column balance reports: use this custom line format

This command displays a simple cashflow statement It shows the change in all “cash” (ie, liquid assets) accounts for the period. It currently assumes that cash accounts are under a top-level account named asset and do not contain receivable, :A/R or :fixed.

$ hledger cashflow
Cashflow Statement

Cash flows:
                 $-1  assets
                  $1    bank:saving
                 $-2    cash
--------------------
                 $-1

Total:
--------------------
                 $-1

With a reporting interval, multiple columns will be shown, one for each report period. Normally cashflow shows changes in assets per period, though as with multicolumn balance reports you can alter the report mode with --change/--cumulative/--historical.

check-dates

Check that transactions are sorted by increasing date. With a query, only matched transactions dates are checked.

check-dupes

Report account names having the same leaf but different prefixes. An example: http://stefanorodighiero.net/software/hledger-dupes.html

equity

Print closing/opening transactions that bring some or all account balances to zero and back. Can be useful for bringing account balances across file boundaries.

help

Show any of the hledger manuals.

The help command displays any of the main hledger manuals, in one of several ways. Run it with no argument to list the manuals, or provide a full or partial manual name to select one.

hledger manuals are available in several formats. hledger help will use the first of these display methods that it finds: info, man, $PAGER, less, stdout (or when non-interactive, just stdout). You can force a particular viewer with the --info, --man, --pager, --cat flags.

shell({{ $ hledger help Please choose a manual by typing “hledger help MANUAL” (a substring is ok). Manuals: hledger hledger-ui hledger-web hledger-api journal csv timeclock timedot }})

shell({{ $ hledger help h man

hledger(1) hledger User Manuals hledger(1)

NAME hledger - a command-line accounting tool

SYNOPSIS hledger [-f FILE] COMMAND [OPTIONS] [ARGS] hledger [-f FILE] ADDONCMD [OPTIONS] [ARGS] hledger

DESCRIPTION hledger is a cross-platform program for tracking money, time, or any … }})

incomestatement

Show an income statement. Alias: is.

--change
show balance change in each period (default)
--cumulative
show balance change accumulated across periods (in multicolumn reports), instead of changes during periods
-H --historical
show historical ending balance in each period (includes postings before report start date), instead of changes during each period
--tree
show accounts as a tree; amounts include subaccounts (default in simple reports)
--flat
show accounts as a list; amounts exclude subaccounts except when account is depth-clipped (default in multicolumn reports)
-A --average
show a row average column (in multicolumn mode)
-T --row-total
show a row total column (in multicolumn mode)
-N --no-total
dont show the final total row
--drop=N
omit N leading account name parts (in flat mode)
--no-elide
dont squash boring parent accounts (in tree mode)
--format=LINEFORMAT
in single-column balance reports: use this custom line format

This command displays a simple income statement. It currently assumes that you have top-level accounts named income (or revenue) and expense (plural forms also allowed.)

$ hledger incomestatement
Income Statement

Revenues:
                 $-2  income
                 $-1    gifts
                 $-1    salary
--------------------
                 $-2

Expenses:
                  $2  expenses
                  $1    food
                  $1    supplies
--------------------
                  $2

Total:
--------------------
                   0

With a reporting interval, multiple columns will be shown, one for each report period. Normally incomestatement shows revenues/expenses per period, though as with multicolumn balance reports you can alter the report mode with --change/--cumulative/--historical.

prices

Print all market prices from the journal.

print

Show transactions from the journal. Aliases: p, txns.

-m STR --match=STR
show the transaction whose description is most similar to STR, and is most recent
--new
show only newer-dated transactions added in each file since last run
-x --explicit
show all amounts explicitly
-O FMT --output-format=FMT
select the output format. Supported formats: txt, csv.
-o FILE --output-file=FILE
write output to FILE. A file extension matching one of the above formats selects that format.
$ hledger print
2008/01/01 income
    assets:bank:checking            $1
    income:salary                  $-1

2008/06/01 gift
    assets:bank:checking            $1
    income:gifts                   $-1

2008/06/02 save
    assets:bank:saving              $1
    assets:bank:checking           $-1

2008/06/03 * eat & shop
    expenses:food                $1
    expenses:supplies            $1
    assets:cash                 $-2

2008/12/31 * pay off
    liabilities:debts               $1
    assets:bank:checking           $-1

The print command displays full journal entries (transactions) from the journal file in date order, tidily formatted. prints output is always a valid hledger journal. It preserves all transaction information, but it does not preserve directives or inter-transaction comments

Normally, the journal entrys explicit or implicit amount style is preserved. Ie when an amount is omitted in the journal, it will be omitted in the output. You can use the -x/--explicit flag to make all amounts explicit, which can be useful for troubleshooting or for making your journal more readable and robust against data entry errors. Note, -x will cause postings with a multi-commodity amount (these can arise when a multi-commodity transaction has an implicit amount) will be split into multiple single-commodity postings, for valid journal output.

With -B/--cost, amounts with transaction prices are converted to cost using that price.

With -m/--match and a STR argument, print will show at most one transaction: the one one whose description is most similar to STR, and is most recent. STR should contain at least two characters. If there is no similar-enough match, no transaction will be shown.

With --new, for each FILE being read, hledger reads (and writes) a special .FILE.seen file in the same directory, containing the latest transaction date(s) that were seen last time FILE was read. When this file is found, only transactions with newer dates (and new transactions on the latest date) are printed. This is useful for ignoring already-seen entries in import data, such as downloaded CSV files. Eg:

$ hledger -f bank1.csv print --new
# shows transactions added since last print --new on this file

It assumes that only same-or-newer-dated transactions are added to FILE, and that the order of same-date transactions remains stable.

The print command also supports output destination and CSV output. Heres an example of prints CSV output:

$ hledger print -Ocsv
"txnidx","date","date2","status","code","description","comment","account","amount","commodity","credit","debit","posting-status","posting-comment"
"1","2008/01/01","","","","income","","assets:bank:checking","1","$","","1","",""
"1","2008/01/01","","","","income","","income:salary","-1","$","1","","",""
"2","2008/06/01","","","","gift","","assets:bank:checking","1","$","","1","",""
"2","2008/06/01","","","","gift","","income:gifts","-1","$","1","","",""
"3","2008/06/02","","","","save","","assets:bank:saving","1","$","","1","",""
"3","2008/06/02","","","","save","","assets:bank:checking","-1","$","1","","",""
"4","2008/06/03","","*","","eat & shop","","expenses:food","1","$","","1","",""
"4","2008/06/03","","*","","eat & shop","","expenses:supplies","1","$","","1","",""
"4","2008/06/03","","*","","eat & shop","","assets:cash","-2","$","2","","",""
"5","2008/12/31","","*","","pay off","","liabilities:debts","1","$","","1","",""
"5","2008/12/31","","*","","pay off","","assets:bank:checking","-1","$","1","","",""
  • There is one CSV record per posting, with the parent transactions fields repeated.
  • The “txnidx” (transaction index) field shows which postings belong to the same transaction. (This number might change if transactions are reordered within the file, files are parsed/included in a different order, etc.)
  • The amount is separated into “commodity” (the symbol) and “amount” (numeric quantity) fields.
  • The numeric amount is repeated in either the “credit” or “debit” column, for convenience. (Those names are not accurate in the accounting sense; it just puts negative amounts under credit and zero or greater amounts under debit.)

print-unique

Print transactions which do not reuse an already-seen description.

register

Show postings and their running total. Aliases: r, reg.

--cumulative
show running total from report start date (default)
-H --historical
show historical running total/balance (includes postings before report start date)
-A --average
show running average of posting amounts instead of total (implies empty)
-r --related
show postings siblings instead
-w N --width=N
set output width (default: terminal width or COLUMNS. -wN,M sets description width as well)
-O FMT --output-format=FMT
select the output format. Supported formats: txt, csv.
-o FILE --output-file=FILE
write output to FILE. A file extension matching one of the above formats selects that format.

The register command displays postings, one per line, and their running total. This is typically used with a query selecting a particular account, to see that accounts activity:

$ hledger register checking
2008/01/01 income               assets:bank:checking            $1            $1
2008/06/01 gift                 assets:bank:checking            $1            $2
2008/06/02 save                 assets:bank:checking           $-1            $1
2008/12/31 pay off              assets:bank:checking           $-1             0

The --historical/-H flag adds the balance from any undisplayed prior postings to the running total. This is useful when you want to see only recent activity, with a historically accurate running balance:

$ hledger register checking -b 2008/6 --historical
2008/06/01 gift                 assets:bank:checking            $1            $2
2008/06/02 save                 assets:bank:checking           $-1            $1
2008/12/31 pay off              assets:bank:checking           $-1             0

The --depth option limits the amount of sub-account detail displayed.

The --average/-A flag shows the running average posting amount instead of the running total (so, the final number displayed is the average for the whole report period). This flag implies --empty (see below). It is affected by --historical. It works best when showing just one account and one commodity.

The --related/-r flag shows the other postings in the transactions of the postings which would normally be shown.

With a reporting interval, register shows summary postings, one per interval, aggregating the postings to each account:

$ hledger register --monthly income
2008/01                 income:salary                          $-1           $-1
2008/06                 income:gifts                           $-1           $-2

Periods with no activity, and summary postings with a zero amount, are not shown by default; use the --empty/-E flag to see them:

$ hledger register --monthly income -E
2008/01                 income:salary                          $-1           $-1
2008/02                                                          0           $-1
2008/03                                                          0           $-1
2008/04                                                          0           $-1
2008/05                                                          0           $-1
2008/06                 income:gifts                           $-1           $-2
2008/07                                                          0           $-2
2008/08                                                          0           $-2
2008/09                                                          0           $-2
2008/10                                                          0           $-2
2008/11                                                          0           $-2
2008/12                                                          0           $-2

Often, youll want to see just one line per interval. The --depth option helps with this, causing subaccounts to be aggregated:

$ hledger register --monthly assets --depth 1h
2008/01                 assets                                  $1            $1
2008/06                 assets                                 $-1             0
2008/12                 assets                                 $-1           $-1

Note when using report intervals, if you specify start/end dates these will be adjusted outward if necessary to contain a whole number of intervals. This ensures that the first and last intervals are full length and comparable to the others in the report.

Custom register output

register uses the full terminal width by default, except on windows. You can override this by setting the COLUMNS environment variable (not a bash shell variable) or by using the --width/-w option.

The description and account columns normally share the space equally (about half of (width - 40) each). You can adjust this by adding a description width as part of widths argument, comma-separated: --width W,D . Heres a diagram:

<--------------------------------- width (W) ---------------------------------->
date (10)  description (D)       account (W-41-D)     amount (12)   balance (12)
DDDDDDDDDD dddddddddddddddddddd  aaaaaaaaaaaaaaaaaaa  AAAAAAAAAAAA  AAAAAAAAAAAA

and some examples:

$ hledger reg                     # use terminal width (or 80 on windows)
$ hledger reg -w 100              # use width 100
$ COLUMNS=100 hledger reg         # set with one-time environment variable
$ export COLUMNS=100; hledger reg # set till session end (or window resize)
$ hledger reg -w 100,40           # set overall width 100, description width 40
$ hledger reg -w $COLUMNS,40      # use terminal width, and set description width

The register command also supports the -o/--output-file and -O/--output-format options for controlling output destination and CSV output.

register-match

Print the one posting whose transaction description is closest to DESC, in the style of the register command. Helps ledger-autosync detect already-seen transactions when importing.

rewrite

Print all transactions, adding custom postings to the matched ones.

stats

Show some journal statistics.

-o FILE --output-file=FILE
write output to FILE. A file extension matching one of the above formats selects that format.
$ hledger stats
Main journal file        : /src/hledger/examples/sample.journal
Included journal files   : 
Transactions span        : 2008-01-01 to 2009-01-01 (366 days)
Last transaction         : 2008-12-31 (2333 days ago)
Transactions             : 5 (0.0 per day)
Transactions last 30 days: 0 (0.0 per day)
Transactions last 7 days : 0 (0.0 per day)
Payees/descriptions      : 5
Accounts                 : 8 (depth 3)
Commodities              : 1 ($)

The stats command displays summary information for the whole journal, or a matched part of it. With a reporting interval, it shows a report for each report period.

The stats command also supports -o/--output-file for controlling output destination.

tags

List all the tag names in use.

test

Run built-in unit tests.

$ hledger test
Cases: 74  Tried: 74  Errors: 0  Failures: 0

This command runs hledgers built-in unit tests and displays a quick report. With a regular expression argument, it selects only tests with matching names. Its mainly used in development, but its also nice to be able to check your hledger executable for smoke at any time.

include(addons.m4.md)