diff --git a/hledger-lib/.date.m4 b/hledger-lib/.date.m4 index e5d9e9e97..30644042f 100644 --- a/hledger-lib/.date.m4 +++ b/hledger-lib/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{March 2025}})m4_dnl +m4_define({{_monthyear_}}, {{June 2025}})m4_dnl diff --git a/hledger-ui/.date.m4 b/hledger-ui/.date.m4 index e5d9e9e97..30644042f 100644 --- a/hledger-ui/.date.m4 +++ b/hledger-ui/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{March 2025}})m4_dnl +m4_define({{_monthyear_}}, {{June 2025}})m4_dnl diff --git a/hledger-ui/hledger-ui.1 b/hledger-ui/hledger-ui.1 index 9816cfc7f..70ddc0609 100644 --- a/hledger-ui/hledger-ui.1 +++ b/hledger-ui/hledger-ui.1 @@ -1,5 +1,5 @@ -.TH "HLEDGER\-UI" "1" "March 2025" "hledger-ui-1.42.99 " "hledger User Manuals" +.TH "HLEDGER\-UI" "1" "June 2025" "hledger-ui-1.43.99 " "hledger User Manuals" @@ -17,7 +17,7 @@ or .PD \f[CR]hledger ui \-\- [OPTS] [QUERYARGS]\f[R] .SH DESCRIPTION -This manual is for hledger\[aq]s terminal interface, version 1.42.99. +This manual is for hledger\[aq]s terminal interface, version 1.43.99. See also the hledger manual for common concepts and file formats. .PP hledger is a robust, user\-friendly, cross\-platform set of programs for @@ -437,33 +437,51 @@ immediately without having to context switch. This leaves more mental bandwidth for your accounting. Of course you can still interact with hledger\-ui when needed, eg to toggle cleared mode, or to explore the history. -.PP -There are currently some limitations with \f[CR]\-\-watch\f[R]: -.PP -It may not work correctly for you, depending on platform or system +.SS \-\-watch problems +\f[I]However.\f[R] There are limitations/unresolved bugs with +\f[CR]\-\-watch\f[R]: +.IP \[bu] 2 +It may not work at all for you, depending on platform or system configuration. -(Eg #836.) +On some unix systems, increasing fs.inotify.max_user_watches or +fs.file\-max parameters in /etc/sysctl.conf might help. +(#836) +.IP \[bu] 2 +It may not detect file changes made by certain tools, such as Jetbrains +IDEs or gedit. +(#1617) +.IP \[bu] 2 +It may not detect changes made from outside a virtual machine, ie by an +editor running on the host system. +.IP \[bu] 2 +It may not detect file changes on certain less common filesystems. +.IP \[bu] 2 +It may use increasing CPU and RAM over time, especially with large +files. +(This is probably not \-\-watch specific, you may be able to reproduce +it by pressing \f[CR]g\f[R] repeatedly.) +(#1825) .PP -At least on mac, there can be a slow build\-up of CPU usage over time, -until the program is restarted (or, suspending and restarting with -\f[CR]CTRL\-z\f[R] \f[CR]fg\f[R] may be enough). -.PP -It will not detect file changes made by certain editors, such as -Jetbrains IDEs or \f[CR]gedit\f[R], or on certain less common -filesystems. -(To work around, press \f[CR]g\f[R] to reload manually, or try -#1617\[aq]s \f[CR]fs.inotify.max_user_watches\f[R] workaround and let us -know.) -.PP -If you are viewing files mounted from another machine, the system clocks -on both machines should be roughly in agreement. +Tips/workarounds: +.IP \[bu] 2 +If \-\-watch won\[aq]t work for you, press \f[CR]g\f[R] to reload data +manually instead. +.IP \[bu] 2 +If \-\-watch is leaking resources over time, quit and restart (or +suspend and resume) hledger\-ui when you\[aq]re not using it. +.IP \[bu] 2 +When running hledger\-ui inside a VM, also make file changes inside the +VM. +.IP \[bu] 2 +When working with files mounted from another machine, make sure the +system clocks on both machines are roughly in agreement. .SH ENVIRONMENT \f[B]LEDGER_FILE\f[R] The main journal file to use when not specified with \f[CR]\-f/\-\-file\f[R]. Default: \f[CR]$HOME/.hledger.journal\f[R]. .SH BUGS -We welcome bug reports in the hledger issue tracker (shortcut: -https://bugs.hledger.org), or on the hledger chat or mail list +We welcome bug reports in the hledger issue tracker +(https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). .PP Some known issues: @@ -471,14 +489,15 @@ Some known issues: \f[CR]\-f\-\f[R] doesn\[aq]t work (hledger\-ui can\[aq]t read from stdin). .PP +\f[CR]\-\-watch\f[R] is not robust, especially with large files (see +WATCH MODE above). +.PP +The Transaction screen does not update after file changes, even if you +press \f[CR]g\f[R], until you exit and re\-enter it. +(#2288) +.PP If you press \f[CR]g\f[R] with large files, there could be a noticeable -pause. -.PP -The Transaction screen does not update from file changes until you exit -and re\-endter it (see SCREENS > Transaction above). -.PP -\f[CR]\-\-watch\f[R] is not yet fully robust on all platforms (see Watch -mode above). +pause with the UI unresponsive. .SH AUTHORS diff --git a/hledger-ui/hledger-ui.info b/hledger-ui/hledger-ui.info index ea5a52d1f..6b7f6b374 100644 --- a/hledger-ui/hledger-ui.info +++ b/hledger-ui/hledger-ui.info @@ -18,7 +18,7 @@ plain text accounting app. or 'hledger ui -- [OPTS] [QUERYARGS]' - This manual is for hledger's terminal interface, version 1.42.99. + This manual is for hledger's terminal interface, version 1.43.99. See also the hledger manual for common concepts and file formats. hledger is a robust, user-friendly, cross-platform set of programs @@ -491,22 +491,41 @@ bandwidth for your accounting. Of course you can still interact with hledger-ui when needed, eg to toggle cleared mode, or to explore the history. - There are currently some limitations with '--watch': +* Menu: - It may not work correctly for you, depending on platform or system -configuration. (Eg #836.) +* --watch problems:: - At least on mac, there can be a slow build-up of CPU usage over time, -until the program is restarted (or, suspending and restarting with -'CTRL-z' 'fg' may be enough). + +File: hledger-ui.info, Node: --watch problems, Up: WATCH MODE - It will not detect file changes made by certain editors, such as -Jetbrains IDEs or 'gedit', or on certain less common filesystems. (To -work around, press 'g' to reload manually, or try #1617's -'fs.inotify.max_user_watches' workaround and let us know.) +5.1 -watch problems +=================== - If you are viewing files mounted from another machine, the system -clocks on both machines should be roughly in agreement. +_However._ There are limitations/unresolved bugs with '--watch': + + * It may not work at all for you, depending on platform or system + configuration. On some unix systems, increasing + fs.inotify.max_user_watches or fs.file-max parameters in + /etc/sysctl.conf might help. (#836) + * It may not detect file changes made by certain tools, such as + Jetbrains IDEs or gedit. (#1617) + * It may not detect changes made from outside a virtual machine, ie + by an editor running on the host system. + * It may not detect file changes on certain less common filesystems. + * It may use increasing CPU and RAM over time, especially with large + files. (This is probably not -watch specific, you may be able to + reproduce it by pressing 'g' repeatedly.) (#1825) + + Tips/workarounds: + + * If -watch won't work for you, press 'g' to reload data manually + instead. + * If -watch is leaking resources over time, quit and restart (or + suspend and resume) hledger-ui when you're not using it. + * When running hledger-ui inside a VM, also make file changes inside + the VM. + * When working with files mounted from another machine, make sure the + system clocks on both machines are roughly in agreement.  File: hledger-ui.info, Node: ENVIRONMENT, Next: BUGS, Prev: WATCH MODE, Up: Top @@ -523,22 +542,23 @@ File: hledger-ui.info, Node: BUGS, Prev: ENVIRONMENT, Up: Top 7 BUGS ****** -We welcome bug reports in the hledger issue tracker (shortcut: -https://bugs.hledger.org), or on the hledger chat or mail list +We welcome bug reports in the hledger issue tracker +(https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). Some known issues: '-f-' doesn't work (hledger-ui can't read from stdin). - If you press 'g' with large files, there could be a noticeable pause. - - The Transaction screen does not update from file changes until you -exit and re-endter it (see SCREENS > Transaction above). - - '--watch' is not yet fully robust on all platforms (see Watch mode + '--watch' is not robust, especially with large files (see WATCH MODE above). + The Transaction screen does not update after file changes, even if +you press 'g', until you exit and re-enter it. (#2288) + + If you press 'g' with large files, there could be a noticeable pause +with the UI unresponsive. +  Tag Table: Node: Top221 @@ -555,8 +575,9 @@ Node: Register screen16383 Node: Transaction screen18826 Node: Error screen20401 Node: WATCH MODE20767 -Node: ENVIRONMENT22343 -Node: BUGS22576 +Node: --watch problems21665 +Node: ENVIRONMENT23018 +Node: BUGS23251  End Tag Table diff --git a/hledger-ui/hledger-ui.txt b/hledger-ui/hledger-ui.txt index 0bf4f6dab..70e89e3c4 100644 --- a/hledger-ui/hledger-ui.txt +++ b/hledger-ui/hledger-ui.txt @@ -11,7 +11,7 @@ SYNOPSIS hledger ui -- [OPTS] [QUERYARGS] DESCRIPTION - This manual is for hledger's terminal interface, version 1.42.99. See + This manual is for hledger's terminal interface, version 1.43.99. See also the hledger manual for common concepts and file formats. hledger is a robust, user-friendly, cross-platform set of programs for @@ -394,44 +394,62 @@ WATCH MODE hledger-ui when needed, eg to toggle cleared mode, or to explore the history. - There are currently some limitations with --watch: + --watch problems + However. There are limitations/unresolved bugs with --watch: - It may not work correctly for you, depending on platform or system con- - figuration. (Eg #836.) + o It may not work at all for you, depending on platform or system con- + figuration. On some unix systems, increasing fs.ino- + tify.max_user_watches or fs.file-max parameters in /etc/sysctl.conf + might help. (#836) - At least on mac, there can be a slow build-up of CPU usage over time, - until the program is restarted (or, suspending and restarting with - CTRL-z fg may be enough). + o It may not detect file changes made by certain tools, such as Jet- + brains IDEs or gedit. (#1617) - It will not detect file changes made by certain editors, such as Jet- - brains IDEs or gedit, or on certain less common filesystems. (To work - around, press g to reload manually, or try #1617's fs.ino- - tify.max_user_watches workaround and let us know.) + o It may not detect changes made from outside a virtual machine, ie by + an editor running on the host system. - If you are viewing files mounted from another machine, the system - clocks on both machines should be roughly in agreement. + o It may not detect file changes on certain less common filesystems. + + o It may use increasing CPU and RAM over time, especially with large + files. (This is probably not --watch specific, you may be able to + reproduce it by pressing g repeatedly.) (#1825) + + Tips/workarounds: + + o If --watch won't work for you, press g to reload data manually in- + stead. + + o If --watch is leaking resources over time, quit and restart (or sus- + pend and resume) hledger-ui when you're not using it. + + o When running hledger-ui inside a VM, also make file changes inside + the VM. + + o When working with files mounted from another machine, make sure the + system clocks on both machines are roughly in agreement. ENVIRONMENT - LEDGER_FILE The main journal file to use when not specified with + LEDGER_FILE The main journal file to use when not specified with -f/--file. Default: $HOME/.hledger.journal. BUGS - We welcome bug reports in the hledger issue tracker (shortcut: - https://bugs.hledger.org), or on the hledger chat or mail list + We welcome bug reports in the hledger issue tracker + (https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). Some known issues: -f- doesn't work (hledger-ui can't read from stdin). - If you press g with large files, there could be a noticeable pause. - - The Transaction screen does not update from file changes until you exit - and re-endter it (see SCREENS > Transaction above). - - --watch is not yet fully robust on all platforms (see Watch mode + --watch is not robust, especially with large files (see WATCH MODE above). + The Transaction screen does not update after file changes, even if you + press g, until you exit and re-enter it. (#2288) + + If you press g with large files, there could be a noticeable pause with + the UI unresponsive. + AUTHORS @@ -450,4 +468,4 @@ LICENSE SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-ui-1.42.99 March 2025 HLEDGER-UI(1) +hledger-ui-1.43.99 June 2025 HLEDGER-UI(1) diff --git a/hledger-web/.date.m4 b/hledger-web/.date.m4 index e5d9e9e97..30644042f 100644 --- a/hledger-web/.date.m4 +++ b/hledger-web/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{March 2025}})m4_dnl +m4_define({{_monthyear_}}, {{June 2025}})m4_dnl diff --git a/hledger-web/hledger-web.1 b/hledger-web/hledger-web.1 index 18257968f..f285903e6 100644 --- a/hledger-web/hledger-web.1 +++ b/hledger-web/hledger-web.1 @@ -1,5 +1,5 @@ -.TH "HLEDGER\-WEB" "1" "March 2025" "hledger-web-1.42.99 " "hledger User Manuals" +.TH "HLEDGER\-WEB" "1" "June 2025" "hledger-web-1.43.99 " "hledger User Manuals" @@ -17,7 +17,7 @@ or .PD \f[CR]hledger web \-\- [OPTS] [QUERY]\f[R] .SH DESCRIPTION -This manual is for hledger\[aq]s web interface, version 1.42.99. +This manual is for hledger\[aq]s web interface, version 1.43.99. See also the hledger manual for common concepts and file formats. .PP hledger is a robust, user\-friendly, cross\-platform set of programs for @@ -220,38 +220,33 @@ If this is not working see Install > Shell completions. By default, hledger\-web allows anyone who can reach it to view the journal and to add new transactions, but not to change existing data. .PP -You can restrict who can reach it by +You can restrict who can reach it, by .IP \[bu] 2 setting the IP address it listens on (see \f[CR]\-\-host\f[R] above). -By default it listens on 127.0.0.1, accessible to all users on the local -machine. +By default it listens on 127.0.0.1, accessible to users on the local +machine only. .IP \[bu] 2 -putting it behind an authenticating proxy, using eg apache or nginx +putting it behind an authenticating proxy, such as caddy or apache .IP \[bu] 2 -custom firewall rules +putting it behind a firewall .PP -You can restrict what the users who reach it can do, by +And you can restrict what the users reaching it can do, by specifying +the \f[CR]\-\-allow=ACCESSLEVEL\f[R] option at startup. +ACCESSLEVEL is one of: .IP \[bu] 2 -using the \f[CR]\-\-capabilities=CAP[,CAP..]\f[R] flag when you start -it, enabling one or more of the following capabilities. -The default value is \f[CR]view,add\f[R]: -.RS 2 +\f[CR]view\f[R] \- allows viewing the journal file(s) .IP \[bu] 2 -\f[CR]view\f[R] \- allows viewing the journal file and all included -files +\f[CR]add\f[R] \- also allows adding new transactions to the main +journal file .IP \[bu] 2 -\f[CR]add\f[R] \- allows adding new transactions to the main journal -file +\f[CR]edit\f[R] \- also allows editing, uploading or downloading the +journal file(s) .IP \[bu] 2 -\f[CR]manage\f[R] \- allows editing, uploading or downloading the main -or included files -.RE -.IP \[bu] 2 -using the \f[CR]\-\-capabilities\-header=HTTPHEADER\f[R] flag to specify -a HTTP header from which it will read capabilities to enable. -hledger\-web on Sandstorm uses the X\-Sandstorm\-Permissions header to -integrate with Sandstorm\[aq]s permissions. -This is disabled by default. +\f[CR]sandstorm\f[R] \- (for the hledger\-web Sandstorm app:) allows +whichever of \f[CR]view\f[R], \f[CR]add\f[R], or \f[CR]edit\f[R] are +specified in the \f[CR]X\-Sandstorm\-Permissions\f[R] HTTP header +.PP +The default access level is \f[CR]add\f[R]. .SH EDITING, UPLOADING, DOWNLOADING If you enable the \f[CR]manage\f[R] capability mentioned above, you\[aq]ll see a new \[dq]spanner\[dq] button to the right of the search @@ -500,8 +495,8 @@ stderr, eg: with \f[CR]\-f/\-\-file\f[R]. Default: \f[CR]$HOME/.hledger.journal\f[R]. .SH BUGS -We welcome bug reports in the hledger issue tracker (shortcut: -https://bugs.hledger.org), or on the hledger chat or mail list +We welcome bug reports in the hledger issue tracker +(https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). .PP Some known issues: diff --git a/hledger-web/hledger-web.info b/hledger-web/hledger-web.info index 546e2e90f..63673b92c 100644 --- a/hledger-web/hledger-web.info +++ b/hledger-web/hledger-web.info @@ -18,7 +18,7 @@ plain text accounting app. or 'hledger web -- [OPTS] [QUERY]' - This manual is for hledger's web interface, version 1.42.99. See + This manual is for hledger's web interface, version 1.43.99. See also the hledger manual for common concepts and file formats. hledger is a robust, user-friendly, cross-platform set of programs @@ -229,30 +229,27 @@ File: hledger-web.info, Node: PERMISSIONS, Next: EDITING UPLOADING DOWNLOADING By default, hledger-web allows anyone who can reach it to view the journal and to add new transactions, but not to change existing data. - You can restrict who can reach it by + You can restrict who can reach it, by * setting the IP address it listens on (see '--host' above). By - default it listens on 127.0.0.1, accessible to all users on the - local machine. - * putting it behind an authenticating proxy, using eg apache or nginx - * custom firewall rules + default it listens on 127.0.0.1, accessible to users on the local + machine only. + * putting it behind an authenticating proxy, such as caddy or apache + * putting it behind a firewall - You can restrict what the users who reach it can do, by + And you can restrict what the users reaching it can do, by specifying +the '--allow=ACCESSLEVEL' option at startup. ACCESSLEVEL is one of: - * using the '--capabilities=CAP[,CAP..]' flag when you start it, - enabling one or more of the following capabilities. The default - value is 'view,add': - * 'view' - allows viewing the journal file and all included - files - * 'add' - allows adding new transactions to the main journal - file - * 'manage' - allows editing, uploading or downloading the main - or included files + * 'view' - allows viewing the journal file(s) + * 'add' - also allows adding new transactions to the main journal + file + * 'edit' - also allows editing, uploading or downloading the journal + file(s) + * 'sandstorm' - (for the hledger-web Sandstorm app:) allows whichever + of 'view', 'add', or 'edit' are specified in the + 'X-Sandstorm-Permissions' HTTP header - * using the '--capabilities-header=HTTPHEADER' flag to specify a HTTP - header from which it will read capabilities to enable. hledger-web - on Sandstorm uses the X-Sandstorm-Permissions header to integrate - with Sandstorm's permissions. This is disabled by default. + The default access level is 'add'.  File: hledger-web.info, Node: EDITING UPLOADING DOWNLOADING, Next: RELOADING, Prev: PERMISSIONS, Up: Top @@ -517,8 +514,8 @@ File: hledger-web.info, Node: BUGS, Prev: ENVIRONMENT, Up: Top 8 BUGS ****** -We welcome bug reports in the hledger issue tracker (shortcut: -https://bugs.hledger.org), or on the hledger chat or mail list +We welcome bug reports in the hledger issue tracker +(https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). Some known issues: @@ -530,13 +527,13 @@ Tag Table: Node: Top223 Node: OPTIONS2581 Node: PERMISSIONS11270 -Node: EDITING UPLOADING DOWNLOADING12621 -Node: RELOADING13636 -Node: JSON API14203 -Node: DEBUG OUTPUT19852 -Node: Debug output20004 -Node: ENVIRONMENT20522 -Node: BUGS20758 +Node: EDITING UPLOADING DOWNLOADING12420 +Node: RELOADING13435 +Node: JSON API14002 +Node: DEBUG OUTPUT19651 +Node: Debug output19803 +Node: ENVIRONMENT20321 +Node: BUGS20557  End Tag Table diff --git a/hledger-web/hledger-web.txt b/hledger-web/hledger-web.txt index a839e98b5..dbbb18042 100644 --- a/hledger-web/hledger-web.txt +++ b/hledger-web/hledger-web.txt @@ -11,7 +11,7 @@ SYNOPSIS hledger web -- [OPTS] [QUERY] DESCRIPTION - This manual is for hledger's web interface, version 1.42.99. See also + This manual is for hledger's web interface, version 1.43.99. See also the hledger manual for common concepts and file formats. hledger is a robust, user-friendly, cross-platform set of programs for @@ -201,57 +201,55 @@ PERMISSIONS By default, hledger-web allows anyone who can reach it to view the journal and to add new transactions, but not to change existing data. - You can restrict who can reach it by + You can restrict who can reach it, by o setting the IP address it listens on (see --host above). By default - it listens on 127.0.0.1, accessible to all users on the local ma- - chine. + it listens on 127.0.0.1, accessible to users on the local machine + only. - o putting it behind an authenticating proxy, using eg apache or nginx + o putting it behind an authenticating proxy, such as caddy or apache - o custom firewall rules + o putting it behind a firewall - You can restrict what the users who reach it can do, by + And you can restrict what the users reaching it can do, by specifying + the --allow=ACCESSLEVEL option at startup. ACCESSLEVEL is one of: - o using the --capabilities=CAP[,CAP..] flag when you start it, enabling - one or more of the following capabilities. The default value is - view,add: + o view - allows viewing the journal file(s) - o view - allows viewing the journal file and all included files + o add - also allows adding new transactions to the main journal file - o add - allows adding new transactions to the main journal file + o edit - also allows editing, uploading or downloading the journal + file(s) - o manage - allows editing, uploading or downloading the main or in- - cluded files + o sandstorm - (for the hledger-web Sandstorm app:) allows whichever of + view, add, or edit are specified in the X-Sandstorm-Permissions HTTP + header - o using the --capabilities-header=HTTPHEADER flag to specify a HTTP - header from which it will read capabilities to enable. hledger-web - on Sandstorm uses the X-Sandstorm-Permissions header to integrate - with Sandstorm's permissions. This is disabled by default. + The default access level is add. EDITING, UPLOADING, DOWNLOADING - If you enable the manage capability mentioned above, you'll see a new - "spanner" button to the right of the search form. Clicking this will - let you edit, upload, or download the journal file or any files it in- + If you enable the manage capability mentioned above, you'll see a new + "spanner" button to the right of the search form. Clicking this will + let you edit, upload, or download the journal file or any files it in- cludes. - Note, unlike any other hledger command, in this mode you (or any visi- + Note, unlike any other hledger command, in this mode you (or any visi- tor) can alter or wipe the data files. - Normally whenever a file is changed in this way, hledger-web saves a - numbered backup (assuming file permissions allow it, the disk is not - full, etc.) hledger-web is not aware of version control systems, cur- - rently; if you use one, you'll have to arrange to commit the changes + Normally whenever a file is changed in this way, hledger-web saves a + numbered backup (assuming file permissions allow it, the disk is not + full, etc.) hledger-web is not aware of version control systems, cur- + rently; if you use one, you'll have to arrange to commit the changes yourself (eg with a cron job or a file watcher like entr). - Changes which would leave the journal file(s) unparseable or non-valid - (eg with failing balance assertions) are prevented. (Probably. This + Changes which would leave the journal file(s) unparseable or non-valid + (eg with failing balance assertions) are prevented. (Probably. This needs re-testing.) RELOADING hledger-web detects changes made to the files by other means (eg if you - edit it directly, outside of hledger-web), and it will show the new - data when you reload the page or navigate to a new page. If a change + edit it directly, outside of hledger-web), and it will show the new + data when you reload the page or navigate to a new page. If a change makes a file unparseable, hledger-web will display an error message un- til the file has been fixed. @@ -259,8 +257,8 @@ RELOADING that both machine clocks are roughly in step.) JSON API - In addition to the web UI, hledger-web also serves a JSON API that can - be used to get data or add new transactions. If you want the JSON API + In addition to the web UI, hledger-web also serves a JSON API that can + be used to get data or add new transactions. If you want the JSON API only, you can use the --serve-api flag. Eg: $ hledger-web -f examples/sample.journal --serve-api @@ -277,7 +275,7 @@ JSON API /accounttransactions/ACCOUNTNAME Eg, all account names in the journal (similar to the accounts command). - (hledger-web's JSON does not include newlines, here we use python to + (hledger-web's JSON does not include newlines, here we use python to prettify it): $ curl -s http://127.0.0.1:5000/accountnames | python -m json.tool @@ -318,26 +316,26 @@ JSON API "aprice": null, ... - Most of the JSON corresponds to hledger's data types; for details of - what the fields mean, see the Hledger.Data.Json haddock docs and click - on the various data types, eg Transaction. And for a higher level un- + Most of the JSON corresponds to hledger's data types; for details of + what the fields mean, see the Hledger.Data.Json haddock docs and click + on the various data types, eg Transaction. And for a higher level un- derstanding, see the journal docs. There is also a basic OpenAPI spec- ification. In some cases there is outer JSON corresponding to a "Report" type. To - understand that, go to the Hledger.Web.Handler.MiscR haddock and look - at the source for the appropriate handler to see what it returns. Eg + understand that, go to the Hledger.Web.Handler.MiscR haddock and look + at the source for the appropriate handler to see what it returns. Eg for /accounttransactions it's getAccounttransactionsR, returning a "ac- - countTransactionsReport ...". Looking up the haddock for that we can - see that /accounttransactions returns an AccountTransactionsReport, - which consists of a report title and a list of AccountTransactionsRe- + countTransactionsReport ...". Looking up the haddock for that we can + see that /accounttransactions returns an AccountTransactionsReport, + which consists of a report title and a list of AccountTransactionsRe- portItem (etc). - You can add a new transaction to the journal with a PUT request to - /add, if hledger-web was started with the add capability (enabled by + You can add a new transaction to the journal with a PUT request to + /add, if hledger-web was started with the add capability (enabled by default). The payload must be the full, exact JSON representation of a - hledger transaction (partial data won't do). You can get sample JSON - from hledger-web's /transactions or /accounttransactions, or you can + hledger transaction (partial data won't do). You can get sample JSON + from hledger-web's /transactions or /accounttransactions, or you can export it with hledger-lib, eg like so: .../hledger$ stack ghci hledger-lib @@ -433,28 +431,28 @@ JSON API "tstatus": "Unmarked" } - And here's how to test adding it with curl. This should add a new en- + And here's how to test adding it with curl. This should add a new en- try to your journal: $ curl http://127.0.0.1:5000/add -X PUT -H 'Content-Type: application/json' --data-binary @txn.json DEBUG OUTPUT Debug output - You can add --debug[=N] to the command line to log debug output. N + You can add --debug[=N] to the command line to log debug output. N ranges from 1 (least output, the default) to 9 (maximum output). Typi- - cally you would start with 1 and increase until you are seeing enough. - Debug output goes to stderr, interleaved with the requests logged on + cally you would start with 1 and increase until you are seeing enough. + Debug output goes to stderr, interleaved with the requests logged on stdout. To capture debug output in a log file instead, you can usually redirect stderr, eg: hledger-web --debug=3 2>hledger-web.log. ENVIRONMENT - LEDGER_FILE The main journal file to use when not specified with + LEDGER_FILE The main journal file to use when not specified with -f/--file. Default: $HOME/.hledger.journal. BUGS - We welcome bug reports in the hledger issue tracker (shortcut: - https://bugs.hledger.org), or on the hledger chat or mail list + We welcome bug reports in the hledger issue tracker + (https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). Some known issues: @@ -479,4 +477,4 @@ LICENSE SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-web-1.42.99 March 2025 HLEDGER-WEB(1) +hledger-web-1.43.99 June 2025 HLEDGER-WEB(1) diff --git a/hledger/.date.m4 b/hledger/.date.m4 index e5d9e9e97..30644042f 100644 --- a/hledger/.date.m4 +++ b/hledger/.date.m4 @@ -1,2 +1,2 @@ m4_dnl Date to show in man pages. Updated by "Shake manuals" -m4_define({{_monthyear_}}, {{March 2025}})m4_dnl +m4_define({{_monthyear_}}, {{June 2025}})m4_dnl diff --git a/hledger/hledger.1 b/hledger/hledger.1 index 744c1fba9..2a915ddb4 100644 --- a/hledger/hledger.1 +++ b/hledger/hledger.1 @@ -1,6 +1,6 @@ .\"t -.TH "HLEDGER" "1" "March 2025" "hledger-1.42.99 " "hledger User Manuals" +.TH "HLEDGER" "1" "June 2025" "hledger-1.43.99 " "hledger User Manuals" @@ -33,7 +33,7 @@ hledger is inspired by and largely compatible with ledger(1), and largely interconvertible with beancount(1). .PP This manual is for hledger\[aq]s command line interface, version -1.42.99. +1.43.99. It also describes the common options, file formats and concepts used by all hledger programs. It might accidentally teach you some bookkeeping/accounting as well! @@ -133,26 +133,21 @@ So we usually configure a different journal file, by setting the For more about how to do that on your system, see Common tasks > Setting LEDGER_FILE. .SS Text encoding -hledger input files containing non\-ascii characters must use UTF\-8 -encoding, with the exception of CSV (SSV, TSV..) -files, which can be read from other encodings (see \f[CR]encoding\f[R] -CSV rule). +hledger expects non\-ascii input to be decodable with the system +locale\[aq]s text encoding. +(For CSV/SSV/TSV files, this can be overridden by the +\f[CR]encoding\f[R] CSV rule.) .PP -In UTF\-8 input files, an optional byte order mark (BOM) at the -beginning of the file is allowed. +So, trying to read non\-ascii files which have the wrong text encoding, +or when no system locale is configured, will fail. +To fix this, configure your system locale appropriately, and/or convert +the files to your system\[aq]s text encoding (using \f[CR]iconv\f[R] on +unix, or powershell or notepad on Windows). +See Install: Text encoding for more tips. .PP -Your system may need to be configured with a locale that understands the -input file\[aq]s encoding. -Eg on some unix systems, you may need set the \f[CR]LANG\f[R] -environment variable. -You can read more about this in Unicode characters, below. +hledger\[aq]s output will use the system locale\[aq]s encoding. .PP -On some unix systems you can use the \f[CR]file\f[R] command to show a -file\[aq]s text encoding. -On mac, you\[aq]ll need the version from homebrew: -\f[CR]brew install file\-formula\f[R]. -.PP -hledger\[aq]s text output is always UTF\-8 encoded. +hledger\[aq]s docs and example files mostly use UTF\-8 encoding. .SS Data formats Usually the data file is in hledger\[aq]s journal format, but it can be in any of the supported file formats, which currently are: @@ -192,7 +187,7 @@ T} T{ \f[CR]csv\f[R] T}@T{ -Comma or other character separated values, for data import +Comma\- or other delimiter\-separated values, for data import T}@T{ \f[CR].csv\f[R] T} @@ -295,6 +290,9 @@ hledger provides various subcommands for getting things done. Most of these commands do not change the journal file; they just read it and output a report. A few commands assist with adding data and file management. +Some often\-used commands are \f[CR]add\f[R], \f[CR]print\f[R], +\f[CR]register\f[R], \f[CR]balancesheet\f[R] and +\f[CR]incomestatement\f[R]. .PP To show a summary of commands, run \f[CR]hledger\f[R] with no arguments. You can see the same commands summary at the start of PART 4: COMMANDS @@ -663,18 +661,13 @@ alignment should be preserved. This requires a well\-configured environment. Here are some tips: .IP \[bu] 2 -A system locale must be configured, and it must be one that can decode -the characters being used. -In bash, you can set a locale like this: -\f[CR]export LANG=en_US.UTF\-8\f[R]. -There are some more details in Troubleshooting. -This step is essential \- without it, hledger will quit on encountering -a non\-ascii character (as with all GHC\-compiled programs). +A system locale must be configured, which can decode the characters +being used. +This is essential \- see Text encoding and Install: Text encoding. .IP \[bu] 2 Your terminal software (eg Terminal.app, iTerm, CMD.exe, xterm..) must support unicode. -On Windows, you may need to use Windows Terminal and/or enable UTF\-8 -support. +On Windows, you may need to use Windows Terminal. .IP \[bu] 2 The terminal must be using a font which includes the required unicode glyphs. @@ -874,6 +867,10 @@ used, the right\-most wins. .PP To inspect the processing of config files, use \f[CR]\-\-debug\f[R] or \f[CR]\-\-debug=8\f[R]. +Or, run the \f[CR]setup\f[R] command, which will display any active +config files. +(\f[CR]setup\f[R] is not affected by config files itself, unlike other +commands.) .PP \f[B]Warning!\f[R] .PP @@ -1193,11 +1190,9 @@ If these don\[aq]t work well, you can set your preferred options in the HTML output can be styled by an optional \f[CR]hledger.css\f[R] file in the same directory. .PP -HTML output will be UTF\-8 encoded. -If your web browser is showing junk characters, you may need to change -its text encoding to UTF\-8. -Eg in Safari, see View \-> Text Encoding and Settings \-> Advanced \-> -Default Encoding. +HTML output will be a HTML fragment, not a complete HTML document. +Like other hledger output, for non\-ascii characters it will use the +system locale\[aq]s text encoding (see Text encoding). .SS CSV / TSV output In CSV or TSV output, digit group marks (such as thousands separators) are disabled automatically. @@ -1232,7 +1227,7 @@ use currency codes instead of currency symbols .IP \[bu] 2 use cost notation instead of equity conversion postings .IP \[bu] 2 -avoid virtual postings +avoid virtual postings, balance assignments, and secondary dates. .PP There is one big adjustment you must handle yourself: for Beancount, the top level account names must be \f[CR]Assets\f[R], @@ -1243,10 +1238,10 @@ if needed, as in this hledger2beancount.conf config file. .PP 2024\-12\-20: Some more things not yet handled for you: .IP \[bu] 2 -P directives are not converted automatically \- convert those yourself +P directives are not converted automatically \- convert those yourself. .IP \[bu] 2 -Balance assignments are not converted (Beancount doesnt support them) \- -replace those with explicit amounts +Balance assignments are not converted (Beancount doesn\[aq]t support +them) \- replace those with explicit amounts. .SS Beancount account names Aside from the top\-level names, hledger will adjust your account names to make valid Beancount account names, by capitalising each part, @@ -1556,7 +1551,8 @@ include other.journal ; Include another journal file here. 2024\-02\-01 note some event, or a transaction not yet fully entered, on this date ; Postings are not required. -; Some other date formats are allowed (but, consistent YYYY\-MM\-DD is useful). +# Consistent YYYY\-MM\-DD date format is recommended, +# but you can use . or / and omit leading zeros if you prefer. 2024.01.01 2024/1/1 .EE @@ -2131,26 +2127,29 @@ files, and balance assertions will usually keep working. The exception is when you reorder multiple postings on the same day, to the same account, which have balance assertions; those will likely need updating. -.SS Assertions and multiple included files -Multiple files included with the \f[CR]include\f[R] directive are -processed as if concatenated into one file, preserving their order and -the posting order within each file. -It means that balance assertions in later files will see balance from -earlier files. +.SS Assertions and multiple files +If an account has transactions appearing in multiple files, balance +assertions can still work \- but \f[I]only if those files are part of a +hierarchy made by include directives\f[R]. .PP -And if you have multiple postings to an account on the same day, split -across multiple files, and you want to assert the account\[aq]s balance -on that day, you\[aq]ll need to put the assertion in the right file \- -the last one in the sequence, probably. -.SS Assertions and multiple \-f files -Unlike \f[CR]include\f[R], when multiple files are specified on the -command line with multiple \f[CR]\-f/\-\-file\f[R] options, balance -assertions will not see balance from earlier files. -This can be useful when you do not want problems in earlier files to -disrupt valid assertions in later files. +If the same files are specified with two \f[CR]\-f\f[R] options on the +command line, the assertions in the second will not see the balances +from the first. .PP -If you do want assertions to see balance from earlier files, use -\f[CR]include\f[R], or concatenate the files temporarily. +To work around this, arrange your files in a hierarchy with +\f[CR]include\f[R]. +Or, you could concatenate the files temporarily, and process them like +one big file. +.PP +Why does it work this way ? +It might be related to hledger\[aq]s goal of stable predictable reports. +File hierarchy is considered \[dq]permanent\[dq], part of your data, +while the order of command line options/arguments is not. +We don\[aq]t want transient changes to be able to change the meaning of +the data. +Eg it would be frustrating if tomorrow all your balance assertions broke +because you wrote command line arguments in a different order. +(Discussion welcome.) .SS Assertions and costs Balance assertions ignore costs, and should normally be written without one: @@ -2269,6 +2268,21 @@ always what is shown by reports. Eg a commodity directive may limit the display precision, but this will not affect balance assertions. Balance assertion failure messages show exact amounts. +.SS Assertions and hledger add +Balance assertions can be included in the amounts given in +\f[CR]add\f[R]. +All types of assertions are supported, and assertions can be used as in +a normal journal file. +.PP +All transactions, not just those that have an explicit assertion, are +validated against the existing assertions in the journal. +This means it is possible for an added transaction to fail even if its +assertions are correct as of the transaction date. +.PP +If this assertion checking is not desired, then it can be disabled with +\f[CR]\-I\f[R]. +.PP +However, balance assignments are currently not supported. .SS Posting comments Text following \f[CR];\f[R], at the end of a posting line, and/or on indented lines immediately below it, form comments for that posting. @@ -2805,41 +2819,85 @@ An account directive both declares an account as a valid posting target, and declares its display order; you can\[aq]t easily do one without the other. .SS Account types -hledger knows that accounts come in several types: assets, liabilities, -expenses and so on. -This enables easy reports like balancesheet and incomestatement, and -filtering by account type with the \f[CR]type:\f[R] query. +hledger knows that in accounting there are three main account types: .PP -As a convenience, hledger will detect these account types automatically -if you are using common english\-language top\-level account names -(described below). -But it\[aq]s more robust to declare accounts\[aq] types explicitly, by -adding \f[CR]type:\f[R] tags to their account directives. -The tag\[aq]s value should be one of the five main account types: -.IP \[bu] 2 -\f[CR]A\f[R] or \f[CR]Asset\f[R] (things you own) -.IP \[bu] 2 -\f[CR]L\f[R] or \f[CR]Liability\f[R] (things you owe) -.IP \[bu] 2 -\f[CR]E\f[R] or \f[CR]Equity\f[R] (investment/ownership; balanced -counterpart of assets & liabilities) -.IP \[bu] 2 -\f[CR]R\f[R] or \f[CR]Revenue\f[R] (what you received money from, AKA -income; technically part of Equity) -.IP \[bu] 2 -\f[CR]X\f[R] or \f[CR]Expense\f[R] (what you spend money on; technically -part of Equity) +.TS +tab(@); +l l l. +T{ +\f[CR]Asset\f[R] +T}@T{ +\f[CR]A\f[R] +T}@T{ +things you own +T} +T{ +\f[CR]Liability\f[R] +T}@T{ +\f[CR]L\f[R] +T}@T{ +things you owe +T} +T{ +\f[CR]Equity\f[R] +T}@T{ +\f[CR]E\f[R] +T}@T{ +owner\[aq]s investment, balances the two above +T} +.TE .PP -or, it can be (these are used less often): -.IP \[bu] 2 -\f[CR]C\f[R] or \f[CR]Cash\f[R] (a subtype of Asset, indicating liquid -assets for the cashflow report) -.IP \[bu] 2 -\f[CR]V\f[R] or \f[CR]Conversion\f[R] (a subtype of Equity, for -conversions (see Cost reporting).) +and two more representing changes in these: .PP -Subaccounts inherit their parent\[aq]s type, or they can override it. -Here is a typical set of account type declarations: +.TS +tab(@); +l l l. +T{ +\f[CR]Revenue\f[R] +T}@T{ +\f[CR]R\f[R] +T}@T{ +inflows (also known as \f[CR]Income\f[R]) +T} +T{ +\f[CR]Expense\f[R] +T}@T{ +\f[CR]X\f[R] +T}@T{ +outflows +T} +.TE +.PP +hledger also uses a couple of subtypes: +.PP +.TS +tab(@); +l l l. +T{ +\f[CR]Cash\f[R] +T}@T{ +\f[CR]C\f[R] +T}@T{ +liquid assets +T} +T{ +\f[CR]Conversion\f[R] +T}@T{ +\f[CR]V\f[R] +T}@T{ +commodity conversions equity +T} +.TE +.PP +As a convenience, hledger will detect these types automatically from +english account names. +But it\[aq]s better to declare them explicitly by adding a +\f[CR]type:\f[R] tag in the account directives. +The tag\[aq]s value can be any of the types or one\-letter abbreviations +above. +.PP +Here is a typical set of account type declarations. +Subaccounts will inherit their parent\[aq]s type, or can override it: .IP .EX account assets ; type: A @@ -2854,17 +2912,35 @@ account assets:cash ; type: C account equity:conversion ; type: V .EE .PP -Here are some tips for working with account types. +This enables the easy balancesheet, balancesheetequity, cashflow and +incomestatement reports, and querying by type:. +.PP +Tips: .IP \[bu] 2 -The rules for inferring types from account names are as follows. -These are just a convenience that sometimes help new users get going; if -they don\[aq]t work for you, just ignore them and declare your account -types. -See also Regular expressions. +You can list accounts and their types, for troubleshooting: .RS 2 .IP .EX -If account\[aq]s name contains this (CI) regular expression: | its type is: +$ hledger accounts \-\-types [ACCTPAT] [type:TYPECODES] [\-DEPTH] [\-\-positions] +.EE +.RE +.IP \[bu] 2 +It\[aq]s a good idea to declare at least one account for each account +type. +Having some types declared and some inferred can disrupt certain +reports. +.IP \[bu] 2 +The rules for inferring types from account names are as follows (using +Regular expressions). +.PD 0 +.P +.PD +If they don\[aq]t work for you, just ignore them and declare your types +with \f[CR]type:\f[R] tags. +.RS 2 +.IP +.EX +If account\[aq]s name contains this case insensitive regular expression | its type is \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|\-\-\-\-\-\-\-\-\-\-\-\-\- \[ha]assets?(:.+)?:(cash|bank|che(ck|que?)(ing)?|savings?|current)(:|$) | Cash \[ha]assets?(:|$) | Asset @@ -2876,16 +2952,9 @@ If account\[aq]s name contains this (CI) regular expression: | its ty .EE .RE .IP \[bu] 2 -If you declare any account types, it\[aq]s a good idea to declare an -account for all of the account types, because a mixture of declared and -name\-inferred types can disrupt certain reports. -.IP \[bu] 2 -Certain uses of account aliases can disrupt account types. -See Rewriting accounts > Aliases and account types. -.IP \[bu] 2 As mentioned above, subaccounts will inherit a type from their parent account. -More precisely, an account\[aq]s type is decided by the first of these +To be precise, an account\[aq]s type is decided by the first of these that exists: .RS 2 .IP "1." 3 @@ -2902,13 +2971,7 @@ the nearest parent. Otherwise, it will have no type. .RE .IP \[bu] 2 -For troubleshooting, you can list accounts and their types with: -.RS 2 -.IP -.EX -$ hledger accounts \-\-types [ACCTPAT] [\-DEPTH] [type:TYPECODES] -.EE -.RE +Account aliases can disrupt account types. .SS \f[CR]alias\f[R] directive You can define account alias rules which rewrite your account names, or parts of them, before generating reports. @@ -3999,20 +4062,19 @@ ignores it and rejects the rest. .PP .SH CSV -hledger can read CSV files (Character Separated Value \- usually comma, -semicolon, or tab) containing dated records, automatically converting -each record into a transaction. +hledger can read transactions from CSV (comma\-separated values) files. +More precisely, it can read DSV (delimiter\-separated values), from a +file or standard input. +Comma\-separated, semicolon\-separated and tab\-separated are the most +common variants, and hledger will recognise these three automatically +based on a \f[CR].csv\f[R], \f[CR].ssv\f[R] or \f[CR].tsv\f[R] file name +extension or a \f[CR]csv:\f[R], \f[CR]ssv:\f[R] or \f[CR]tsv:\f[R] file +path prefix. .PP -(To learn about \f[I]writing\f[R] CSV, see CSV output.) -.PP -For best error messages when reading CSV/TSV/SSV files, make sure they -have a corresponding \f[CR].csv\f[R], \f[CR].tsv\f[R] or \f[CR].ssv\f[R] -file extension or use a hledger file prefix (see File Extension below). +(To learn about producing CSV or TSV \f[I]output\f[R], see Output +format.) .PP Each CSV file must be described by a corresponding \f[I]rules file\f[R]. -.PD 0 -.P -.PD This contains rules describing the CSV data (header line, fields layout, date format etc.), how to construct hledger transactions from it, and how to categorise transactions based on description or other attributes. @@ -4049,7 +4111,7 @@ $ hledger print \-f basic.csv income:unknown \-10.23 .EE .PP -There\[aq]s an introductory Importing CSV data tutorial on hledger.org, +There\[aq]s an introductory Tutorial: Import CSV data on hledger.org, and more CSV rules examples below, and a larger collection at https://github.com/simonmichael/hledger/tree/master/examples/csv. .SS CSV rules cheatsheet @@ -4183,20 +4245,35 @@ See also \[dq]Working with CSV > Reading files specified by rule\[dq]. encoding ENCODING .EE .PP -hledger normally expects non\-ascii text to be UTF8\-encoded. +hledger normally expects non\-ascii text to be using the system +locale\[aq]s text encoding. If you need to read CSV files which have some other encoding, you can do it by adding \f[CR]encoding ENCODING\f[R] to your CSV rules. -Eg: \f[CR]encoding ISO88591\f[R]. +Eg: \f[CR]encoding iso\-8859\-1\f[R]. .PP -The following encodings are supported (these names are -case\-insensitive, and can be written with inner spaces or hyphens if -you prefer): ASCII, UTF8, UTF16, UTF32, ISO88591, ISO88592, ISO88593, -ISO88594, ISO88595, ISO88596, ISO88597, ISO88598, ISO88599, ISO885910, -ISO885911, ISO885913, ISO885914, ISO885915, ISO885916, CP1250, CP1251, -CP1252, CP1253, CP1254, CP1255, CP1256, CP1257, CP1258, KOI8R, KOI8U, -GB18030, MacOSRoman, JISX0201, JISX0208, ISO2022JP, ShiftJIS, CP437, -CP737, CP775, CP850, CP852, CP855, CP857, CP860, CP861, CP862, CP863, -CP864, CP865, CP866, CP869, CP874, CP932. +The following encodings are supported: +.PP +\f[CR]ascii\f[R], \f[CR]utf\-8\f[R], \f[CR]utf\-16\f[R], +\f[CR]utf\-32\f[R], \f[CR]iso\-8859\-1\f[R], \f[CR]iso\-8859\-2\f[R], +\f[CR]iso\-8859\-3\f[R], \f[CR]iso\-8859\-4\f[R], +\f[CR]iso\-8859\-5\f[R], \f[CR]iso\-8859\-6\f[R], +\f[CR]iso\-8859\-7\f[R], \f[CR]iso\-8859\-8\f[R], +\f[CR]iso\-8859\-9\f[R], \f[CR]iso\-8859\-10\f[R], +\f[CR]iso\-8859\-11\f[R], \f[CR]iso\-8859\-13\f[R], +\f[CR]iso\-8859\-14\f[R], \f[CR]iso\-8859\-15\f[R], +\f[CR]iso\-8859\-16\f[R], \f[CR]cp1250\f[R], \f[CR]cp1251\f[R], +\f[CR]cp1252\f[R], \f[CR]cp1253\f[R], \f[CR]cp1254\f[R], +\f[CR]cp1255\f[R], \f[CR]cp1256\f[R], \f[CR]cp1257\f[R], +\f[CR]cp1258\f[R], \f[CR]koi8\-r\f[R], \f[CR]koi8\-u\f[R], +\f[CR]gb18030\f[R], \f[CR]macintosh\f[R], \f[CR]jis\-x\-0201\f[R], +\f[CR]jis\-x\-0208\f[R], \f[CR]iso\-2022\-jp\f[R], +\f[CR]shift\-jis\f[R], \f[CR]cp437\f[R], \f[CR]cp737\f[R], +\f[CR]cp775\f[R], \f[CR]cp850\f[R], \f[CR]cp852\f[R], \f[CR]cp855\f[R], +\f[CR]cp857\f[R], \f[CR]cp860\f[R], \f[CR]cp861\f[R], \f[CR]cp862\f[R], +\f[CR]cp863\f[R], \f[CR]cp864\f[R], \f[CR]cp865\f[R], \f[CR]cp866\f[R], +\f[CR]cp869\f[R], \f[CR]cp874\f[R], \f[CR]cp932\f[R]. +.PP +\f[I]Added in 1.42.\f[R] .SS \f[CR]separator\f[R] You can use the \f[CR]separator\f[R] rule to read other kinds of character\-separated data. @@ -5302,49 +5379,68 @@ if something comment C .EE .SS How CSV rules are evaluated -Here\[aq]s how to think of CSV rules being evaluated (if you really need -to). -First, +Here\[aq]s how to think of CSV rules being evaluated. +If you get a confusing error while reading a CSV file, it may help to +try to understand which of these steps is failing: +.IP "1." 3 +Any included rules files are inlined, from top to bottom, depth first +(scanning each included file for further includes, recursively, before +proceeding). +.IP "2." 3 +Top level rules (\f[CR]date\-format\f[R], \f[CR]fields\f[R], +\f[CR]newest\-first\f[R], \f[CR]skip\f[R] etc) are read, top to bottom. +\[dq]Top level rules\[dq] means non\-conditional rules. +If a rule occurs more than once, the last one wins; except for +\f[CR]skip\f[R]/\f[CR]end\f[R] rules, where the first one wins. +.IP "3." 3 +The CSV file is read as text. +Any non\-ascii characters will be decoded using the text encoding +specified by the \f[CR]encoding\f[R] rule, otherwise the system +locale\[aq]s text encoding. +.IP "4." 3 +Any top\-level skip or end rule is applied. +\f[CR]skip [N]\f[R] immediately skips the current or next N CSV records; +\f[CR]end\f[R] immediately skips all remaining CSV records (not normally +used at top level). +.IP "5." 3 +Now any remaining CSV records are processed. +For each CSV record, in file order: +.RS 4 .IP \[bu] 2 -\f[CR]include\f[R] \- all includes are inlined, from top to bottom, -depth first. -(At each include point the file is inlined and scanned for further -includes, recursively, before proceeding.) +Is there a conditional skip/end rule that applies for this record ? +Search the \f[CR]if\f[R] blocks, from top to bottom, for a succeeding +one containing a \f[CR]skip\f[R] or \f[CR]end\f[R] rule. +If found, skip the specified number of CSV records, then continue at 5. +.PD 0 +.P +.PD +Otherwise... +.IP \[bu] 2 +Do some basic validation on this CSV record (eg, check that it has at +least two fields). +.IP \[bu] 2 +For each hledger field (\f[CR]date\f[R], \f[CR]description\f[R], +\f[CR]account1\f[R], etc.): +.RS 2 +.IP "1." 3 +Get the field\[aq]s assigned value, first searching top level +assignments, made directly or by the \f[CR]fields\f[R] rule, then +assignments made inside succeeding \f[CR]if\f[R] blocks. +If there are more than one, the last one wins. +.IP "2." 3 +Compute the field\[aq]s actual value (as text), by interpolating any +%CSVFIELD references within the assigned value; or by choosing a default +value if there was no assignment. +.RE +.IP \[bu] 2 +Generate a hledger transaction from the hledger field values, parsing +them if needed (eg from text to an amount). +.RE .PP -Then \[dq]global\[dq] rules are evaluated, top to bottom. -If a rule is repeated, the last one wins: -.IP \[bu] 2 -\f[CR]skip\f[R] (at top level) -.IP \[bu] 2 -\f[CR]date\-format\f[R] -.IP \[bu] 2 -\f[CR]newest\-first\f[R] -.IP \[bu] 2 -\f[CR]fields\f[R] \- names the CSV fields, optionally sets up initial -assignments to hledger fields -.PP -Then for each CSV record in turn: -.IP \[bu] 2 -test all \f[CR]if\f[R] blocks. -If any of them contain a \f[CR]end\f[R] rule, skip all remaining CSV -records. -Otherwise if any of them contain a \f[CR]skip\f[R] rule, skip that many -CSV records. -If there are multiple matched \f[CR]skip\f[R] rules, the first one wins. -.IP \[bu] 2 -collect all field assignments at top level and in matched \f[CR]if\f[R] -blocks. -When there are multiple assignments for a field, keep only the last one. -.IP \[bu] 2 -compute a value for each hledger field \- either the one that was -assigned to it (and interpolate the %CSVFIELD references), or a default -.IP \[bu] 2 -generate a hledger transaction (journal entry) from these values. -.PP -This is all part of the CSV reader, one of several readers hledger can -use to parse input files. -When all files have been read successfully, the transactions are passed -as input to whichever hledger command the user specified. +This is all done by the CSV reader, one of several readers hledger can +use to read transactions from an input file. +When all input files have been read successfully, their transactions are +passed to whichever hledger command the user specified. .PP .SS Well factored rules Some things than can help reduce duplication and complexity in rules @@ -5672,11 +5768,19 @@ i 2015/03/30 09:00:00 some account optional description after 2 spaces ; option o 2015/03/30 09:20:00 i 2015/03/31 22:21:45 another:account o 2015/04/01 02:00:34 +i 2015/04/02 12:00:00 another:account ; this demonstrates multple sessions being clocked in +i 2015/04/02 13:00:00 some account +o 2015/04/02 14:00:00 +o 2015/04/02 15:00:00 another:account .EE .PP hledger treats each clock\-in/clock\-out pair as a transaction posting some number of hours to an account. -Or if the session spans more than one day, it is split into several +Entries are paired by the account name if the same name is given for a +clock\-in/clock\-out pair. +If no name is given for a clock\-out, then it is paired with the most +recent clock\-in entry. +If the session spans more than one day, it is split into several transactions, one for each day. For the above time log, \f[CR]hledger print\f[R] generates these journal entries: @@ -5691,6 +5795,12 @@ $ hledger \-f t.timeclock print 2015\-04\-01 * 00:00\-02:00 (another:account) 2.01h + +2015\-04\-02 * 12:00\-15:00 ; this demonstrates multiple sessions being clocked in + (another:account) 3.00h + +2015\-04\-02 * 13:00\-14:00 + (some account) 1.00h .EE .PP Here is a sample.timeclock to download and some queries to try: @@ -6454,20 +6564,20 @@ account name, while \f[CR]assets\f[R] matches at level 1. The same would be true with the argument \f[CR]\-\-depth assets=1 \-\-depth savings=2\f[R]. .SH Queries -One of hledger\[aq]s strengths is being able to quickly report on a -precise subset of your data. -Most hledger commands accept query arguments, to restrict their scope. -Multiple query terms can be provided to build up a more complex query. +Many hledger commands accept query arguments, which restrict their scope +and let you report on a precise subset of your data. +Here\[aq]s a quick overview of hledger\[aq]s queries: .IP \[bu] 2 -By default, a query term is interpreted as a case\-insensitive substring -pattern for matching account names: +By default, a query argument is treated as a case\-insensitive substring +pattern for matching account names. +Eg: .RS 2 .PP -\f[CR]car:fuel\f[R] +\f[CR]dining groceries\f[R] .PD 0 .P .PD -\f[CR]dining groceries\f[R] +\f[CR]car:fuel\f[R] .PD 0 .P .PD @@ -6483,9 +6593,9 @@ in single or double quotes: .PD .RE .IP \[bu] 2 -These patterns are actually regular expressions, so you can add regexp -metacharacters for more precision (see \[dq]Regular expressions\[dq] -above for details): +Patterns are actually regular expressions, so you can add regexp +metacharacters for more precision (or you may need to backslash\-escape +certain characters; see \[dq]Regular expressions\[dq] above): .RS 2 .PP \f[CR]\[aq]\[ha]expenses\[rs]b\[aq]\f[R] @@ -6506,8 +6616,8 @@ above for details): .PD .RE .IP \[bu] 2 -To match something other than account name, add one of the query type -prefixes described in \[dq]Query types\[dq] below: +To match something other than the account name, you can add a query type +prefix, such as: .RS 2 .PP \f[CR]date:202312\-\f[R] @@ -6534,9 +6644,14 @@ prefixes described in \[dq]Query types\[dq] below: .PD 0 .P .PD +\f[CR]acct:groceries\f[R] (but \f[CR]acct:\f[R] is the default, so we +usually don\[aq]t bother writing it) +.PD 0 +.P +.PD .RE .IP \[bu] 2 -Add a \f[CR]not:\f[R] prefix to negate a term: +To negate a query, add a \f[CR]not:\f[R] prefix: .RS 2 .PP \f[CR]not:status:\[aq]*\[aq]\f[R] @@ -6553,20 +6668,42 @@ Add a \f[CR]not:\f[R] prefix to negate a term: .PD .RE .IP \[bu] 2 -Terms with different types are AND\-ed, terms with the same type are -OR\-ed (mostly; see \[dq]Combining query terms\[dq] below). -The following query: -.RS 2 +Multiple query terms can be combined, as space\-separated queries Eg: +\f[CR]hledger print date:2022 desc:amazon desc:amzn\f[R] (show +transactions dated in 2022 whose description contains \[dq]amazon\[dq] +or \[dq]amzn\[dq]). +.PD 0 +.P +.PD +.IP \[bu] 2 +Or more flexibly as boolean queries. +Eg: +\f[CR]hledger print expr:\[aq]date:2022 and (desc:amazon or desc:amzn) and not date:202210\[aq]\f[R] +.PD 0 +.P +.PD .PP -\f[CR]date:2022 desc:amazon desc:amzn\f[R] -.PP -is interpreted as: -.PP -\f[I]date is in 2022 AND ( transaction description contains -\[dq]amazon\[dq] OR \[dq]amzn\[dq] )\f[R] -.RE +All hledger commands use the same query language, but different commands +may interpret the query in different ways. +We haven\[aq]t described the commands yet (that\[aq]s coming in PART 4: +COMMANDS below) but here\[aq]s the gist of it: +.IP \[bu] 2 +Transaction\-oriented commands (\f[CR]print\f[R], \f[CR]aregister\f[R], +\f[CR]close\f[R], \f[CR]import\f[R], \f[CR]descriptions\f[R]..) +try to match transactions (including the transaction\[aq]s postings). +.IP \[bu] 2 +Posting\-oriented commands (\f[CR]register\f[R], \f[CR]balance\f[R], +\f[CR]balancesheet\f[R], \f[CR]incomestatement\f[R], +\f[CR]accounts\f[R]..) +try to match postings. +Postings inherit their transaction\[aq]s attributes for querying +purposes, so transaction fields like date or description can still be +referenced in a posting query. +.IP \[bu] 2 +A few commands match in more specific ways. +(Eg \f[CR]aregister\f[R], which has a special first argument.) .SS Query types -Here are the types of query term available. +Here are the query types available: .SS acct: query \f[B]\f[CB]acct:REGEX\f[B]\f[R], or just \f[B]\f[CB]REGEX\f[B]\f[R] .PD 0 @@ -6586,11 +6723,15 @@ the \[dq]acct:\[dq] prefix. Match postings with a single\-commodity amount equal to, less than, or greater than N. (Postings with multi\-commodity amounts are not tested and will always match.) +\f[CR]amt:\f[R] needs quotes to hide the less than/greater than sign +from the command line shell. +.PP The comparison has two modes: if N is preceded by a + or \- sign (or is 0), the two signed numbers are compared. Otherwise, the absolute magnitudes are compared, ignoring sign. -\f[CR]amt:\f[R] needs quotes to hide the less than/greater than sign -from the command line shell. +.PP +Keep in mind that \f[CR]amt:\f[R] matches posting amounts, not account +balances. .SS code: query \f[B]\f[CB]code:REGEX\f[B]\f[R] .PD 0 @@ -6649,38 +6790,6 @@ Match (or display, depending on command) accounts at or above this depth, optionally only for accounts matching a provided regular expression. See Depth for detailed rules. -.SS expr: query -\f[B]\f[CB]expr:\[aq]QUERYEXPR\[aq]\f[B]\f[R] -.PD 0 -.P -.PD -\f[CR]expr\f[R] lets you write more complicated query expressions with -AND, OR, NOT, and parentheses. -.PD 0 -.P -.PD -Eg: \f[CR]expr:\[aq]date:lastmonth and not (food or rent)\[aq]\f[R] -.PD 0 -.P -.PD -The expression should be enclosed in quotes. -See Combining query terms below. -.SS not: query -\f[B]\f[CB]not:QUERYTERM\f[B]\f[R] -.PD 0 -.P -.PD -You can prepend \f[B]\f[CB]not:\f[B]\f[R] to any other query term to -negate the match. -.PD 0 -.P -.PD -Eg: \f[CR]not:equity\f[R], \f[CR]not:desc:apple\f[R] -.PD 0 -.P -.PD -(Also, a trick: \f[CR]not:not:...\f[R] can sometimes solve query -problems conveniently..) .SS note: query \f[B]\f[CB]note:REGEX\f[B]\f[R] .PD 0 @@ -6742,7 +6851,24 @@ Accounts also inherit the tags of their parent accounts. Postings also inherit the tags of their account and their transaction . .IP \[bu] 2 Transactions also acquire the tags of their postings. -.SS Combining query terms +.SS Negative queries +.SS not: query +\f[B]\f[CB]not:QUERY\f[B]\f[R] +.PD 0 +.P +.PD +You can prepend \f[B]\f[CB]not:\f[B]\f[R] to a query to negate the +match. +.PD 0 +.P +.PD +Eg: \f[CR]not:equity\f[R], \f[CR]not:desc:apple\f[R] +.PD 0 +.P +.PD +(Also, a trick: \f[CR]not:not:...\f[R] can sometimes solve query +problems conveniently.) +.SS Space\-separated queries When given multiple space\-separated query terms, most commands select things which match: .IP \[bu] 2 @@ -6763,48 +6889,94 @@ have any postings matching any of the positive account terms AND have no postings matching any of the negative account terms AND .IP \[bu] 2 match all the other terms. +.SS Boolean queries +You can write more complicated \[dq]boolean\[dq] query expressions, +enclosed in quotes and prefixed with \f[CR]expr:\f[R]. +These can combine subqueries with NOT, AND, OR operators (case +insensitive), and parentheses for grouping. +Eg, to show transactions involving both cash and expense accounts: +.IP +.EX +hledger print expr:\[aq]cash AND expenses\[aq] +.EE .PP -We also support more complex boolean queries with the \f[CR]expr:\f[R] -prefix. -This allows one to combine query terms using \f[CR]and\f[R], -\f[CR]or\f[R], \f[CR]not\f[R] keywords (case insensitive), and to group -them by enclosing in parentheses. +The prefix and enclosing quotes are required, so don\[aq]t write +\f[CR]hledger print cash AND expenses\f[R]. +That would be a space\-separated query showing transactions involving +accounts with any of \[dq]cash\[dq], \[dq]and\[dq], \[dq]expenses\[dq] +in their names. .PP -Some examples: -.IP \[bu] 2 -Exclude account names containing \[aq]food\[aq]: -.RS 2 +You can write space\-separated queries \f[I]inside\f[R] a boolean query, +and they will combine as described above, but it might be confusing and +best avoided. +Eg these are equivalent, showing transactions involving cash or expenses +accounts: +.IP +.EX +hledger print expr:\[aq]cash expenses\[aq] +hledger print cash expenses +.EE .PP -\f[CR]expr:\[dq]not food\[dq]\f[R] (\f[CR]not:food\f[R] is equivalent) -.RE -.IP \[bu] 2 -Match things which have \[aq]cool\[aq] in the description and the -\[aq]A\[aq] tag: -.RS 2 +There is a restriction with \f[CR]date:\f[R] queries: they may not be +used inside OR expressions. .PP -\f[CR]expr:\[dq]desc:cool and tag:A\[dq]\f[R] -(\f[CR]expr:\[dq]desc:cool tag:A\[dq]\f[R] is equivalent) -.RE -.IP \[bu] 2 -Match things which either do not reference the \[aq]expenses:food\[aq] -account, or do have the \[aq]A\[aq] tag: -.RS 2 +Actually, there are three types of boolean query: \f[CR]expr:\f[R] for +general use, and \f[CR]any:\f[R] and \f[CR]all:\f[R] variants which can +be useful with \f[CR]print\f[R]. +.SS expr: query +\f[B]\f[CB]expr:\[aq]QUERYEXPR\[aq]\f[B]\f[R] +.PD 0 +.P +.PD +For example, +\f[CR]expr:\[aq]date:lastmonth AND NOT (food OR rent)\[aq]\f[R] means +\[dq]match things which are dated in the last month and do not have food +or rent in the account name\[dq]. .PP -\f[CR]expr:\[dq]not expenses:food or tag:A\[dq]\f[R] -.RE -.IP \[bu] 2 -Match things which either do not reference the \[aq]expenses:food\[aq] -account, or which reference the \[aq]expenses:drink\[aq] account and -also have the \[aq]A\[aq] tag: -.RS 2 -.PP -\f[CR]expr:\[dq]expenses:food or (expenses:drink and tag:A)\[dq]\f[R] -.RE -.PP -\f[CR]expr:\f[R] has a restriction: \f[CR]date:\f[R] queries may not be -used inside \f[CR]or\f[R] expressions. -That would allow disjoint report periods or disjoint result sets, with -unclear semantics for our reports. +When using \f[CR]expr:\f[R] with transaction\-oriented commands like +\f[CR]print\f[R], posting\-oriented query terms like \f[CR]acct:\f[R] +and \f[CR]amt:\f[R] are considered to match the transaction if they +match any of its postings. +.PD 0 +.P +.PD +So, \f[CR]hledger print expr:\[aq]cash and amt:>0\[aq]\f[R] means +\[dq]show transactions with (at least one posting involving a cash +account) and (at least one posting with a positive amount)\[dq]. +.SS any: query +\f[B]\f[CB]any:\[aq]QUERYEXPR\[aq]\f[B]\f[R] +.PD 0 +.P +.PD +Like \f[CR]expr:\f[R], but when used with transaction\-oriented commands +like \f[CR]print\f[R], it matches the transaction only if a posting can +be matched by all of QUERYEXPR. +.PD 0 +.P +.PD +So, \f[CR]hledger print any:\[aq]cash and amt:>0\[aq]\f[R] means +\[dq]show transactions where at least one posting posts a positive +amount to a cash account\[dq]. +.SS all: query +\f[B]\f[CB]all:\[aq]QUERYEXPR\[aq]\f[B]\f[R] +.PD 0 +.P +.PD +Like \f[CR]expr:\f[R], but when used with transaction\-oriented commands +like \f[CR]print\f[R], it matches the transaction only if all postings +are matched by all of QUERYEXPR. +.PD 0 +.P +.PD +So, \f[CR]hledger print all:\[aq]cash and amt:0\[aq]\f[R] means +\[dq]show transactions where all postings involve a cash account and +have a zero amount\[dq]. +.PD 0 +.P +.PD +Or, \f[CR]hledger print all:\[aq]cash or checking\[aq]\f[R] means +\[dq]show transactions which touch only cash and/or checking +accounts\[dq]. .SS Queries and command options Some queries can also be expressed as command\-line options: \f[CR]depth:2\f[R] is equivalent to \f[CR]\-\-depth 2\f[R], @@ -7250,7 +7422,7 @@ This is produced by reports that show full journal entries: \f[CR]rewrite\f[R] etc. .IP \[bu] 2 It shows amounts with their original journal precisions, which may not -be consistent. +be consistent from one amount to the next. .IP \[bu] 2 It adds a trailing decimal mark when needed to avoid showing ambiguous amounts. @@ -8273,12 +8445,18 @@ If you have installed more add\-on commands, they also will be listed. .PP \f[B]Help commands\f[R] .IP \[bu] 2 -help \- show the hledger manual with info/man/pager +commands \- show the hledger commands list (default) .IP \[bu] 2 demo \- show small hledger demos in the terminal +.IP \[bu] 2 +help \- show the hledger manual with info, man, or pager .PP \f[B]User interface commands\f[R] .IP \[bu] 2 +repl \- run commands from an interactive prompt +.IP \[bu] 2 +run \- run commands from a script +.IP \[bu] 2 ui \- (if installed) run hledger\[aq]s terminal UI .IP \[bu] 2 web \- (if installed) run hledger\[aq]s web UI @@ -8349,6 +8527,8 @@ check \- check for various kinds of error in the data .IP \[bu] 2 diff \- compare account transactions in two journal files .IP \[bu] 2 +setup \- check and show the status of the hledger installation +.IP \[bu] 2 test \- run self tests .PP Next, these commands are described in detail. @@ -9324,6 +9504,7 @@ Flags: txt, beancount, csv, tsv, html, fods, json, sql. \-o \-\-output\-file=FILE write output to FILE. A file extension matching one of the above formats selects that format. + \-\-location add file/line number tags to print output. .EE .PP The print command displays full journal entries (transactions) from the @@ -9442,6 +9623,9 @@ recent transaction whose description is most similar to DESC. DESC should contain at least two characters. If there is no similar\-enough match, no transaction will be shown and the program exit code will be non\-zero. +.PP +With \f[CR]\-\-location\f[R], print adds the source file and line number +to every transaction, as a tag. .SS print output format This command also supports the output destination and output format options The output formats supported are \f[CR]txt\f[R], @@ -10325,15 +10509,16 @@ changes and more, during one time period or many. Generally it shows a table, with rows representing accounts, and columns representing periods. .PP -Note there are some higher\-level variants of the \f[CR]balance\f[R] -command with convenient defaults, which can be simpler to use: -\f[CR]balancesheet\f[R], \f[CR]balancesheetequity\f[R], -\f[CR]cashflow\f[R] and \f[CR]incomestatement\f[R]. +Note there are some variants of the \f[CR]balance\f[R] command with +convenient defaults, which are simpler to use: \f[CR]balancesheet\f[R], +\f[CR]balancesheetequity\f[R], \f[CR]cashflow\f[R] and +\f[CR]incomestatement\f[R]. When you need more control, then use \f[CR]balance\f[R]. .SS balance features Here\[aq]s a quick overview of the \f[CR]balance\f[R] command\[aq]s features, followed by more detailed descriptions and examples. -Many of these work with the higher\-level commands as well. +Many of these work with the other balance\-like commands as well +(\f[CR]bs\f[R], \f[CR]cf\f[R], \f[CR]is\f[R]..). .PP \f[CR]balance\f[R] can show.. .IP \[bu] 2 @@ -10639,9 +10824,9 @@ Revenues and liability balances are typically negative, however, so \f[CR]\-S\f[R] shows these in reverse order. To work around this, you can add \f[CR]\-\-invert\f[R] to flip the signs. -(Or, use one of the higher\-level reports, which flip the sign -automatically. -Eg: \f[CR]hledger incomestatement \-MAS\f[R]). +Or you could use one of the higher\-level balance reports +(\f[CR]bs\f[R], \f[CR]is\f[R]..), which flip the sign automatically (eg: +\f[CR]hledger is \-MAS\f[R]). .PP .SS Percentages With \f[CR]\-%/\-\-percent\f[R], balance reports show each account\[aq]s @@ -10778,7 +10963,7 @@ specifying a report start date, or by using the \f[CR]\-H/\-\-historical\f[R] flag. (\f[CR]\-H\f[R] causes report start date to be ignored when summing postings.) -.SS Balance report types +.SS Balance report modes The balance command is quite flexible; here is the full detail on how to control what it reports. If the following seems complicated, don\[aq]t worry \- this is for @@ -10787,8 +10972,8 @@ familiar with all the report modes. .PP There are three important option groups: .PP -\f[CR]hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] ...\f[R] -.SS Calculation type +\f[CR]hledger balance [CALCULATIONMODE] [ACCUMULATIONMODE] [VALUATIONMODE] ...\f[R] +.SS Calculation mode The basic calculation to perform for each table cell. It is one of: .IP \[bu] 2 @@ -10805,7 +10990,7 @@ fluctuations) current valued balance minus each amount\[aq]s original cost) .IP \[bu] 2 \f[CR]\-\-count\f[R] : show the count of postings -.SS Accumulation type +.SS Accumulation mode How amounts should accumulate across a report\[aq]s subperiods/columns. Another way to say it: which time period\[aq]s postings should contribute to each cell\[aq]s calculation. @@ -10828,13 +11013,14 @@ until this column\[aq]s end\[dq]. Typically used to see historical end balances of assets/liabilities/equity. (\f[B]default for balancesheet, balancesheetequity\f[R]) -.SS Valuation type +.SS Valuation mode Which kind of value or cost conversion should be applied, if any, before displaying the report. -It is one of: +See Cost reporting and Value reporting for more about conversions. +.PP +A valuation (or cost) mode can be selected with the \-\-value option: .IP \[bu] 2 -no valuation type : don\[aq]t convert to cost or value -(\f[B]default\f[R]) +no conversion : don\[aq]t convert to cost or value (\f[B]default\f[R]) .IP \[bu] 2 \f[CR]\-\-value=cost[,COMM]\f[R] : convert amounts to cost (then optionally to some other commodity) @@ -10855,19 +11041,22 @@ today\[aq]s date \f[CR]\-\-value=YYYY\-MM\-DD[,COMM]\f[R] : convert amounts to market value on another date .PP -or one of the equivalent simpler flags: +or with the legacy \-B/\-V/\-X options, which are equivalent and easier +to type: .IP \[bu] 2 -\f[CR]\-B/\-\-cost\f[R] : like \-\-value=cost (though, note \-\-cost and -\-\-value are independent options which can both be used at once) +\f[CR]\-B\f[R]/\f[CR]\-\-cost\f[R] : like \-\-value=cost .IP \[bu] 2 -\f[CR]\-V/\-\-market\f[R] : like \-\-value=end +\f[CR]\-V\f[R]/\f[CR]\-\-market\f[R] : like \-\-value=end .IP \[bu] 2 -\f[CR]\-X COMM/\-\-exchange COMM\f[R] : like \-\-value=end,COMM +\f[CR]\-X COMM\f[R]/\f[CR]\-\-exchange COMM\f[R] : like +\-\-value=end,COMM .PP -See Cost reporting and Value reporting for more about these. -.SS Combining balance report types -Most combinations of these options should produce reasonable reports, -but if you find any that seem wrong or misleading, let us know. +Note that \-\-value can also convert to cost, as a convenience; but +actually \-\-cost and \-\-value are independent options, and could be +used together. +.SS Combining balance report modes +Most combinations of these modes should produce reasonable reports, but +if you find any that seem wrong or misleading, let us know. The following restrictions are applied: .IP \[bu] 2 \f[CR]\-\-valuechange\f[R] implies \f[CR]\-\-value=end\f[R] @@ -10932,8 +11121,8 @@ DATE\-value of change from journal start to period end T} .TE .SS Budget report -The \f[CR]\-\-budget\f[R] report type is like a regular balance report, -but with two main differences: +The \f[CR]\-\-budget\f[R] report is like a regular balance report, but +with two main differences: .IP \[bu] 2 Budget goals and performance percentages are also shown, in brackets .IP \[bu] 2 @@ -11356,9 +11545,9 @@ $ hledger \-f examples/bcexample.hledger bal assets:us:etrade \-3 \-Y \-O csv \- .EE .SS Balance report output As noted in Output format, if you choose HTML output (by using -\f[CR]\-O html\f[R] or \f[CR]\-o somefile.html\f[R]), it will use the -UTF\-8 text encoding, And you can create a \f[CR]hledger.css\f[R] file -in the same directory to customise the report\[aq]s appearance. +\f[CR]\-O html\f[R] or \f[CR]\-o somefile.html\f[R]), you can create a +\f[CR]hledger.css\f[R] file in the same directory to customise the +report\[aq]s appearance. .PP The HTML and FODS output formats can generate hyperlinks to a \f[CR]hledger\-web\f[R] register view for each account and period. @@ -12118,74 +12307,73 @@ commands: syntax errors and no invalid include directives. This ensures that all files exist and are readable. .IP \[bu] 2 -\f[B]autobalanced\f[R] \- all transactions are balanced, after inferring -missing amounts and conversion costs where possible, and then converting -to cost. -This ensures that each individual transaction is well formed. +\f[B]autobalanced\f[R] \- all transactions are balanced, after +automatically inferring missing amounts and conversion rates and then +converting amounts to cost. +This ensures that each transaction\[aq]s entry is well formed. .IP \[bu] 2 \f[B]assertions\f[R] \- all balance assertions in the journal are passing. -Balance assertions are like canaries in your journal, they catch many -problems. -They can get in the way sometimes; you can disable them temporarily with -\f[CR]\-I\f[R]/\f[CR]\-\-ignore\-assertions\f[R] (unless overridden with -\f[CR]\-s\f[R]/\f[CR]\-\-strict\f[R] or -\f[CR]hledger check assertions\f[R]). +Balance assertions are a strong defense against errors; they help catch +many problems. +If this check gets in your way, you can disable it with +\f[CR]\-I\f[R]/\f[CR]\-\-ignore\-assertions\f[R]. +Or you can add that to your config file to disable it by default (and +then use \f[CR]\-s\f[R]/\f[CR]\-\-strict\f[R] or +\f[CR]hledger check assertions\f[R] to enable it). .SS Strict checks -These additional checks are performed by any command when the +These additional checks are performed by all commands when the \f[CR]\-s\f[R]/\f[CR]\-\-strict\f[R] flag is used (strict mode). -Strict mode always enables the balance assertions check, also. -These provide extra error\-catching power when you are serious about -keeping your data clean and free of typos: +They provide extra error\-catching power to keep your data clean and +correct. +Strict mode also always enables the \f[CR]assertions\f[R] check. .IP \[bu] 2 -\f[B]balanced\f[R] \- like \f[CR]autobalanced\f[R], but in conversion -transactions, costs must be written explicitly. -This ensures some redundancy in the entry, which helps prevent typos. +\f[B]balanced\f[R] \- like \f[CR]autobalanced\f[R], but all conversions +between commodities must use explicit cost notation or equity postings. +This prevents wrong conversions caused by typos. .IP \[bu] 2 \f[B]commodities\f[R] \- all commodity symbols used must be declared. This guards against mistyping or omitting commodity symbols. +Declaring commodities also sets their precision for display and +transaction balancing. .IP \[bu] 2 \f[B]accounts\f[R] \- all account names used must be declared. This prevents the use of mis\-spelled or outdated account names. .SS Other checks -These other checks are not wanted by everyone, but can be run using the +These are not wanted by everyone, but can be run using the \f[CR]check\f[R] command: .IP \[bu] 2 -\f[B]ordereddates\f[R] \- within each file, transactions are ordered by -date. -This is a simple and effective error catcher, and you should use it. -Alas! -not everyone wants it. -If you do, use \f[CR]hledger check \-s ordereddates\f[R]. -When enabled, this check is performed early, before balance assertions -(because copy\-pasted dates are often the root cause of balance -assertion failures). +\f[B]tags\f[R] \- all tags used must be declared. +This prevents mis\-spelled tag names. +Note hledger fairly often finds unintended tags in comments. .IP \[bu] 2 -\f[B]payees\f[R] \- all payees used by transactions must be declared. -This will force you to always use known/declared payee names. -For most people this is a bit too restrictive. +\f[B]payees\f[R] \- all payees used in transactions must be declared. +This will force you to declare any new payee name before using it. +Most people will probably find this a bit too strict. .IP \[bu] 2 -\f[B]tags\f[R] \- all tags used by transactions must be declared. -This prevents mistyped tag names. +\f[B]ordereddates\f[R] \- within each file, transactions must be ordered +by date. +This is a simple and effective error catcher. +It\[aq]s not included in strict mode, but you can add it by running +\f[CR]hledger check \-s ordereddates\f[R]. +If enabled, this check is performed before balance assertions. .IP \[bu] 2 \f[B]recentassertions\f[R] \- all accounts with balance assertions must -have a balance assertion within the last 7 days before their latest -posting. -This encourages you to add balance assertions fairly regularly for your -active asset/liability accounts, which in turn should encourage you to -check and reconcile with their real world balances fairly regularly. -\f[CR]close \-\-assert\f[R] can be helpful. -(The older balance assertions become redundant; you can remove them -periodically, or leave them in place, perhaps commented, as -documentation.) +have one that\[aq]s within the 7 days before their latest posting. +This will encourage adding balance assertions for your active +asset/liability accounts, which in turn should encourage you to +reconcile regularly with those real world balances \- another strong +defense against errors. +\f[CR]hledger close \-\-assert\f[R] can help generate assertion entries. +Over time the older assertions become somewhat redundant, and you can +remove them if you like (they don\[aq]t affect performance much, but +they add some noise to the journal). .IP \[bu] 2 -\f[B]uniqueleafnames\f[R] \- no two accounts may have the same leaf -name. -The leaf name is the last colon\-separated part of an account name, eg -\f[CR]checking\f[R] in \f[CR]assets:bank:checking\f[R]. -This encourages you to keep those unique, effectively giving each -account a short name which is easier to remember and to type in -reporting commands. +\f[B]uniqueleafnames\f[R] \- no two accounts may have the same last +account name part (eg the \f[CR]checking\f[R] in +\f[CR]assets:bank:checking\f[R]). +This ensures each account can be matched by a unique short name, easier +to remember and to type. .SS Custom checks You can build your own custom checks with add\-on command scripts. See also Cookbook > Scripting. @@ -12233,6 +12421,73 @@ These transactions are in the first file only: These transactions are in the second file only: .EE +.SS setup +Check the status of the hledger installation. +.IP +.EX +Flags: +no command\-specific flags +.EE +.PP +\f[CR]setup\f[R] tests your hledger installation and prints a list of +results, sometimes with helpful hints. +This is a good first command to run after installing hledger. +Also after upgrading, or when something\[aq]s not working, or just when +you want a reminder of where things are. +.PP +It makes one network request to detect the latest hledger release +version. +It\[aq]s ok if this fails or times out. +It will use ANSI color by default, unless disabled by NO_COLOR or +\-\-color=n. +It does not use a pager or a config file. +.PP +It expects that the hledger version you are running is installed in your +PATH. +If not, it will stop until you have done that (to keep things simple). +.PP +Example: +.IP +.EX +$ hledger setup +Checking your hledger setup.. +Legend: good, neutral, unknown, warning + +hledger +* is a released version ? no hledger 1.42.99\-gbca4b39c5\-20250425, mac\-aarch64 +* is up to date ? yes 1.42.99 installed, latest is 1.42.1 +* is a native binary for this machine ? yes aarch64 +* is installed in PATH ? yes /Users/simon/.local/bin/hledger +* has a system text encoding configured ? yes UTF\-8, data files should use this encoding +* has a user config file ? (optional) no +* current directory has a local config ? yes /Users/simon/src/hledger/hledger.conf +* the config file is readable ? yes /Users/simon/src/hledger/hledger.conf + +terminal +* the NO_COLOR variable is defined ? no +* \-\-color is configured by config file ? no +* hledger will use color by default ? yes +* the PAGER variable is defined ? yes less +* \-\-pager is configured by config file ? no +* hledger will use a pager when needed ? yes /opt/homebrew/bin/less +* the LESS variable is defined ? yes +* the HLEDGER_LESS variable is defined ? no +* adjusting LESS variable for color etc. ? yes +* \-\-pretty is enabled by config file ? no tables will use ASCII characters +* bash shell completions are installed ? ? +* zsh shell completions are installed ? ? + +journal +* the LEDGER_FILE variable is defined ? yes /Users/simon/finance/2025/2025.journal +* a default journal file is readable ? yes /Users/simon/finance/2025/2025.journal +* it includes additional files ? yes 15 +* all commodities are declared ? yes 10 +* all accounts are declared ? yes 160 +* all accounts have types ? no 14 untyped +* accounts of each type were detected ? yes ALERXCV +* commodities/accounts are checked ? no use \-s to check commodities/accounts +* balance assertions are checked ? yes use \-I to ignore assertions +.EE .SS test Run built\-in unit tests. .IP @@ -12250,18 +12505,18 @@ sanity\-check the installed hledger executable on your platform. All tests are expected to pass \- if you ever see a failure, please report as a bug! .PP -This command also accepts tasty test runner options, written after a -\-\- (double hyphen). -Eg to run only the tests in Hledger.Data.Amount, with ANSI colour codes -disabled: +Any arguments before a \f[CR]\-\-\f[R] argument will be passed to the +\f[CR]tasty\f[R] test runner as test\-selecting \-p patterns, and any +arguments after \f[CR]\-\-\f[R] will be passed to tasty unchanged. +.PP +Examples: .IP .EX -$ hledger test \-\- \-pData.Amount \-\-color=never +$ hledger test # run all unit tests +$ hledger test balance # run tests with \[dq]balance\[dq] in their name +$ hledger test \-\- \-h # show tasty\[aq]s options .EE .PP -For help on these, see https://github.com/feuerbach/tasty#options -(\f[CR]\-\- \-\-help\f[R] currently doesn\[aq]t show them). -.PP .SH PART 5: COMMON TASKS Here are some quick examples of how to do some basic tasks with hledger. .SH Getting help @@ -12724,8 +12979,8 @@ See the close command. If using version control, don\[aq]t forget to \f[CR]git add\f[R] the new file. .SH BUGS -We welcome bug reports in the hledger issue tracker (shortcut: -https://bugs.hledger.org), or on the hledger chat or mail list +We welcome bug reports in the hledger issue tracker +(https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). .PP Some known issues and limitations: @@ -12734,9 +12989,9 @@ The need to precede add\-on command options with \f[CR]\-\-\f[R] when invoked from hledger is awkward. (See Command options, Constructing command lines.) .PP -A UTF\-8\-aware system locale must be configured to work with non\-ascii -data. -(See Unicode characters, Troubleshooting.) +A system locale with a suitable text encoding must be configured to work +with non\-ascii data. +(See Text encoding, Troubleshooting.) .PP On Microsoft Windows, depending whether you are running in a CMD window or a Cygwin/MSYS/Mintty window and how you installed hledger, non\-ascii @@ -12780,42 +13035,16 @@ On Windows, \f[CR]$env:LEDGER_FILE\f[R] should show it. You may need to force your shell to see the new configuration. A simple way is to close your terminal window and open a new one. .PP -\f[B]LANG issues: I get errors like \[dq]Illegal byte sequence\[dq] or -\[dq]Invalid or incomplete multibyte or wide character\[dq] or -\[dq]commitAndReleaseBuffer: invalid argument (invalid +\f[B]Text decoding issues: I get errors like \[dq]Illegal byte +sequence\[dq] or \[dq]Invalid or incomplete multibyte or wide +character\[dq] or \[dq]commitAndReleaseBuffer: invalid argument (invalid character)\[dq]\f[R] .PD 0 .P .PD -Programs compiled with GHC (hledger, haskell build tools, etc.) -need the system locale to be UTF\-8\-aware, or they will fail when they -encounter non\-ascii characters. -To fix it, set the LANG environment variable to a locale which supports -UTF\-8 and which is installed on your system. -.PP -On unix, \f[CR]locale \-a\f[R] lists the installed locales. -Look for one which mentions \f[CR]utf8\f[R], \f[CR]UTF\-8\f[R] or -similar. -Some examples: \f[CR]C.UTF\-8\f[R], \f[CR]en_US.utf\-8\f[R], -\f[CR]fr_FR.utf8\f[R]. -If necessary, use your system package manager to install one. -Then select it by setting the \f[CR]LANG\f[R] environment variable. -Note, exact spelling and capitalisation of the locale name may be -important: Here\[aq]s one common way to configure this permanently for -your shell: -.IP -.EX -$ echo \[dq]export LANG=en_US.utf8\[dq] >>\[ti]/.profile -# close and re\-open terminal window -.EE -.PP -If you are using Nix (not NixOS) for GHC and Hledger, you might need to -set the \f[CR]LOCALE_ARCHIVE\f[R] variable: -.IP -.EX -$ echo \[dq]export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale\-archive\[dq] >>\[ti]/.profile -# close and re\-open terminal window -.EE +hledger usually needs its input to be decodable with the system +locale\[aq]s text encoding. +See Text encoding and Install: Text encoding. .PP \f[B]COMPATIBILITY ISSUES: hledger gives an error with my Ledger file\f[R] diff --git a/hledger/hledger.info b/hledger/hledger.info index f4d3bd011..52b8be076 100644 --- a/hledger/hledger.info +++ b/hledger/hledger.info @@ -26,7 +26,7 @@ accounting and a simple, editable file format. hledger is inspired by and largely compatible with ledger(1), and largely interconvertible with beancount(1). - This manual is for hledger's command line interface, version 1.42.99. + This manual is for hledger's command line interface, version 1.43.99. It also describes the common options, file formats and concepts used by all hledger programs. It might accidentally teach you some bookkeeping/accounting as well! You don't need to know everything in @@ -177,23 +177,20 @@ File: hledger.info, Node: Text encoding, Next: Data formats, Up: Input 2.1 Text encoding ================= -hledger input files containing non-ascii characters must use UTF-8 -encoding, with the exception of CSV (SSV, TSV..) files, which can be -read from other encodings (see 'encoding' CSV rule). +hledger expects non-ascii input to be decodable with the system locale's +text encoding. (For CSV/SSV/TSV files, this can be overridden by the +'encoding' CSV rule.) - In UTF-8 input files, an optional byte order mark (BOM) at the -beginning of the file is allowed. + So, trying to read non-ascii files which have the wrong text +encoding, or when no system locale is configured, will fail. To fix +this, configure your system locale appropriately, and/or convert the +files to your system's text encoding (using 'iconv' on unix, or +powershell or notepad on Windows). See Install: Text encoding for more +tips. - Your system may need to be configured with a locale that understands -the input file's encoding. Eg on some unix systems, you may need set -the 'LANG' environment variable. You can read more about this in -Unicode characters, below. + hledger's output will use the system locale's encoding. - On some unix systems you can use the 'file' command to show a file's -text encoding. On mac, you'll need the version from homebrew: 'brew -install file-formula'. - - hledger's text output is always UTF-8 encoded. + hledger's docs and example files mostly use UTF-8 encoding.  File: hledger.info, Node: Data formats, Next: Standard input, Prev: Text encoding, Up: Input @@ -214,9 +211,9 @@ Reader: Reads: Automatically used for time logging 'timedot' timedot files, for approximate '.timedot' time logging -'csv' Comma or other character '.csv' - separated values, for data - import +'csv' Comma- or other '.csv' + delimiter-separated values, for + data import 'ssv' Semicolon separated values '.ssv' 'tsv' Tab separated values '.tsv' 'rules' CSV/SSV/TSV/other separated '.rules' @@ -304,7 +301,8 @@ File: hledger.info, Node: Commands, Next: Options, Prev: Input, Up: Top hledger provides various subcommands for getting things done. Most of these commands do not change the journal file; they just read it and output a report. A few commands assist with adding data and file -management. +management. Some often-used commands are 'add', 'print', 'register', +'balancesheet' and 'incomestatement'. To show a summary of commands, run 'hledger' with no arguments. You can see the same commands summary at the start of PART 4: COMMANDS @@ -675,16 +673,13 @@ hledger is expected to handle non-ascii characters correctly: This requires a well-configured environment. Here are some tips: - * A system locale must be configured, and it must be one that can - decode the characters being used. In bash, you can set a locale - like this: 'export LANG=en_US.UTF-8'. There are some more details - in Troubleshooting. This step is essential - without it, hledger - will quit on encountering a non-ascii character (as with all - GHC-compiled programs). + * A system locale must be configured, which can decode the characters + being used. This is essential - see Text encoding and Install: + Text encoding. * Your terminal software (eg Terminal.app, iTerm, CMD.exe, xterm..) must support unicode. On Windows, you may need to use Windows - Terminal and/or enable UTF-8 support. + Terminal. * The terminal must be using a font which includes the required unicode glyphs. @@ -875,7 +870,9 @@ troubleshooting. When both '--conf' and '--no-conf' options are used, the right-most wins. To inspect the processing of config files, use '--debug' or -'--debug=8'. +'--debug=8'. Or, run the 'setup' command, which will display any active +config files. ('setup' is not affected by config files itself, unlike +other commands.) *Warning!* @@ -1103,10 +1100,9 @@ File: hledger.info, Node: HTML output, Next: CSV / TSV output, Prev: Text out HTML output can be styled by an optional 'hledger.css' file in the same directory. - HTML output will be UTF-8 encoded. If your web browser is showing -junk characters, you may need to change its text encoding to UTF-8. Eg -in Safari, see View -> Text Encoding and Settings -> Advanced -> Default -Encoding. + HTML output will be a HTML fragment, not a complete HTML document. +Like other hledger output, for non-ascii characters it will use the +system locale's text encoding (see Text encoding).  File: hledger.info, Node: CSV / TSV output, Next: FODS output, Prev: HTML output, Up: Output format @@ -1151,7 +1147,7 @@ want to follow its conventions, for a cleaner conversion: * use Beancount-friendly account names * use currency codes instead of currency symbols * use cost notation instead of equity conversion postings - * avoid virtual postings + * avoid virtual postings, balance assignments, and secondary dates. There is one big adjustment you must handle yourself: for Beancount, the top level account names must be 'Assets', 'Liabilities', 'Equity', @@ -1162,9 +1158,9 @@ hledger2beancount.conf config file. 2024-12-20: Some more things not yet handled for you: * P directives are not converted automatically - convert those - yourself - * Balance assignments are not converted (Beancount doesnt support - them) - replace those with explicit amounts + yourself. + * Balance assignments are not converted (Beancount doesn't support + them) - replace those with explicit amounts. * Menu: @@ -1563,7 +1559,8 @@ include other.journal ; Include another journal file here. 2024-02-01 note some event, or a transaction not yet fully entered, on this date ; Postings are not required. -; Some other date formats are allowed (but, consistent YYYY-MM-DD is useful). +# Consistent YYYY-MM-DD date format is recommended, +# but you can use . or / and omit leading zeros if you prefer. 2024.01.01 2024/1/1 @@ -2127,8 +2124,7 @@ does not disable balance assignments, described below). * Menu: * Assertions and ordering:: -* Assertions and multiple included files:: -* Assertions and multiple -f files:: +* Assertions and multiple files:: * Assertions and costs:: * Assertions and commodities:: * Assertions and subaccounts:: @@ -2136,9 +2132,10 @@ does not disable balance assignments, described below). * Assertions and virtual postings:: * Assertions and auto postings:: * Assertions and precision:: +* Assertions and hledger add::  -File: hledger.info, Node: Assertions and ordering, Next: Assertions and multiple included files, Up: Balance assertions +File: hledger.info, Node: Assertions and ordering, Next: Assertions and multiple files, Up: Balance assertions 8.12.1 Assertions and ordering ------------------------------ @@ -2155,39 +2152,35 @@ same account, which have balance assertions; those will likely need updating.  -File: hledger.info, Node: Assertions and multiple included files, Next: Assertions and multiple -f files, Prev: Assertions and ordering, Up: Balance assertions +File: hledger.info, Node: Assertions and multiple files, Next: Assertions and costs, Prev: Assertions and ordering, Up: Balance assertions -8.12.2 Assertions and multiple included files ---------------------------------------------- +8.12.2 Assertions and multiple files +------------------------------------ -Multiple files included with the 'include' directive are processed as if -concatenated into one file, preserving their order and the posting order -within each file. It means that balance assertions in later files will -see balance from earlier files. +If an account has transactions appearing in multiple files, balance +assertions can still work - but _only if those files are part of a +hierarchy made by include directives_. - And if you have multiple postings to an account on the same day, -split across multiple files, and you want to assert the account's -balance on that day, you'll need to put the assertion in the right file -- the last one in the sequence, probably. + If the same files are specified with two '-f' options on the command +line, the assertions in the second will not see the balances from the +first. + + To work around this, arrange your files in a hierarchy with +'include'. Or, you could concatenate the files temporarily, and process +them like one big file. + + Why does it work this way ? It might be related to hledger's goal of +stable predictable reports. File hierarchy is considered "permanent", +part of your data, while the order of command line options/arguments is +not. We don't want transient changes to be able to change the meaning +of the data. Eg it would be frustrating if tomorrow all your balance +assertions broke because you wrote command line arguments in a different +order. (Discussion welcome.)  -File: hledger.info, Node: Assertions and multiple -f files, Next: Assertions and costs, Prev: Assertions and multiple included files, Up: Balance assertions +File: hledger.info, Node: Assertions and costs, Next: Assertions and commodities, Prev: Assertions and multiple files, Up: Balance assertions -8.12.3 Assertions and multiple -f files ---------------------------------------- - -Unlike 'include', when multiple files are specified on the command line -with multiple '-f/--file' options, balance assertions will not see -balance from earlier files. This can be useful when you do not want -problems in earlier files to disrupt valid assertions in later files. - - If you do want assertions to see balance from earlier files, use -'include', or concatenate the files temporarily. - - -File: hledger.info, Node: Assertions and costs, Next: Assertions and commodities, Prev: Assertions and multiple -f files, Up: Balance assertions - -8.12.4 Assertions and costs +8.12.3 Assertions and costs --------------------------- Balance assertions ignore costs, and should normally be written without @@ -2205,7 +2198,7 @@ costs), and because balance _assignments_ do use costs (see below).  File: hledger.info, Node: Assertions and commodities, Next: Assertions and subaccounts, Prev: Assertions and costs, Up: Balance assertions -8.12.5 Assertions and commodities +8.12.4 Assertions and commodities --------------------------------- The balance assertions described so far are "*single commodity balance @@ -2254,7 +2247,7 @@ specified commodities and no others. It can be done by  File: hledger.info, Node: Assertions and subaccounts, Next: Assertions and status, Prev: Assertions and commodities, Up: Balance assertions -8.12.6 Assertions and subaccounts +8.12.5 Assertions and subaccounts --------------------------------- All of the balance assertions above (both '=' and '==') are @@ -2273,7 +2266,7 @@ by adding a star after the equals ('=*' or '==*'):  File: hledger.info, Node: Assertions and status, Next: Assertions and virtual postings, Prev: Assertions and subaccounts, Up: Balance assertions -8.12.7 Assertions and status +8.12.6 Assertions and status ---------------------------- Balance assertions always consider postings of all statuses (unmarked, @@ -2283,7 +2276,7 @@ pending, or cleared); they are not affected by the '-U'/'--unmarked' /  File: hledger.info, Node: Assertions and virtual postings, Next: Assertions and auto postings, Prev: Assertions and status, Up: Balance assertions -8.12.8 Assertions and virtual postings +8.12.7 Assertions and virtual postings -------------------------------------- Balance assertions always consider both real and virtual postings; they @@ -2292,7 +2285,7 @@ are not affected by the '--real/-R' flag or 'real:' query.  File: hledger.info, Node: Assertions and auto postings, Next: Assertions and precision, Prev: Assertions and virtual postings, Up: Balance assertions -8.12.9 Assertions and auto postings +8.12.8 Assertions and auto postings ----------------------------------- Balance assertions _are_ affected by the '--auto' flag, which generates @@ -2309,16 +2302,36 @@ these. So to avoid making fragile assertions, either: (or avoid auto postings entirely).  -File: hledger.info, Node: Assertions and precision, Prev: Assertions and auto postings, Up: Balance assertions +File: hledger.info, Node: Assertions and precision, Next: Assertions and hledger add, Prev: Assertions and auto postings, Up: Balance assertions -8.12.10 Assertions and precision --------------------------------- +8.12.9 Assertions and precision +------------------------------- Balance assertions compare the exactly calculated amounts, which are not always what is shown by reports. Eg a commodity directive may limit the display precision, but this will not affect balance assertions. Balance assertion failure messages show exact amounts. + +File: hledger.info, Node: Assertions and hledger add, Prev: Assertions and precision, Up: Balance assertions + +8.12.10 Assertions and hledger add +---------------------------------- + +Balance assertions can be included in the amounts given in 'add'. All +types of assertions are supported, and assertions can be used as in a +normal journal file. + + All transactions, not just those that have an explicit assertion, are +validated against the existing assertions in the journal. This means it +is possible for an added transaction to fail even if its assertions are +correct as of the transaction date. + + If this assertion checking is not desired, then it can be disabled +with '-I'. + + However, balance assignments are currently not supported. +  File: hledger.info, Node: Posting comments, Next: Transaction balancing, Prev: Balance assertions, Up: Journal @@ -2770,34 +2783,29 @@ File: hledger.info, Node: Account types, Prev: Account display order, Up: acc 8.17.4 Account types -------------------- -hledger knows that accounts come in several types: assets, liabilities, -expenses and so on. This enables easy reports like balancesheet and -incomestatement, and filtering by account type with the 'type:' query. +hledger knows that in accounting there are three main account types: - As a convenience, hledger will detect these account types -automatically if you are using common english-language top-level account -names (described below). But it's more robust to declare accounts' -types explicitly, by adding 'type:' tags to their account directives. -The tag's value should be one of the five main account types: +'Asset' 'A' things you own +'Liability' 'L' things you owe +'Equity' 'E' owner's investment, balances the two above - * 'A' or 'Asset' (things you own) - * 'L' or 'Liability' (things you owe) - * 'E' or 'Equity' (investment/ownership; balanced counterpart of - assets & liabilities) - * 'R' or 'Revenue' (what you received money from, AKA income; - technically part of Equity) - * 'X' or 'Expense' (what you spend money on; technically part of - Equity) + and two more representing changes in these: - or, it can be (these are used less often): +'Revenue' 'R' inflows (also known as 'Income') +'Expense' 'X' outflows - * 'C' or 'Cash' (a subtype of Asset, indicating liquid assets for the - cashflow report) - * 'V' or 'Conversion' (a subtype of Equity, for conversions (see Cost - reporting).) + hledger also uses a couple of subtypes: - Subaccounts inherit their parent's type, or they can override it. -Here is a typical set of account type declarations: +'Cash' 'C' liquid assets +'Conversion' 'V' commodity conversions equity + + As a convenience, hledger will detect these types automatically from +english account names. But it's better to declare them explicitly by +adding a 'type:' tag in the account directives. The tag's value can be +any of the types or one-letter abbreviations above. + + Here is a typical set of account type declarations. Subaccounts will +inherit their parent's type, or can override it: account assets ; type: A account liabilities ; type: L @@ -2810,14 +2818,25 @@ account assets:cash ; type: C account equity:conversion ; type: V - Here are some tips for working with account types. + This enables the easy balancesheet, balancesheetequity, cashflow and +incomestatement reports, and querying by type:. - * The rules for inferring types from account names are as follows. - These are just a convenience that sometimes help new users get - going; if they don't work for you, just ignore them and declare - your account types. See also Regular expressions. + Tips: - If account's name contains this (CI) regular expression: | its type is: + * You can list accounts and their types, for troubleshooting: + + $ hledger accounts --types [ACCTPAT] [type:TYPECODES] [-DEPTH] [--positions] + + * It's a good idea to declare at least one account for each account + type. Having some types declared and some inferred can disrupt + certain reports. + + * The rules for inferring types from account names are as follows + (using Regular expressions). + If they don't work for you, just ignore them and declare your types + with 'type:' tags. + + If account's name contains this case insensitive regular expression | its type is --------------------------------------------------------------------|------------- ^assets?(:.+)?:(cash|bank|che(ck|que?)(ing)?|savings?|current)(:|$) | Cash ^assets?(:|$) | Asset @@ -2827,16 +2846,9 @@ account equity:conversion ; type: V ^(income|revenue)s?(:|$) | Revenue ^expenses?(:|$) | Expense - * If you declare any account types, it's a good idea to declare an - account for all of the account types, because a mixture of declared - and name-inferred types can disrupt certain reports. - - * Certain uses of account aliases can disrupt account types. See - Rewriting accounts > Aliases and account types. - * As mentioned above, subaccounts will inherit a type from their - parent account. More precisely, an account's type is decided by - the first of these that exists: + parent account. To be precise, an account's type is decided by the + first of these that exists: 1. A 'type:' declaration for this account. 2. A 'type:' declaration in the parent accounts above it, @@ -2846,9 +2858,7 @@ account equity:conversion ; type: V preferring the nearest parent. 5. Otherwise, it will have no type. - * For troubleshooting, you can list accounts and their types with: - - $ hledger accounts --types [ACCTPAT] [-DEPTH] [type:TYPECODES] + * Account aliases can disrupt account types.  File: hledger.info, Node: alias directive, Next: commodity directive, Prev: account directive, Up: Journal @@ -4027,15 +4037,14 @@ File: hledger.info, Node: CSV, Next: Timeclock, Prev: Journal, Up: Top 9 CSV ***** -hledger can read CSV files (Character Separated Value - usually comma, -semicolon, or tab) containing dated records, automatically converting -each record into a transaction. +hledger can read transactions from CSV (comma-separated values) files. +More precisely, it can read DSV (delimiter-separated values), from a +file or standard input. Comma-separated, semicolon-separated and +tab-separated are the most common variants, and hledger will recognise +these three automatically based on a '.csv', '.ssv' or '.tsv' file name +extension or a 'csv:', 'ssv:' or 'tsv:' file path prefix. - (To learn about _writing_ CSV, see CSV output.) - - For best error messages when reading CSV/TSV/SSV files, make sure -they have a corresponding '.csv', '.tsv' or '.ssv' file extension or use -a hledger file prefix (see File Extension below). + (To learn about producing CSV or TSV _output_, see Output format.) Each CSV file must be described by a corresponding _rules file_. This contains rules describing the CSV data (header line, fields layout, @@ -4065,8 +4074,8 @@ $ hledger print -f basic.csv expenses:unknown 10.23 income:unknown -10.23 - There's an introductory Importing CSV data tutorial on hledger.org, -and more CSV rules examples below, and a larger collection at + There's an introductory Tutorial: Import CSV data on hledger.org, and +more CSV rules examples below, and a larger collection at https://github.com/simonmichael/hledger/tree/master/examples/csv. * Menu: @@ -4172,19 +4181,24 @@ File: hledger.info, Node: encoding, Next: separator, Prev: source, Up: CSV encoding ENCODING - hledger normally expects non-ascii text to be UTF8-encoded. If you -need to read CSV files which have some other encoding, you can do it by -adding 'encoding ENCODING' to your CSV rules. Eg: 'encoding ISO88591'. + hledger normally expects non-ascii text to be using the system +locale's text encoding. If you need to read CSV files which have some +other encoding, you can do it by adding 'encoding ENCODING' to your CSV +rules. Eg: 'encoding iso-8859-1'. - The following encodings are supported (these names are -case-insensitive, and can be written with inner spaces or hyphens if you -prefer): ASCII, UTF8, UTF16, UTF32, ISO88591, ISO88592, ISO88593, -ISO88594, ISO88595, ISO88596, ISO88597, ISO88598, ISO88599, ISO885910, -ISO885911, ISO885913, ISO885914, ISO885915, ISO885916, CP1250, CP1251, -CP1252, CP1253, CP1254, CP1255, CP1256, CP1257, CP1258, KOI8R, KOI8U, -GB18030, MacOSRoman, JISX0201, JISX0208, ISO2022JP, ShiftJIS, CP437, -CP737, CP775, CP850, CP852, CP855, CP857, CP860, CP861, CP862, CP863, -CP864, CP865, CP866, CP869, CP874, CP932. + The following encodings are supported: + + 'ascii', 'utf-8', 'utf-16', 'utf-32', 'iso-8859-1', 'iso-8859-2', +'iso-8859-3', 'iso-8859-4', 'iso-8859-5', 'iso-8859-6', 'iso-8859-7', +'iso-8859-8', 'iso-8859-9', 'iso-8859-10', 'iso-8859-11', 'iso-8859-13', +'iso-8859-14', 'iso-8859-15', 'iso-8859-16', 'cp1250', 'cp1251', +'cp1252', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', +'koi8-r', 'koi8-u', 'gb18030', 'macintosh', 'jis-x-0201', 'jis-x-0208', +'iso-2022-jp', 'shift-jis', 'cp437', 'cp737', 'cp775', 'cp850', 'cp852', +'cp855', 'cp857', 'cp860', 'cp861', 'cp862', 'cp863', 'cp864', 'cp865', +'cp866', 'cp869', 'cp874', 'cp932'. + + _Added in 1.42._  File: hledger.info, Node: separator, Next: skip, Prev: encoding, Up: CSV @@ -5302,40 +5316,59 @@ File: hledger.info, Node: How CSV rules are evaluated, Next: Well factored rul 9.19.14 How CSV rules are evaluated ----------------------------------- -Here's how to think of CSV rules being evaluated (if you really need -to). First, +Here's how to think of CSV rules being evaluated. If you get a +confusing error while reading a CSV file, it may help to try to +understand which of these steps is failing: - * 'include' - all includes are inlined, from top to bottom, depth - first. (At each include point the file is inlined and scanned for - further includes, recursively, before proceeding.) + 1. Any included rules files are inlined, from top to bottom, depth + first (scanning each included file for further includes, + recursively, before proceeding). - Then "global" rules are evaluated, top to bottom. If a rule is -repeated, the last one wins: + 2. Top level rules ('date-format', 'fields', 'newest-first', 'skip' + etc) are read, top to bottom. "Top level rules" means + non-conditional rules. If a rule occurs more than once, the last + one wins; except for 'skip'/'end' rules, where the first one wins. - * 'skip' (at top level) - * 'date-format' - * 'newest-first' - * 'fields' - names the CSV fields, optionally sets up initial - assignments to hledger fields + 3. The CSV file is read as text. Any non-ascii characters will be + decoded using the text encoding specified by the 'encoding' rule, + otherwise the system locale's text encoding. - Then for each CSV record in turn: + 4. Any top-level skip or end rule is applied. 'skip [N]' immediately + skips the current or next N CSV records; 'end' immediately skips + all remaining CSV records (not normally used at top level). - * test all 'if' blocks. If any of them contain a 'end' rule, skip - all remaining CSV records. Otherwise if any of them contain a - 'skip' rule, skip that many CSV records. If there are multiple - matched 'skip' rules, the first one wins. - * collect all field assignments at top level and in matched 'if' - blocks. When there are multiple assignments for a field, keep only - the last one. - * compute a value for each hledger field - either the one that was - assigned to it (and interpolate the %CSVFIELD references), or a - default - * generate a hledger transaction (journal entry) from these values. + 5. Now any remaining CSV records are processed. For each CSV record, + in file order: - This is all part of the CSV reader, one of several readers hledger -can use to parse input files. When all files have been read -successfully, the transactions are passed as input to whichever hledger -command the user specified. + * Is there a conditional skip/end rule that applies for this + record ? Search the 'if' blocks, from top to bottom, for a + succeeding one containing a 'skip' or 'end' rule. If found, + skip the specified number of CSV records, then continue at 5. + Otherwise... + + * Do some basic validation on this CSV record (eg, check that it + has at least two fields). + + * For each hledger field ('date', 'description', 'account1', + etc.): + + 1. Get the field's assigned value, first searching top level + assignments, made directly or by the 'fields' rule, then + assignments made inside succeeding 'if' blocks. If there + are more than one, the last one wins. + + 2. Compute the field's actual value (as text), by + interpolating any %CSVFIELD references within the + assigned value; or by choosing a default value if there + was no assignment. + + * Generate a hledger transaction from the hledger field values, + parsing them if needed (eg from text to an amount). + + This is all done by the CSV reader, one of several readers hledger +can use to read transactions from an input file. When all input files +have been read successfully, their transactions are passed to whichever +hledger command the user specified.  File: hledger.info, Node: Well factored rules, Prev: How CSV rules are evaluated, Up: Working with CSV @@ -5678,11 +5711,18 @@ i 2015/03/30 09:00:00 some account optional description after 2 spaces ; option o 2015/03/30 09:20:00 i 2015/03/31 22:21:45 another:account o 2015/04/01 02:00:34 +i 2015/04/02 12:00:00 another:account ; this demonstrates multple sessions being clocked in +i 2015/04/02 13:00:00 some account +o 2015/04/02 14:00:00 +o 2015/04/02 15:00:00 another:account hledger treats each clock-in/clock-out pair as a transaction posting -some number of hours to an account. Or if the session spans more than -one day, it is split into several transactions, one for each day. For -the above time log, 'hledger print' generates these journal entries: +some number of hours to an account. Entries are paired by the account +name if the same name is given for a clock-in/clock-out pair. If no +name is given for a clock-out, then it is paired with the most recent +clock-in entry. If the session spans more than one day, it is split +into several transactions, one for each day. For the above time log, +'hledger print' generates these journal entries: $ hledger -f t.timeclock print 2015-03-30 * optional description after 2 spaces ; optional comment, tags: @@ -5694,6 +5734,12 @@ $ hledger -f t.timeclock print 2015-04-01 * 00:00-02:00 (another:account) 2.01h +2015-04-02 * 12:00-15:00 ; this demonstrates multiple sessions being clocked in + (another:account) 3.00h + +2015-04-02 * 13:00-14:00 + (some account) 1.00h + Here is a sample.timeclock to download and some queries to try: $ hledger -f sample.timeclock balance # current time balances @@ -6354,33 +6400,33 @@ File: hledger.info, Node: Queries, Next: Pivoting, Prev: Depth, Up: Top 15 Queries ********** -One of hledger's strengths is being able to quickly report on a precise -subset of your data. Most hledger commands accept query arguments, to -restrict their scope. Multiple query terms can be provided to build up -a more complex query. +Many hledger commands accept query arguments, which restrict their scope +and let you report on a precise subset of your data. Here's a quick +overview of hledger's queries: - * By default, a query term is interpreted as a case-insensitive - substring pattern for matching account names: + * By default, a query argument is treated as a case-insensitive + substring pattern for matching account names. Eg: - 'car:fuel' 'dining groceries' + 'car:fuel' * Patterns containing spaces or other special characters must be enclosed in single or double quotes: ''personal care'' - * These patterns are actually regular expressions, so you can add - regexp metacharacters for more precision (see "Regular expressions" - above for details): + * Patterns are actually regular expressions, so you can add regexp + metacharacters for more precision (or you may need to + backslash-escape certain characters; see "Regular expressions" + above): ''^expenses\b'' ''food$'' ''fuel|repair'' ''accounts (payable|receivable)'' - * To match something other than account name, add one of the query - type prefixes described in "Query types" below: + * To match something other than the account name, you can add a query + type prefix, such as: 'date:202312-' 'status:' @@ -6388,39 +6434,59 @@ a more complex query. 'cur:USD' 'cur:\\$' 'amt:'>0'' + 'acct:groceries' (but 'acct:' is the default, so we usually don't + bother writing it) - * Add a 'not:' prefix to negate a term: + * To negate a query, add a 'not:' prefix: 'not:status:'*'' 'not:desc:'opening|closing'' 'not:cur:USD' - * Terms with different types are AND-ed, terms with the same type are - OR-ed (mostly; see "Combining query terms" below). The following - query: + * Multiple query terms can be combined, as space-separated queries + Eg: 'hledger print date:2022 desc:amazon desc:amzn' (show + transactions dated in 2022 whose description contains "amazon" or + "amzn"). - 'date:2022 desc:amazon desc:amzn' + * Or more flexibly as boolean queries. Eg: 'hledger print + expr:'date:2022 and (desc:amazon or desc:amzn) and not + date:202210'' - is interpreted as: + All hledger commands use the same query language, but different +commands may interpret the query in different ways. We haven't +described the commands yet (that's coming in PART 4: COMMANDS below) but +here's the gist of it: - _date is in 2022 AND ( transaction description contains "amazon" OR - "amzn" )_ + * Transaction-oriented commands ('print', 'aregister', 'close', + 'import', 'descriptions'..) try to match transactions (including + the transaction's postings). + + * Posting-oriented commands ('register', 'balance', 'balancesheet', + 'incomestatement', 'accounts'..) try to match postings. Postings + inherit their transaction's attributes for querying purposes, so + transaction fields like date or description can still be referenced + in a posting query. + + * A few commands match in more specific ways. (Eg 'aregister', which + has a special first argument.) * Menu: * Query types:: -* Combining query terms:: +* Negative queries:: +* Space-separated queries:: +* Boolean queries:: * Queries and command options:: * Queries and account aliases:: * Queries and valuation::  -File: hledger.info, Node: Query types, Next: Combining query terms, Up: Queries +File: hledger.info, Node: Query types, Next: Negative queries, Up: Queries 15.1 Query types ================ -Here are the types of query term available. +Here are the query types available: * Menu: @@ -6432,8 +6498,6 @@ Here are the types of query term available. * date query:: * date2 query:: * depth query:: -* expr query:: -* not query:: * note query:: * payee query:: * real query:: @@ -6461,11 +6525,15 @@ File: hledger.info, Node: amt query, Next: code query, Prev: acct query, Up: *'amt:N, amt:'N', amt:'>=N''* Match postings with a single-commodity amount equal to, less than, or greater than N. (Postings with multi-commodity amounts are not tested -and will always match.) The comparison has two modes: if N is preceded -by a + or - sign (or is 0), the two signed numbers are compared. -Otherwise, the absolute magnitudes are compared, ignoring sign. 'amt:' -needs quotes to hide the less than/greater than sign from the command -line shell. +and will always match.) 'amt:' needs quotes to hide the less +than/greater than sign from the command line shell. + + The comparison has two modes: if N is preceded by a + or - sign (or +is 0), the two signed numbers are compared. Otherwise, the absolute +magnitudes are compared, ignoring sign. + + Keep in mind that 'amt:' matches posting amounts, not account +balances.  File: hledger.info, Node: code query, Next: cur query, Prev: amt query, Up: Query types @@ -6524,7 +6592,7 @@ If you use secondary dates: this matches secondary dates within the specified period. It is not affected by the '--date2' flag.  -File: hledger.info, Node: depth query, Next: expr query, Prev: date2 query, Up: Query types +File: hledger.info, Node: depth query, Next: note query, Prev: date2 query, Up: Query types 15.1.8 depth: query ------------------- @@ -6535,36 +6603,11 @@ depth, optionally only for accounts matching a provided regular expression. See Depth for detailed rules.  -File: hledger.info, Node: expr query, Next: not query, Prev: depth query, Up: Query types +File: hledger.info, Node: note query, Next: payee query, Prev: depth query, Up: Query types -15.1.9 expr: query +15.1.9 note: query ------------------ -*'expr:'QUERYEXPR''* -'expr' lets you write more complicated query expressions with AND, OR, -NOT, and parentheses. -Eg: 'expr:'date:lastmonth and not (food or rent)'' -The expression should be enclosed in quotes. See Combining query terms -below. - - -File: hledger.info, Node: not query, Next: note query, Prev: expr query, Up: Query types - -15.1.10 not: query ------------------- - -*'not:QUERYTERM'* -You can prepend *'not:'* to any other query term to negate the match. -Eg: 'not:equity', 'not:desc:apple' -(Also, a trick: 'not:not:...' can sometimes solve query problems -conveniently..) - - -File: hledger.info, Node: note query, Next: payee query, Prev: not query, Up: Query types - -15.1.11 note: query -------------------- - *'note:REGEX'* Match transaction notes (the part of the description right of '|', or the whole description if there's no '|'). @@ -6572,7 +6615,7 @@ the whole description if there's no '|').  File: hledger.info, Node: payee query, Next: real query, Prev: note query, Up: Query types -15.1.12 payee: query +15.1.10 payee: query -------------------- *'payee:REGEX'* @@ -6582,7 +6625,7 @@ Match transaction payee/payer names (the part of the description left of  File: hledger.info, Node: real query, Next: status query, Prev: payee query, Up: Query types -15.1.13 real: query +15.1.11 real: query ------------------- *'real:, real:0'* @@ -6591,7 +6634,7 @@ Match real or virtual postings respectively.  File: hledger.info, Node: status query, Next: type query, Prev: real query, Up: Query types -15.1.14 status: query +15.1.12 status: query --------------------- *'status:, status:!, status:*'* @@ -6600,7 +6643,7 @@ Match unmarked, pending, or cleared transactions respectively.  File: hledger.info, Node: type query, Next: tag query, Prev: status query, Up: Query types -15.1.15 type: query +15.1.13 type: query ------------------- *'type:TYPECODES'* @@ -6614,7 +6657,7 @@ kinds of account alias can disrupt account types, see Rewriting accounts  File: hledger.info, Node: tag query, Prev: type query, Up: Query types -15.1.16 tag: query +15.1.14 tag: query ------------------ *'tag:NAMEREGEX[=VALREGEX]'* @@ -6630,10 +6673,32 @@ Match by tag name, and optionally also by tag value. Note: * Transactions also acquire the tags of their postings.  -File: hledger.info, Node: Combining query terms, Next: Queries and command options, Prev: Query types, Up: Queries +File: hledger.info, Node: Negative queries, Next: Space-separated queries, Prev: Query types, Up: Queries -15.2 Combining query terms -========================== +15.2 Negative queries +===================== + +* Menu: + +* not query:: + + +File: hledger.info, Node: not query, Up: Negative queries + +15.2.1 not: query +----------------- + +*'not:QUERY'* +You can prepend *'not:'* to a query to negate the match. +Eg: 'not:equity', 'not:desc:apple' +(Also, a trick: 'not:not:...' can sometimes solve query problems +conveniently.) + + +File: hledger.info, Node: Space-separated queries, Next: Boolean queries, Prev: Negative queries, Up: Queries + +15.3 Space-separated queries +============================ When given multiple space-separated query terms, most commands select things which match: @@ -6650,40 +6715,94 @@ things which match: * have no postings matching any of the negative account terms AND * match all the other terms. - We also support more complex boolean queries with the 'expr:' prefix. -This allows one to combine query terms using 'and', 'or', 'not' keywords -(case insensitive), and to group them by enclosing in parentheses. + +File: hledger.info, Node: Boolean queries, Next: Queries and command options, Prev: Space-separated queries, Up: Queries - Some examples: +15.4 Boolean queries +==================== - * Exclude account names containing 'food': +You can write more complicated "boolean" query expressions, enclosed in +quotes and prefixed with 'expr:'. These can combine subqueries with +NOT, AND, OR operators (case insensitive), and parentheses for grouping. +Eg, to show transactions involving both cash and expense accounts: - 'expr:"not food"' ('not:food' is equivalent) +hledger print expr:'cash AND expenses' - * Match things which have 'cool' in the description and the 'A' tag: + The prefix and enclosing quotes are required, so don't write 'hledger +print cash AND expenses'. That would be a space-separated query showing +transactions involving accounts with any of "cash", "and", "expenses" in +their names. - 'expr:"desc:cool and tag:A"' ('expr:"desc:cool tag:A"' is - equivalent) + You can write space-separated queries _inside_ a boolean query, and +they will combine as described above, but it might be confusing and best +avoided. Eg these are equivalent, showing transactions involving cash +or expenses accounts: - * Match things which either do not reference the 'expenses:food' - account, or do have the 'A' tag: +hledger print expr:'cash expenses' +hledger print cash expenses - 'expr:"not expenses:food or tag:A"' + There is a restriction with 'date:' queries: they may not be used +inside OR expressions. - * Match things which either do not reference the 'expenses:food' - account, or which reference the 'expenses:drink' account and also - have the 'A' tag: + Actually, there are three types of boolean query: 'expr:' for general +use, and 'any:' and 'all:' variants which can be useful with 'print'. - 'expr:"expenses:food or (expenses:drink and tag:A)"' +* Menu: - 'expr:' has a restriction: 'date:' queries may not be used inside -'or' expressions. That would allow disjoint report periods or disjoint -result sets, with unclear semantics for our reports. +* expr query:: +* any query:: +* all query::  -File: hledger.info, Node: Queries and command options, Next: Queries and account aliases, Prev: Combining query terms, Up: Queries +File: hledger.info, Node: expr query, Next: any query, Up: Boolean queries -15.3 Queries and command options +15.4.1 expr: query +------------------ + +*'expr:'QUERYEXPR''* +For example, 'expr:'date:lastmonth AND NOT (food OR rent)'' means "match +things which are dated in the last month and do not have food or rent in +the account name". + + When using 'expr:' with transaction-oriented commands like 'print', +posting-oriented query terms like 'acct:' and 'amt:' are considered to +match the transaction if they match any of its postings. +So, 'hledger print expr:'cash and amt:>0'' means "show transactions with +(at least one posting involving a cash account) and (at least one +posting with a positive amount)". + + +File: hledger.info, Node: any query, Next: all query, Prev: expr query, Up: Boolean queries + +15.4.2 any: query +----------------- + +*'any:'QUERYEXPR''* +Like 'expr:', but when used with transaction-oriented commands like +'print', it matches the transaction only if a posting can be matched by +all of QUERYEXPR. +So, 'hledger print any:'cash and amt:>0'' means "show transactions where +at least one posting posts a positive amount to a cash account". + + +File: hledger.info, Node: all query, Prev: any query, Up: Boolean queries + +15.4.3 all: query +----------------- + +*'all:'QUERYEXPR''* +Like 'expr:', but when used with transaction-oriented commands like +'print', it matches the transaction only if all postings are matched by +all of QUERYEXPR. +So, 'hledger print all:'cash and amt:0'' means "show transactions where +all postings involve a cash account and have a zero amount". +Or, 'hledger print all:'cash or checking'' means "show transactions +which touch only cash and/or checking accounts". + + +File: hledger.info, Node: Queries and command options, Next: Queries and account aliases, Prev: Boolean queries, Up: Queries + +15.5 Queries and command options ================================ Some queries can also be expressed as command-line options: 'depth:2' is @@ -6694,7 +6813,7 @@ resulting query is their intersection.  File: hledger.info, Node: Queries and account aliases, Next: Queries and valuation, Prev: Queries and command options, Up: Queries -15.4 Queries and account aliases +15.6 Queries and account aliases ================================ When account names are rewritten with '--alias' or 'alias', 'acct:' will @@ -6703,7 +6822,7 @@ match either the old or the new account name.  File: hledger.info, Node: Queries and valuation, Prev: Queries and account aliases, Up: Queries -15.5 Queries and valuation +15.7 Queries and valuation ========================== When amounts are converted to other commodities in cost or value @@ -7151,7 +7270,7 @@ by humans)* * This is produced by reports that show full journal entries: 'print', 'import', 'close', 'rewrite' etc. * It shows amounts with their original journal precisions, which may - not be consistent. + not be consistent from one amount to the next. * It adds a trailing decimal mark when needed to avoid showing ambiguous amounts. * It can be parsed reliably (by hledger and ledger2beancount at @@ -7998,11 +8117,14 @@ If you have installed more add-on commands, they also will be listed. *Help commands* - * help - show the hledger manual with info/man/pager + * commands - show the hledger commands list (default) * demo - show small hledger demos in the terminal + * help - show the hledger manual with info, man, or pager *User interface commands* + * repl - run commands from an interactive prompt + * run - run commands from a script * ui - (if installed) run hledger's terminal UI * web - (if installed) run hledger's web UI @@ -8054,6 +8176,7 @@ If you have installed more add-on commands, they also will be listed. * check - check for various kinds of error in the data * diff - compare account transactions in two journal files + * setup - check and show the status of the hledger installation * test - run self tests Next, these commands are described in detail. @@ -9096,6 +9219,7 @@ Flags: txt, beancount, csv, tsv, html, fods, json, sql. -o --output-file=FILE write output to FILE. A file extension matching one of the above formats selects that format. + --location add file/line number tags to print output. The print command displays full journal entries (transactions) from the journal file, sorted by date (or with '--date2', by secondary date). @@ -9225,6 +9349,9 @@ whose description is most similar to DESC. DESC should contain at least two characters. If there is no similar-enough match, no transaction will be shown and the program exit code will be non-zero. + With '--location', print adds the source file and line number to +every transaction, as a tag. +  File: hledger.info, Node: print output format, Prev: print other features, Up: print @@ -10087,8 +10214,8 @@ listing account balances, balance changes, values, value changes and more, during one time period or many. Generally it shows a table, with rows representing accounts, and columns representing periods. - Note there are some higher-level variants of the 'balance' command -with convenient defaults, which can be simpler to use: 'balancesheet', + Note there are some variants of the 'balance' command with convenient +defaults, which are simpler to use: 'balancesheet', 'balancesheetequity', 'cashflow' and 'incomestatement'. When you need more control, then use 'balance'. @@ -10106,7 +10233,7 @@ more control, then use 'balance'. * Percentages:: * Multi-period balance report:: * Balance change end balance:: -* Balance report types:: +* Balance report modes:: * Budget report:: * Balance report layout:: * Balance report output:: @@ -10120,7 +10247,7 @@ File: hledger.info, Node: balance features, Next: Simple balance report, Up: Here's a quick overview of the 'balance' command's features, followed by more detailed descriptions and examples. Many of these work with the -higher-level commands as well. +other balance-like commands as well ('bs', 'cf', 'is'..). 'balance' can show.. @@ -10415,8 +10542,9 @@ commodity, it is treated as 0). Revenues and liability balances are typically negative, however, so '-S' shows these in reverse order. To work around this, you can add -'--invert' to flip the signs. (Or, use one of the higher-level reports, -which flip the sign automatically. Eg: 'hledger incomestatement -MAS'). +'--invert' to flip the signs. Or you could use one of the higher-level +balance reports ('bs', 'is'..), which flip the sign automatically (eg: +'hledger is -MAS').  File: hledger.info, Node: Percentages, Next: Multi-period balance report, Prev: Sorting by amount, Up: balance @@ -10502,7 +10630,7 @@ viewing in the terminal. Here are some ways to handle that: && open a.html'  -File: hledger.info, Node: Balance change end balance, Next: Balance report types, Prev: Multi-period balance report, Up: balance +File: hledger.info, Node: Balance change end balance, Next: Balance report modes, Prev: Multi-period balance report, Up: balance 29.1.12 Balance change, end balance ----------------------------------- @@ -10539,9 +10667,9 @@ historical end balances: ignored when summing postings.)  -File: hledger.info, Node: Balance report types, Next: Budget report, Prev: Balance change end balance, Up: balance +File: hledger.info, Node: Balance report modes, Next: Budget report, Prev: Balance change end balance, Up: balance -29.1.13 Balance report types +29.1.13 Balance report modes ---------------------------- The balance command is quite flexible; here is the full detail on how to @@ -10551,20 +10679,20 @@ experimentation to get familiar with all the report modes. There are three important option groups: - 'hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] + 'hledger balance [CALCULATIONMODE] [ACCUMULATIONMODE] [VALUATIONMODE] ...' * Menu: -* Calculation type:: -* Accumulation type:: -* Valuation type:: -* Combining balance report types:: +* Calculation mode:: +* Accumulation mode:: +* Valuation mode:: +* Combining balance report modes::  -File: hledger.info, Node: Calculation type, Next: Accumulation type, Up: Balance report types +File: hledger.info, Node: Calculation mode, Next: Accumulation mode, Up: Balance report modes -29.1.13.1 Calculation type +29.1.13.1 Calculation mode .......................... The basic calculation to perform for each table cell. It is one of: @@ -10580,9 +10708,9 @@ The basic calculation to perform for each table cell. It is one of: * '--count' : show the count of postings  -File: hledger.info, Node: Accumulation type, Next: Valuation type, Prev: Calculation type, Up: Balance report types +File: hledger.info, Node: Accumulation mode, Next: Valuation mode, Prev: Calculation mode, Up: Balance report modes -29.1.13.2 Accumulation type +29.1.13.2 Accumulation mode ........................... How amounts should accumulate across a report's subperiods/columns. @@ -10606,15 +10734,18 @@ each cell's calculation. It is one of: balancesheetequity*)  -File: hledger.info, Node: Valuation type, Next: Combining balance report types, Prev: Accumulation type, Up: Balance report types +File: hledger.info, Node: Valuation mode, Next: Combining balance report modes, Prev: Accumulation mode, Up: Balance report modes -29.1.13.3 Valuation type +29.1.13.3 Valuation mode ........................ Which kind of value or cost conversion should be applied, if any, before -displaying the report. It is one of: +displaying the report. See Cost reporting and Value reporting for more +about conversions. - * no valuation type : don't convert to cost or value (*default*) + A valuation (or cost) mode can be selected with the -value option: + + * no conversion : don't convert to cost or value (*default*) * '--value=cost[,COMM]' : convert amounts to cost (then optionally to some other commodity) * '--value=then[,COMM]' : convert amounts to market value on @@ -10627,23 +10758,25 @@ displaying the report. It is one of: * '--value=YYYY-MM-DD[,COMM]' : convert amounts to market value on another date - or one of the equivalent simpler flags: + or with the legacy -B/-V/-X options, which are equivalent and easier +to type: - * '-B/--cost' : like -value=cost (though, note -cost and -value are - independent options which can both be used at once) - * '-V/--market' : like -value=end - * '-X COMM/--exchange COMM' : like -value=end,COMM + * '-B'/'--cost' : like -value=cost + * '-V'/'--market' : like -value=end + * '-X COMM'/'--exchange COMM' : like -value=end,COMM - See Cost reporting and Value reporting for more about these. + Note that -value can also convert to cost, as a convenience; but +actually -cost and -value are independent options, and could be used +together.  -File: hledger.info, Node: Combining balance report types, Prev: Valuation type, Up: Balance report types +File: hledger.info, Node: Combining balance report modes, Prev: Valuation mode, Up: Balance report modes -29.1.13.4 Combining balance report types +29.1.13.4 Combining balance report modes ........................................ -Most combinations of these options should produce reasonable reports, -but if you find any that seem wrong or misleading, let us know. The +Most combinations of these modes should produce reasonable reports, but +if you find any that seem wrong or misleading, let us know. The following restrictions are applied: * '--valuechange' implies '--value=end' @@ -10676,13 +10809,13 @@ Accumulation:v YYYY-MM-DD end  -File: hledger.info, Node: Budget report, Next: Balance report layout, Prev: Balance report types, Up: balance +File: hledger.info, Node: Budget report, Next: Balance report layout, Prev: Balance report modes, Up: balance 29.1.14 Budget report --------------------- -The '--budget' report type is like a regular balance report, but with -two main differences: +The '--budget' report is like a regular balance report, but with two +main differences: * Budget goals and performance percentages are also shown, in brackets @@ -11070,9 +11203,8 @@ File: hledger.info, Node: Balance report output, Next: Some useful balance rep ----------------------------- As noted in Output format, if you choose HTML output (by using '-O html' -or '-o somefile.html'), it will use the UTF-8 text encoding, And you can -create a 'hledger.css' file in the same directory to customise the -report's appearance. +or '-o somefile.html'), you can create a 'hledger.css' file in the same +directory to customise the report's appearance. The HTML and FODS output formats can generate hyperlinks to a 'hledger-web' register view for each account and period. E.g. if your @@ -11855,6 +11987,7 @@ File: hledger.info, Node: Maintenance commands, Next: PART 5 COMMON TASKS, Pr * check:: * diff:: +* setup:: * test::  @@ -11905,16 +12038,17 @@ commands: errors and no invalid include directives. This ensures that all files exist and are readable. - * *autobalanced* - all transactions are balanced, after inferring - missing amounts and conversion costs where possible, and then - converting to cost. This ensures that each individual transaction - is well formed. + * *autobalanced* - all transactions are balanced, after automatically + inferring missing amounts and conversion rates and then converting + amounts to cost. This ensures that each transaction's entry is + well formed. * *assertions* - all balance assertions in the journal are passing. - Balance assertions are like canaries in your journal, they catch - many problems. They can get in the way sometimes; you can disable - them temporarily with '-I'/'--ignore-assertions' (unless overridden - with '-s'/'--strict' or 'hledger check assertions'). + Balance assertions are a strong defense against errors; they help + catch many problems. If this check gets in your way, you can + disable it with '-I'/'--ignore-assertions'. Or you can add that to + your config file to disable it by default (and then use + '-s'/'--strict' or 'hledger check assertions' to enable it).  File: hledger.info, Node: Strict checks, Next: Other checks, Prev: Basic checks, Up: check @@ -11922,18 +12056,19 @@ File: hledger.info, Node: Strict checks, Next: Other checks, Prev: Basic chec 32.1.2 Strict checks -------------------- -These additional checks are performed by any command when the -'-s'/'--strict' flag is used (strict mode). Strict mode always enables -the balance assertions check, also. These provide extra error-catching -power when you are serious about keeping your data clean and free of -typos: +These additional checks are performed by all commands when the +'-s'/'--strict' flag is used (strict mode). They provide extra +error-catching power to keep your data clean and correct. Strict mode +also always enables the 'assertions' check. - * *balanced* - like 'autobalanced', but in conversion transactions, - costs must be written explicitly. This ensures some redundancy in - the entry, which helps prevent typos. + * *balanced* - like 'autobalanced', but all conversions between + commodities must use explicit cost notation or equity postings. + This prevents wrong conversions caused by typos. * *commodities* - all commodity symbols used must be declared. This - guards against mistyping or omitting commodity symbols. + guards against mistyping or omitting commodity symbols. Declaring + commodities also sets their precision for display and transaction + balancing. * *accounts* - all account names used must be declared. This prevents the use of mis-spelled or outdated account names. @@ -11944,38 +12079,37 @@ File: hledger.info, Node: Other checks, Next: Custom checks, Prev: Strict che 32.1.3 Other checks ------------------- -These other checks are not wanted by everyone, but can be run using the -'check' command: +These are not wanted by everyone, but can be run using the 'check' +command: - * *ordereddates* - within each file, transactions are ordered by - date. This is a simple and effective error catcher, and you should - use it. Alas! not everyone wants it. If you do, use 'hledger - check -s ordereddates'. When enabled, this check is performed - early, before balance assertions (because copy-pasted dates are - often the root cause of balance assertion failures). + * *tags* - all tags used must be declared. This prevents mis-spelled + tag names. Note hledger fairly often finds unintended tags in + comments. - * *payees* - all payees used by transactions must be declared. This - will force you to always use known/declared payee names. For most - people this is a bit too restrictive. + * *payees* - all payees used in transactions must be declared. This + will force you to declare any new payee name before using it. Most + people will probably find this a bit too strict. - * *tags* - all tags used by transactions must be declared. This - prevents mistyped tag names. + * *ordereddates* - within each file, transactions must be ordered by + date. This is a simple and effective error catcher. It's not + included in strict mode, but you can add it by running 'hledger + check -s ordereddates'. If enabled, this check is performed before + balance assertions. * *recentassertions* - all accounts with balance assertions must have - a balance assertion within the last 7 days before their latest - posting. This encourages you to add balance assertions fairly - regularly for your active asset/liability accounts, which in turn - should encourage you to check and reconcile with their real world - balances fairly regularly. 'close --assert' can be helpful. (The - older balance assertions become redundant; you can remove them - periodically, or leave them in place, perhaps commented, as - documentation.) + one that's within the 7 days before their latest posting. This + will encourage adding balance assertions for your active + asset/liability accounts, which in turn should encourage you to + reconcile regularly with those real world balances - another strong + defense against errors. 'hledger close --assert' can help generate + assertion entries. Over time the older assertions become somewhat + redundant, and you can remove them if you like (they don't affect + performance much, but they add some noise to the journal). - * *uniqueleafnames* - no two accounts may have the same leaf name. - The leaf name is the last colon-separated part of an account name, - eg 'checking' in 'assets:bank:checking'. This encourages you to - keep those unique, effectively giving each account a short name - which is easier to remember and to type in reporting commands. + * *uniqueleafnames* - no two accounts may have the same last account + name part (eg the 'checking' in 'assets:bank:checking'). This + ensures each account can be matched by a unique short name, easier + to remember and to type.  File: hledger.info, Node: Custom checks, Prev: Other checks, Up: check @@ -11993,7 +12127,7 @@ also Cookbook > Scripting. Here are some examples from hledger/bin/: are passing  -File: hledger.info, Node: diff, Next: test, Prev: check, Up: Maintenance commands +File: hledger.info, Node: diff, Next: setup, Prev: check, Up: Maintenance commands 32.2 diff ========= @@ -12032,9 +12166,75 @@ These transactions are in the first file only: These transactions are in the second file only:  -File: hledger.info, Node: test, Prev: diff, Up: Maintenance commands +File: hledger.info, Node: setup, Next: test, Prev: diff, Up: Maintenance commands -32.3 test +32.3 setup +========== + +Check the status of the hledger installation. + +Flags: +no command-specific flags + + 'setup' tests your hledger installation and prints a list of results, +sometimes with helpful hints. This is a good first command to run after +installing hledger. Also after upgrading, or when something's not +working, or just when you want a reminder of where things are. + + It makes one network request to detect the latest hledger release +version. It's ok if this fails or times out. It will use ANSI color by +default, unless disabled by NO_COLOR or -color=n. It does not use a +pager or a config file. + + It expects that the hledger version you are running is installed in +your PATH. If not, it will stop until you have done that (to keep things +simple). + + Example: + +$ hledger setup +Checking your hledger setup.. +Legend: good, neutral, unknown, warning + +hledger +* is a released version ? no hledger 1.42.99-gbca4b39c5-20250425, mac-aarch64 +* is up to date ? yes 1.42.99 installed, latest is 1.42.1 +* is a native binary for this machine ? yes aarch64 +* is installed in PATH ? yes /Users/simon/.local/bin/hledger +* has a system text encoding configured ? yes UTF-8, data files should use this encoding +* has a user config file ? (optional) no +* current directory has a local config ? yes /Users/simon/src/hledger/hledger.conf +* the config file is readable ? yes /Users/simon/src/hledger/hledger.conf + +terminal +* the NO_COLOR variable is defined ? no +* --color is configured by config file ? no +* hledger will use color by default ? yes +* the PAGER variable is defined ? yes less +* --pager is configured by config file ? no +* hledger will use a pager when needed ? yes /opt/homebrew/bin/less +* the LESS variable is defined ? yes +* the HLEDGER_LESS variable is defined ? no +* adjusting LESS variable for color etc. ? yes +* --pretty is enabled by config file ? no tables will use ASCII characters +* bash shell completions are installed ? ? +* zsh shell completions are installed ? ? + +journal +* the LEDGER_FILE variable is defined ? yes /Users/simon/finance/2025/2025.journal +* a default journal file is readable ? yes /Users/simon/finance/2025/2025.journal +* it includes additional files ? yes 15 +* all commodities are declared ? yes 10 +* all accounts are declared ? yes 160 +* all accounts have types ? no 14 untyped +* accounts of each type were detected ? yes ALERXCV +* commodities/accounts are checked ? no use -s to check commodities/accounts +* balance assertions are checked ? yes use -I to ignore assertions + + +File: hledger.info, Node: test, Prev: setup, Up: Maintenance commands + +32.4 test ========= Run built-in unit tests. @@ -12051,14 +12251,15 @@ sanity-check the installed hledger executable on your platform. All tests are expected to pass - if you ever see a failure, please report as a bug! - This command also accepts tasty test runner options, written after a -- (double hyphen). Eg to run only the tests in Hledger.Data.Amount, -with ANSI colour codes disabled: + Any arguments before a '--' argument will be passed to the 'tasty' +test runner as test-selecting -p patterns, and any arguments after '--' +will be passed to tasty unchanged. -$ hledger test -- -pData.Amount --color=never + Examples: - For help on these, see https://github.com/feuerbach/tasty#options -('-- --help' currently doesn't show them). +$ hledger test # run all unit tests +$ hledger test balance # run tests with "balance" in their name +$ hledger test -- -h # show tasty's options  File: hledger.info, Node: PART 5 COMMON TASKS, Next: Getting help, Prev: Maintenance commands, Up: Top @@ -12520,8 +12721,8 @@ File: hledger.info, Node: BUGS, Prev: Migrating to a new file, Up: Top 43 BUGS ******* -We welcome bug reports in the hledger issue tracker (shortcut: -https://bugs.hledger.org), or on the hledger chat or mail list +We welcome bug reports in the hledger issue tracker +(https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). Some known issues and limitations: @@ -12530,8 +12731,8 @@ https://bugs.hledger.org), or on the hledger chat or mail list from hledger is awkward. (See Command options, Constructing command lines.) - A UTF-8-aware system locale must be configured to work with non-ascii -data. (See Unicode characters, Troubleshooting.) + A system locale with a suitable text encoding must be configured to +work with non-ascii data. (See Text encoding, Troubleshooting.) On Microsoft Windows, depending whether you are running in a CMD window or a Cygwin/MSYS/Mintty window and how you installed hledger, @@ -12574,31 +12775,11 @@ using it* * You may need to force your shell to see the new configuration. A simple way is to close your terminal window and open a new one. - *LANG issues: I get errors like "Illegal byte sequence" or "Invalid -or incomplete multibyte or wide character" or "commitAndReleaseBuffer: -invalid argument (invalid character)"* -Programs compiled with GHC (hledger, haskell build tools, etc.) need -the system locale to be UTF-8-aware, or they will fail when they -encounter non-ascii characters. To fix it, set the LANG environment -variable to a locale which supports UTF-8 and which is installed on your -system. - - On unix, 'locale -a' lists the installed locales. Look for one which -mentions 'utf8', 'UTF-8' or similar. Some examples: 'C.UTF-8', -'en_US.utf-8', 'fr_FR.utf8'. If necessary, use your system package -manager to install one. Then select it by setting the 'LANG' -environment variable. Note, exact spelling and capitalisation of the -locale name may be important: Here's one common way to configure this -permanently for your shell: - -$ echo "export LANG=en_US.utf8" >>~/.profile -# close and re-open terminal window - - If you are using Nix (not NixOS) for GHC and Hledger, you might need -to set the 'LOCALE_ARCHIVE' variable: - -$ echo "export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive" >>~/.profile -# close and re-open terminal window + *Text decoding issues: I get errors like "Illegal byte sequence" or +"Invalid or incomplete multibyte or wide character" or +"commitAndReleaseBuffer: invalid argument (invalid character)"* +hledger usually needs its input to be decodable with the system locale's +text encoding. See Text encoding and Install: Text encoding. *COMPATIBILITY ISSUES: hledger gives an error with my Ledger file* Not all of Ledger's journal file syntax or feature set is supported. @@ -12610,384 +12791,389 @@ Node: Top208 Node: PART 1 USER INTERFACE4363 Node: Input4502 Node: Text encoding5594 -Node: Data formats6451 -Node: Standard input8175 -Node: Multiple files8564 -Node: Strict mode9301 -Node: Commands10135 -Node: Add-on commands11321 -Node: Options12539 -Node: Special characters19282 -Node: Escaping shell special characters20232 -Node: Escaping on Windows21476 -Node: Escaping regular expression special characters22209 -Node: Escaping add-on arguments23196 -Node: Escaping in other situations24225 -Node: Using a wild card25184 -Node: Unicode characters25563 -Node: Regular expressions27227 -Node: hledger's regular expressions30486 -Node: Argument files32127 -Node: Config files32830 -Node: Shell completions35983 -Node: Output36472 -Node: Output destination36663 -Node: Output format37221 -Node: Text output39007 -Node: Box-drawing characters39986 -Node: Colour40486 -Node: Paging41072 -Node: HTML output42598 -Node: CSV / TSV output43052 -Node: FODS output43306 -Node: Beancount output44110 -Node: Beancount account names45565 -Node: Beancount commodity names46106 -Node: Beancount virtual postings46753 -Node: Beancount metadata47069 -Node: Beancount costs47849 -Node: Beancount operating currency48265 -Node: SQL output48715 -Node: JSON output49506 -Node: Commodity styles50323 -Node: Debug output51210 -Node: Environment52042 -Node: PART 2 DATA FORMATS52699 -Node: Journal52842 -Node: Journal cheatsheet55320 -Node: Comments61534 -Node: Transactions62478 -Node: Dates63615 -Node: Simple dates63767 -Node: Posting dates64383 -Node: Status65470 -Node: Code67236 -Node: Description67571 -Node: Payee and note68258 -Node: Transaction comments69349 -Node: Postings69865 -Node: Debits and credits71028 -Node: The two space delimiter71638 -Node: Account names72203 -Node: Amounts74007 -Node: Decimal marks75036 -Node: Digit group marks76140 -Node: Commodity76775 -Node: Costs77892 -Node: Balance assertions80144 -Node: Assertions and ordering81407 -Node: Assertions and multiple included files82135 -Node: Assertions and multiple -f files82895 -Node: Assertions and costs83537 -Node: Assertions and commodities84187 -Node: Assertions and subaccounts85846 -Node: Assertions and status86506 -Node: Assertions and virtual postings86926 -Node: Assertions and auto postings87291 -Node: Assertions and precision88166 -Node: Posting comments88617 -Node: Transaction balancing89157 -Node: Tags91159 -Node: Querying with tags92453 -Node: Displaying tags93252 -Node: When to use tags ?93648 -Node: Tag names94312 -Node: Special tags94865 -Node: Directives96430 -Node: Directives and multiple files97887 -Node: Directive effects98832 -Node: account directive101988 -Node: Account comments103438 -Node: Account error checking104097 -Node: Account display order105634 -Node: Account types106832 -Node: alias directive110606 -Node: Basic aliases111817 -Node: Regex aliases112692 -Node: Combining aliases113739 -Node: Aliases and multiple files115193 -Node: end aliases directive115976 -Node: Aliases can generate bad account names116344 -Node: Aliases and account types117177 -Node: commodity directive118069 -Node: Commodity directive syntax119656 -Node: Commodity error checking121305 -Node: decimal-mark directive121780 -Node: include directive122359 -Node: P directive123435 -Node: payee directive124469 -Node: tag directive125091 -Node: Periodic transactions125703 -Node: Periodic rule syntax127857 -Node: Periodic rules and relative dates128680 -Node: Two spaces between period expression and description!129457 -Node: Auto postings130418 -Node: Auto postings and multiple files133578 -Node: Auto postings and dates133983 -Node: Auto postings and transaction balancing / inferred amounts / balance assertions134424 -Node: Auto posting tags135270 -Node: Auto postings on forecast transactions only136165 -Node: Other syntax136635 -Node: Balance assignments137407 -Node: Balance assignments and costs138935 -Node: Balance assignments and multiple files139357 -Node: Bracketed posting dates139780 -Node: D directive140478 -Node: apply account directive142251 -Node: Y directive143118 -Node: Secondary dates144106 -Node: Star comments145591 -Node: Valuation expressions146283 -Node: Virtual postings146582 -Node: Other Ledger directives148206 -Node: Other cost/lot notations148968 -Node: CSV151809 -Node: CSV rules cheatsheet153905 -Node: source155932 -Node: encoding156932 -Node: separator157871 -Node: skip158524 -Node: date-format159174 -Node: timezone160017 -Node: newest-first161143 -Node: intra-day-reversed161856 -Node: decimal-mark162456 -Node: fields list162936 -Node: Field assignment164744 -Node: Field names165963 -Node: date field167295 -Node: date2 field167459 -Node: status field167654 -Node: code field167844 -Node: description field168032 -Node: comment field168249 -Node: account field168806 -Node: amount field169524 -Node: currency field172363 -Node: balance field172771 -Node: if block173294 -Node: Matchers174821 -Node: Multiple matchers176811 -Node: Match groups177619 -Node: if table178512 -Node: balance-type180575 -Node: include181402 -Node: Working with CSV181971 -Node: Rapid feedback182523 -Node: Valid CSV183106 -Node: File Extension183982 -Node: Reading CSV from standard input184717 -Node: Reading multiple CSV files185103 -Node: Reading files specified by rule185579 -Node: Valid transactions186976 -Node: Deduplicating importing187801 -Node: Setting amounts189030 -Node: Amount signs191557 -Node: Setting currency/commodity192622 -Node: Amount decimal places193998 -Node: Referencing other fields195255 -Node: How CSV rules are evaluated196363 -Node: Well factored rules198031 -Node: CSV rules examples198521 -Node: Bank of Ireland198719 -Node: Coinbase200316 -Node: Amazon201499 -Node: Paypal203341 -Node: Timeclock211091 -Node: Timedot213360 -Node: Timedot examples216837 -Node: PART 3 REPORTING CONCEPTS219114 -Node: Time periods219278 -Node: Report start & end date219551 -Node: Smart dates221027 -Node: Report intervals222970 -Node: Date adjustments223544 -Node: Start date adjustment223764 -Node: End date adjustment224667 -Node: Period headings225412 -Node: Period expressions226345 -Node: Period expressions with a report interval228250 -Node: More complex report intervals228698 -Node: Multiple weekday intervals230814 -Node: Depth231825 -Node: Queries233660 -Node: Query types235358 -Node: acct query235775 -Node: amt query236086 -Node: code query236703 -Node: cur query236898 -Node: desc query237504 -Node: date query237687 -Node: date2 query238083 -Node: depth query238374 -Node: expr query238710 -Node: not query239091 -Node: note query239431 -Node: payee query239697 -Node: real query239978 -Node: status query240183 -Node: type query240423 -Node: tag query240956 -Node: Combining query terms241585 -Node: Queries and command options243325 -Node: Queries and account aliases243779 -Node: Queries and valuation244104 -Node: Pivoting244466 -Node: Generating data246742 -Node: Forecasting248542 -Node: --forecast249198 -Node: Inspecting forecast transactions250299 -Node: Forecast reports251632 -Node: Forecast tags252741 -Node: Forecast period in detail253361 -Node: Forecast troubleshooting254449 -Node: Budgeting255520 -Node: Amount formatting256080 -Node: Commodity display style256324 -Node: Rounding258165 -Node: Trailing decimal marks258770 -Node: Amount parseability259703 -Node: Cost reporting261284 -Node: Recording costs262115 -Node: Reporting at cost263842 -Node: Equity conversion postings264607 -Node: Inferring equity conversion postings267252 -Node: Combining costs and equity conversion postings268394 -Node: Requirements for detecting equity conversion postings269619 -Node: Infer cost and equity by default ?271141 -Node: Value reporting271578 -Node: -V Value272514 -Node: -X Value in specified commodity272841 -Node: Valuation date273191 -Node: Finding market price274151 -Node: --infer-market-prices market prices from transactions275531 -Node: Valuation commodity278575 -Node: --value Flexible valuation280008 -Node: Valuation examples281851 -Node: Interaction of valuation and queries283983 -Node: Effect of valuation on reports284700 -Node: PART 4 COMMANDS292598 -Node: Help commands294814 -Node: commands295000 -Node: demo295208 -Node: help296442 -Node: User interface commands298147 -Node: repl298358 -Node: Examples300622 -Node: run301180 -Node: Examples 2303595 -Node: ui304619 -Node: web304756 -Node: Data entry commands304884 -Node: add305082 -Node: import307537 -Node: Import preview308571 -Node: Overlap detection309519 -Node: First import312405 -Node: Importing balance assignments313600 -Node: Import and commodity styles314655 -Node: Import special cases315093 -Node: Basic report commands316428 -Node: accounts316729 -Node: codes319662 -Node: commodities320684 -Node: descriptions320928 -Node: files321395 -Node: notes321692 -Node: payees322204 -Node: prices322988 -Node: stats323880 -Node: tags325621 -Node: Standard report commands326928 -Node: print327233 -Node: print explicitness329974 -Node: print amount style330894 -Node: print parseability332132 -Node: print other features333051 -Node: print output format333914 -Node: aregister337199 -Node: aregister and posting dates341752 -Node: register342653 -Node: Custom register output349894 -Node: balancesheet351079 -Node: balancesheetequity356044 -Node: cashflow361379 -Node: incomestatement366192 -Node: Advanced report commands371041 -Node: balance371249 -Node: balance features376686 -Node: Simple balance report378762 -Node: Balance report line format380572 -Node: Filtered balance report382932 -Node: List or tree mode383451 -Node: Depth limiting384964 -Node: Dropping top-level accounts385731 -Node: Showing declared accounts386241 -Node: Sorting by amount386971 -Node: Percentages387808 -Node: Multi-period balance report388515 -Node: Balance change end balance391267 -Node: Balance report types392904 -Node: Calculation type393583 -Node: Accumulation type394287 -Node: Valuation type395388 -Node: Combining balance report types396577 -Node: Budget report398609 -Node: Using the budget report400914 -Node: Budget date surprises403190 -Node: Selecting budget goals404554 -Node: Budgeting vs forecasting405502 -Node: Balance report layout407179 -Node: Wide layout408384 -Node: Tall layout410789 -Node: Bare layout412095 -Node: Tidy layout414159 -Node: Balance report output415703 -Node: Some useful balance reports416518 -Node: roi417778 -Node: Spaces and special characters in --inv and --pnl420025 -Node: Semantics of --inv and --pnl420751 -Node: IRR and TWR explained422838 -Node: Chart commands426249 -Node: activity426430 -Node: Data generation commands426927 -Node: close427133 -Node: close --clopen429696 -Node: close --close431870 -Node: close --open432394 -Node: close --assert432644 -Node: close --assign432971 -Node: close --retain433650 -Node: close customisation434507 -Node: close and balance assertions436151 -Node: close examples437673 -Node: Retain earnings437910 -Node: Migrate balances to a new file438413 -Node: More detailed close examples439775 -Node: rewrite439997 -Node: Re-write rules in a file442569 -Node: Diff output format443879 -Node: rewrite vs print --auto445152 -Node: Maintenance commands445866 -Node: check446075 -Node: Basic checks447157 -Node: Strict checks448110 -Node: Other checks448985 -Node: Custom checks450840 -Node: diff451295 -Node: test452502 -Node: PART 5 COMMON TASKS453374 -Node: Getting help453607 -Node: Constructing command lines454516 -Node: Starting a journal file455354 -Node: Setting LEDGER_FILE456738 -Node: Setting opening balances457996 -Node: Recording transactions461318 -Node: Reconciling462043 -Node: Reporting464432 -Node: Migrating to a new file468546 -Node: BUGS468995 -Node: Troubleshooting469960 +Node: Data formats6343 +Node: Standard input8077 +Node: Multiple files8466 +Node: Strict mode9203 +Node: Commands10037 +Node: Add-on commands11319 +Node: Options12537 +Node: Special characters19280 +Node: Escaping shell special characters20230 +Node: Escaping on Windows21474 +Node: Escaping regular expression special characters22207 +Node: Escaping add-on arguments23194 +Node: Escaping in other situations24223 +Node: Using a wild card25182 +Node: Unicode characters25561 +Node: Regular expressions26982 +Node: hledger's regular expressions30241 +Node: Argument files31882 +Node: Config files32585 +Node: Shell completions35886 +Node: Output36375 +Node: Output destination36566 +Node: Output format37124 +Node: Text output38910 +Node: Box-drawing characters39889 +Node: Colour40389 +Node: Paging40975 +Node: HTML output42501 +Node: CSV / TSV output42919 +Node: FODS output43173 +Node: Beancount output43977 +Node: Beancount account names45478 +Node: Beancount commodity names46019 +Node: Beancount virtual postings46666 +Node: Beancount metadata46982 +Node: Beancount costs47762 +Node: Beancount operating currency48178 +Node: SQL output48628 +Node: JSON output49419 +Node: Commodity styles50236 +Node: Debug output51123 +Node: Environment51955 +Node: PART 2 DATA FORMATS52612 +Node: Journal52755 +Node: Journal cheatsheet55233 +Node: Comments61484 +Node: Transactions62428 +Node: Dates63565 +Node: Simple dates63717 +Node: Posting dates64333 +Node: Status65420 +Node: Code67186 +Node: Description67521 +Node: Payee and note68208 +Node: Transaction comments69299 +Node: Postings69815 +Node: Debits and credits70978 +Node: The two space delimiter71588 +Node: Account names72153 +Node: Amounts73957 +Node: Decimal marks74986 +Node: Digit group marks76090 +Node: Commodity76725 +Node: Costs77842 +Node: Balance assertions80094 +Node: Assertions and ordering81342 +Node: Assertions and multiple files82061 +Node: Assertions and costs83229 +Node: Assertions and commodities83876 +Node: Assertions and subaccounts85535 +Node: Assertions and status86195 +Node: Assertions and virtual postings86615 +Node: Assertions and auto postings86980 +Node: Assertions and precision87855 +Node: Assertions and hledger add88339 +Node: Posting comments89087 +Node: Transaction balancing89627 +Node: Tags91629 +Node: Querying with tags92923 +Node: Displaying tags93722 +Node: When to use tags ?94118 +Node: Tag names94782 +Node: Special tags95335 +Node: Directives96900 +Node: Directives and multiple files98357 +Node: Directive effects99302 +Node: account directive102458 +Node: Account comments103908 +Node: Account error checking104567 +Node: Account display order106104 +Node: Account types107302 +Node: alias directive110577 +Node: Basic aliases111788 +Node: Regex aliases112663 +Node: Combining aliases113710 +Node: Aliases and multiple files115164 +Node: end aliases directive115947 +Node: Aliases can generate bad account names116315 +Node: Aliases and account types117148 +Node: commodity directive118040 +Node: Commodity directive syntax119627 +Node: Commodity error checking121276 +Node: decimal-mark directive121751 +Node: include directive122330 +Node: P directive123406 +Node: payee directive124440 +Node: tag directive125062 +Node: Periodic transactions125674 +Node: Periodic rule syntax127828 +Node: Periodic rules and relative dates128651 +Node: Two spaces between period expression and description!129428 +Node: Auto postings130389 +Node: Auto postings and multiple files133549 +Node: Auto postings and dates133954 +Node: Auto postings and transaction balancing / inferred amounts / balance assertions134395 +Node: Auto posting tags135241 +Node: Auto postings on forecast transactions only136136 +Node: Other syntax136606 +Node: Balance assignments137378 +Node: Balance assignments and costs138906 +Node: Balance assignments and multiple files139328 +Node: Bracketed posting dates139751 +Node: D directive140449 +Node: apply account directive142222 +Node: Y directive143089 +Node: Secondary dates144077 +Node: Star comments145562 +Node: Valuation expressions146254 +Node: Virtual postings146553 +Node: Other Ledger directives148177 +Node: Other cost/lot notations148939 +Node: CSV151780 +Node: CSV rules cheatsheet153934 +Node: source155961 +Node: encoding156961 +Node: separator158003 +Node: skip158656 +Node: date-format159306 +Node: timezone160149 +Node: newest-first161275 +Node: intra-day-reversed161988 +Node: decimal-mark162588 +Node: fields list163068 +Node: Field assignment164876 +Node: Field names166095 +Node: date field167427 +Node: date2 field167591 +Node: status field167786 +Node: code field167976 +Node: description field168164 +Node: comment field168381 +Node: account field168938 +Node: amount field169656 +Node: currency field172495 +Node: balance field172903 +Node: if block173426 +Node: Matchers174953 +Node: Multiple matchers176943 +Node: Match groups177751 +Node: if table178644 +Node: balance-type180707 +Node: include181534 +Node: Working with CSV182103 +Node: Rapid feedback182655 +Node: Valid CSV183238 +Node: File Extension184114 +Node: Reading CSV from standard input184849 +Node: Reading multiple CSV files185235 +Node: Reading files specified by rule185711 +Node: Valid transactions187108 +Node: Deduplicating importing187933 +Node: Setting amounts189162 +Node: Amount signs191689 +Node: Setting currency/commodity192754 +Node: Amount decimal places194130 +Node: Referencing other fields195387 +Node: How CSV rules are evaluated196495 +Node: Well factored rules199212 +Node: CSV rules examples199702 +Node: Bank of Ireland199900 +Node: Coinbase201497 +Node: Amazon202680 +Node: Paypal204522 +Node: Timeclock212272 +Node: Timedot215097 +Node: Timedot examples218574 +Node: PART 3 REPORTING CONCEPTS220851 +Node: Time periods221015 +Node: Report start & end date221288 +Node: Smart dates222764 +Node: Report intervals224707 +Node: Date adjustments225281 +Node: Start date adjustment225501 +Node: End date adjustment226404 +Node: Period headings227149 +Node: Period expressions228082 +Node: Period expressions with a report interval229987 +Node: More complex report intervals230435 +Node: Multiple weekday intervals232551 +Node: Depth233562 +Node: Queries235397 +Node: Query types238069 +Node: acct query238444 +Node: amt query238755 +Node: code query239452 +Node: cur query239647 +Node: desc query240253 +Node: date query240436 +Node: date2 query240832 +Node: depth query241123 +Node: note query241459 +Node: payee query241725 +Node: real query242006 +Node: status query242211 +Node: type query242451 +Node: tag query242984 +Node: Negative queries243613 +Node: not query243795 +Node: Space-separated queries244082 +Node: Boolean queries244770 +Node: expr query246088 +Node: any query246768 +Node: all query247221 +Node: Queries and command options247767 +Node: Queries and account aliases248215 +Node: Queries and valuation248540 +Node: Pivoting248902 +Node: Generating data251178 +Node: Forecasting252978 +Node: --forecast253634 +Node: Inspecting forecast transactions254735 +Node: Forecast reports256068 +Node: Forecast tags257177 +Node: Forecast period in detail257797 +Node: Forecast troubleshooting258885 +Node: Budgeting259956 +Node: Amount formatting260516 +Node: Commodity display style260760 +Node: Rounding262601 +Node: Trailing decimal marks263206 +Node: Amount parseability264139 +Node: Cost reporting265748 +Node: Recording costs266579 +Node: Reporting at cost268306 +Node: Equity conversion postings269071 +Node: Inferring equity conversion postings271716 +Node: Combining costs and equity conversion postings272858 +Node: Requirements for detecting equity conversion postings274083 +Node: Infer cost and equity by default ?275605 +Node: Value reporting276042 +Node: -V Value276978 +Node: -X Value in specified commodity277305 +Node: Valuation date277655 +Node: Finding market price278615 +Node: --infer-market-prices market prices from transactions279995 +Node: Valuation commodity283039 +Node: --value Flexible valuation284472 +Node: Valuation examples286315 +Node: Interaction of valuation and queries288447 +Node: Effect of valuation on reports289164 +Node: PART 4 COMMANDS297062 +Node: Help commands299497 +Node: commands299683 +Node: demo299891 +Node: help301125 +Node: User interface commands302830 +Node: repl303041 +Node: Examples305305 +Node: run305863 +Node: Examples 2308278 +Node: ui309302 +Node: web309439 +Node: Data entry commands309567 +Node: add309765 +Node: import312220 +Node: Import preview313254 +Node: Overlap detection314202 +Node: First import317088 +Node: Importing balance assignments318283 +Node: Import and commodity styles319338 +Node: Import special cases319776 +Node: Basic report commands321111 +Node: accounts321412 +Node: codes324345 +Node: commodities325367 +Node: descriptions325611 +Node: files326078 +Node: notes326375 +Node: payees326887 +Node: prices327671 +Node: stats328563 +Node: tags330304 +Node: Standard report commands331611 +Node: print331916 +Node: print explicitness334728 +Node: print amount style335648 +Node: print parseability336886 +Node: print other features337805 +Node: print output format338766 +Node: aregister342051 +Node: aregister and posting dates346604 +Node: register347505 +Node: Custom register output354746 +Node: balancesheet355931 +Node: balancesheetequity360896 +Node: cashflow366231 +Node: incomestatement371044 +Node: Advanced report commands375893 +Node: balance376101 +Node: balance features381522 +Node: Simple balance report383625 +Node: Balance report line format385435 +Node: Filtered balance report387795 +Node: List or tree mode388314 +Node: Depth limiting389827 +Node: Dropping top-level accounts390594 +Node: Showing declared accounts391104 +Node: Sorting by amount391834 +Node: Percentages392688 +Node: Multi-period balance report393395 +Node: Balance change end balance396147 +Node: Balance report modes397784 +Node: Calculation mode398463 +Node: Accumulation mode399167 +Node: Valuation mode400268 +Node: Combining balance report modes401612 +Node: Budget report403642 +Node: Using the budget report405942 +Node: Budget date surprises408218 +Node: Selecting budget goals409582 +Node: Budgeting vs forecasting410530 +Node: Balance report layout412207 +Node: Wide layout413412 +Node: Tall layout415817 +Node: Bare layout417123 +Node: Tidy layout419187 +Node: Balance report output420731 +Node: Some useful balance reports421505 +Node: roi422765 +Node: Spaces and special characters in --inv and --pnl425012 +Node: Semantics of --inv and --pnl425738 +Node: IRR and TWR explained427825 +Node: Chart commands431236 +Node: activity431417 +Node: Data generation commands431914 +Node: close432120 +Node: close --clopen434683 +Node: close --close436857 +Node: close --open437381 +Node: close --assert437631 +Node: close --assign437958 +Node: close --retain438637 +Node: close customisation439494 +Node: close and balance assertions441138 +Node: close examples442660 +Node: Retain earnings442897 +Node: Migrate balances to a new file443400 +Node: More detailed close examples444762 +Node: rewrite444984 +Node: Re-write rules in a file447556 +Node: Diff output format448866 +Node: rewrite vs print --auto450139 +Node: Maintenance commands450853 +Node: check451072 +Node: Basic checks452154 +Node: Strict checks453175 +Node: Other checks454112 +Node: Custom checks455864 +Node: diff456319 +Node: setup457527 +Node: test460394 +Node: PART 5 COMMON TASKS461297 +Node: Getting help461530 +Node: Constructing command lines462439 +Node: Starting a journal file463277 +Node: Setting LEDGER_FILE464661 +Node: Setting opening balances465919 +Node: Recording transactions469241 +Node: Reconciling469966 +Node: Reporting472355 +Node: Migrating to a new file476469 +Node: BUGS476918 +Node: Troubleshooting477886  End Tag Table diff --git a/hledger/hledger.txt b/hledger/hledger.txt index 290050106..900d63b44 100644 --- a/hledger/hledger.txt +++ b/hledger/hledger.txt @@ -19,7 +19,7 @@ DESCRIPTION and largely compatible with ledger(1), and largely interconvertible with beancount(1). - This manual is for hledger's command line interface, version 1.42.99. + This manual is for hledger's command line interface, version 1.43.99. It also describes the common options, file formats and concepts used by all hledger programs. It might accidentally teach you some bookkeep- ing/accounting as well! You don't need to know everything in here to @@ -101,23 +101,19 @@ Input Common tasks > Setting LEDGER_FILE. Text encoding - hledger input files containing non-ascii characters must use UTF-8 en- - coding, with the exception of CSV (SSV, TSV..) files, which can be - read from other encodings (see encoding CSV rule). + hledger expects non-ascii input to be decodable with the system lo- + cale's text encoding. (For CSV/SSV/TSV files, this can be overridden + by the encoding CSV rule.) - In UTF-8 input files, an optional byte order mark (BOM) at the begin- - ning of the file is allowed. + So, trying to read non-ascii files which have the wrong text encoding, + or when no system locale is configured, will fail. To fix this, con- + figure your system locale appropriately, and/or convert the files to + your system's text encoding (using iconv on unix, or powershell or + notepad on Windows). See Install: Text encoding for more tips. - Your system may need to be configured with a locale that understands - the input file's encoding. Eg on some unix systems, you may need set - the LANG environment variable. You can read more about this in Unicode - characters, below. + hledger's output will use the system locale's encoding. - On some unix systems you can use the file command to show a file's text - encoding. On mac, you'll need the version from homebrew: brew install - file-formula. - - hledger's text output is always UTF-8 encoded. + hledger's docs and example files mostly use UTF-8 encoding. Data formats Usually the data file is in hledger's journal format, but it can be in @@ -132,7 +128,7 @@ Input logging timedot timedot files, for approximate .timedot time logging - csv Comma or other character sepa- .csv + csv Comma- or other delimiter-sepa- .csv rated values, for data import ssv Semicolon separated values .ssv tsv Tab separated values .tsv @@ -206,50 +202,51 @@ Commands hledger provides various subcommands for getting things done. Most of these commands do not change the journal file; they just read it and output a report. A few commands assist with adding data and file man- - agement. + agement. Some often-used commands are add, print, register, bal- + ancesheet and incomestatement. - To show a summary of commands, run hledger with no arguments. You can + To show a summary of commands, run hledger with no arguments. You can see the same commands summary at the start of PART 4: COMMANDS below. To use a particular command, run hledger CMD [CMDOPTS] [CMDARGS], - o CMD is the full command name, or its standard abbreviation shown in + o CMD is the full command name, or its standard abbreviation shown in the commands list, or any unambiguous prefix of the name. - o CMDOPTS are command-specific options, if any. Command-specific op- + o CMDOPTS are command-specific options, if any. Command-specific op- tions must be written after the command name. Eg: hledger print -x. - o CMDARGS are additional arguments to the command, if any. Most - hledger commands accept arguments representing a query, to limit the + o CMDARGS are additional arguments to the command, if any. Most + hledger commands accept arguments representing a query, to limit the data in some way. Eg: hledger reg assets:checking. To list a command's options, arguments, and documentation in the termi- nal, run hledger CMD -h. Eg: hledger bal -h. Add-on commands - In addition to the built-in commands, you can install add-on commands: - programs or scripts named "hledger-SOMETHING", which will also appear - in hledger's commands list. If you used the hledger-install script, - you will have several add-ons installed already. Some more can be - found in hledger's bin/ directory, documented at + In addition to the built-in commands, you can install add-on commands: + programs or scripts named "hledger-SOMETHING", which will also appear + in hledger's commands list. If you used the hledger-install script, + you will have several add-ons installed already. Some more can be + found in hledger's bin/ directory, documented at https://hledger.org/scripts.html. More precisely, add-on commands are programs or scripts in your shell's PATH, whose name starts with "hledger-" and ends with no extension or a - recognised extension (".bat", ".com", ".exe", ".hs", ".js", ".lhs", - ".lua", ".php", ".pl", ".py", ".rb", ".rkt", or ".sh"), and (on unix + recognised extension (".bat", ".com", ".exe", ".hs", ".js", ".lhs", + ".lua", ".php", ".pl", ".py", ".rb", ".rkt", or ".sh"), and (on unix and mac) which has executable permission for the current user. You can run add-on commands using hledger, much like built-in commands: hledger ADDONCMD [-- ADDONCMDOPTS] [ADDONCMDARGS]. But note the double - hyphen argument, required before add-on-specific options. Eg: hledger - ui -- --watch or hledger web -- --serve. If this causes difficulty, + hyphen argument, required before add-on-specific options. Eg: hledger + ui -- --watch or hledger web -- --serve. If this causes difficulty, you can always run the add-on directly, without using hledger: hledger-ui --watch or hledger-web --serve. Options - Run hledger -h to see general command line help. Options can be writ- - ten either before or after the command name. These options are spe- + Run hledger -h to see general command line help. Options can be writ- + ten either before or after the command name. These options are spe- cific to the hledger CLI: Flags: @@ -341,47 +338,47 @@ Options --pager=YN use a pager when needed ? y/yes (default) or n/no --color=YNA --colour use ANSI color ? y/yes, n/no, or auto (default) - Usually hledger accepts any unambiguous flag prefix, eg you can write + Usually hledger accepts any unambiguous flag prefix, eg you can write --tl instead of --tldr or --dry instead of --dry-run. - If the same option appears more than once in a command line, usually + If the same option appears more than once in a command line, usually the last (right-most) wins. Similarly, if mutually exclusive flags are - used together, the right-most wins. (When flags are mutually exclu- + used together, the right-most wins. (When flags are mutually exclu- sive, they'll usually have a group prefix in --help.) - With most commands, arguments are interpreted as a hledger query which - filter the data. Some queries can be expressed either with options or + With most commands, arguments are interpreted as a hledger query which + filter the data. Some queries can be expressed either with options or with arguments. Below are more tips for using the command line interface - feel free to skip these until you need them. Special characters - Here we touch on shell escaping/quoting rules, and give some examples. - This is a slightly complicated topic which you may not need at first, + Here we touch on shell escaping/quoting rules, and give some examples. + This is a slightly complicated topic which you may not need at first, but you should be aware of it, so you can return here when needed. If you are able to minimise the use of special characters in your data, - you won't need escaping as much, and your command lines will be sim- - pler. For example, avoiding spaces in account names, and using an - ISO-4217 currency code like USD instead of the $ currency symbol, can + you won't need escaping as much, and your command lines will be sim- + pler. For example, avoiding spaces in account names, and using an + ISO-4217 currency code like USD instead of the $ currency symbol, can be helpful. - But if you want to use spaced account names and $, go right ahead; es- + But if you want to use spaced account names and $, go right ahead; es- caping isn't a big deal. Escaping shell special characters - At the command line, characters which have special meaning for your + At the command line, characters which have special meaning for your shell must be "shell-escaped" (AKA "quoted") if you want hledger to see them. Often these include space, <, >, (, ), |, \, $ and/or %. - For example, to match an account name containing the phrase "credit + For example, to match an account name containing the phrase "credit card", don't write this: $ hledger register credit card - In that command, "credit" and "card" are treated as separate query ar- - guments (described below), so this would match accounts containing ei- + In that command, "credit" and "card" are treated as separate query ar- + guments (described below), so this would match accounts containing ei- ther word. Instead, enclose the phrase in double or single quotes: $ hledger register "credit card" @@ -391,10 +388,10 @@ Options $ hledger register credit\ card - Some shell characters still have a special meaning inside double + Some shell characters still have a special meaning inside double quotes, such as the dollar sign ($). Eg in "assets:$account", the bash - shell would replace $account with the value of a shell variable with - that name. When you don't want that, use single quotes, which escape + shell would replace $account with the value of a shell variable with + that name. When you don't want that, use single quotes, which escape more strongly: $ hledger balance 'assets:$account' @@ -403,21 +400,21 @@ Options If you are using hledger in a Powershell or Command window on Microsoft Windows, the escaping rules are different: - o In a Powershell window (powershell, blue background), you must use + o In a Powershell window (powershell, blue background), you must use double quotes or single quotes (not backslash). - o In a Command window (cmd, black background), you must use double + o In a Command window (cmd, black background), you must use double quotes (not single quotes or backslash). - The next two sections were written for Unix-like shells, so might need + The next two sections were written for Unix-like shells, so might need to be adapted if you're using cmd or powershell. (Edits welcome.) Escaping regular expression special characters - Many hledger arguments are regular expressions (described below), and - these too have characters which cause special effects. Some of those - characters are ., ^, $, [, ], (, ), |, and \. When you don't want - these to cause special effects, you can "regex-escape" them by writing - \ (a backslash) before them. But since backslash is also special to + Many hledger arguments are regular expressions (described below), and + these too have characters which cause special effects. Some of those + characters are ., ^, $, [, ], (, ), |, and \. When you don't want + these to cause special effects, you can "regex-escape" them by writing + \ (a backslash) before them. But since backslash is also special to the shell, you may need to also shell-escape the backslashes. Eg, in the bash shell, to match a literal $ sign, you could write: @@ -428,14 +425,14 @@ Options $ hledger balance 'cur:\$' - (The dollar sign is regex-escaped by the backslash preceding it. Then - that backslash is shell-escaped by another backslash, or by single + (The dollar sign is regex-escaped by the backslash preceding it. Then + that backslash is shell-escaped by another backslash, or by single quotes.) Escaping add-on arguments When you run an external add-on command with hledger (described below), - any options or arguments being passed through to the add-on executable - lose one level of shell-escaping, so you must add an extra level of + any options or arguments being passed through to the add-on executable + lose one level of shell-escaping, so you must add an extra level of shell-escaping to compensate. Eg, in the bash shell, to run the ui add-on and match a literal $ sign, @@ -455,7 +452,7 @@ Options o \\$ is regex-escaped, then shell-escaped - o \\\\$ is regex-escaped, then shell-escaped, then both slashes are + o \\\\$ is regex-escaped, then shell-escaped, then both slashes are shell-escaped once more for hledger argument pass-through. Or you can avoid such triple-escaping, by running the add-on executable @@ -464,8 +461,8 @@ Options $ hledger-ui cur:\\$ Escaping in other situations - hledger options and arguments are sometimes used in places other than - the command line, with different escaping rules. For example, back- + hledger options and arguments are sometimes used in places other than + the command line, with different escaping rules. For example, back- slash-quoting generally does not work there. Here are some more tips. In Windows cmd Use double quotes @@ -475,16 +472,16 @@ Options filter prompt In hledger-web's Use single or double quotes search form - In an argument Don't use spaces, don't shell-escape, do regex-es- + In an argument Don't use spaces, don't shell-escape, do regex-es- file cape when needed - In a config file Use single or double quotes, and enclose the whole + In a config file Use single or double quotes, and enclose the whole argument ("desc:a b" not desc:"a b") - In ghci (the Use double quotes, and enclose the whole argument + In ghci (the Use double quotes, and enclose the whole argument Haskell REPL) Using a wild card - When escaping a special character is too much hassle (or impossible), - you can often just write . (period) instead. In regular expressions, + When escaping a special character is too much hassle (or impossible), + you can often just write . (period) instead. In regular expressions, this means "accept any character here". Eg: $ hledger register credit.card @@ -492,8 +489,8 @@ Options Unicode characters hledger is expected to handle non-ascii characters correctly: - o they should be parsed correctly in input files and on the command - line, by all hledger tools (add, iadd, hledger-web's search/add/edit + o they should be parsed correctly in input files and on the command + line, by all hledger tools (add, iadd, hledger-web's search/add/edit forms, etc.) o they should be displayed correctly by all hledger tools, and @@ -501,16 +498,13 @@ Options This requires a well-configured environment. Here are some tips: - o A system locale must be configured, and it must be one that can de- - code the characters being used. In bash, you can set a locale like - this: export LANG=en_US.UTF-8. There are some more details in Trou- - bleshooting. This step is essential - without it, hledger will quit - on encountering a non-ascii character (as with all GHC-compiled pro- - grams). + o A system locale must be configured, which can decode the characters + being used. This is essential - see Text encoding and Install: Text + encoding. o Your terminal software (eg Terminal.app, iTerm, CMD.exe, xterm..) must support unicode. On Windows, you may need to use Windows Termi- - nal and/or enable UTF-8 support. + nal. o The terminal must be using a font which includes the required unicode glyphs. @@ -681,7 +675,9 @@ Options bleshooting. When both --conf and --no-conf options are used, the right-most wins. - To inspect the processing of config files, use --debug or --debug=8. + To inspect the processing of config files, use --debug or --debug=8. + Or, run the setup command, which will display any active config files. + (setup is not affected by config files itself, unlike other commands.) Warning! @@ -845,10 +841,9 @@ Output HTML output can be styled by an optional hledger.css file in the same directory. - HTML output will be UTF-8 encoded. If your web browser is showing junk - characters, you may need to change its text encoding to UTF-8. Eg in - Safari, see View -> Text Encoding and Settings -> Advanced -> Default - Encoding. + HTML output will be a HTML fragment, not a complete HTML document. + Like other hledger output, for non-ascii characters it will use the + system locale's text encoding (see Text encoding). CSV / TSV output In CSV or TSV output, digit group marks (such as thousands separators) @@ -881,7 +876,7 @@ Output o use cost notation instead of equity conversion postings - o avoid virtual postings + o avoid virtual postings, balance assignments, and secondary dates. There is one big adjustment you must handle yourself: for Beancount, the top level account names must be Assets, Liabilities, Equity, In- @@ -891,10 +886,11 @@ Output 2024-12-20: Some more things not yet handled for you: - o P directives are not converted automatically - convert those yourself + o P directives are not converted automatically - convert those your- + self. - o Balance assignments are not converted (Beancount doesnt support them) - - replace those with explicit amounts + o Balance assignments are not converted (Beancount doesn't support + them) - replace those with explicit amounts. Beancount account names Aside from the top-level names, hledger will adjust your account names @@ -1184,7 +1180,8 @@ Journal 2024-02-01 note some event, or a transaction not yet fully entered, on this date ; Postings are not required. - ; Some other date formats are allowed (but, consistent YYYY-MM-DD is useful). + # Consistent YYYY-MM-DD date format is recommended, + # but you can use . or / and omit leading zeros if you prefer. 2024.01.01 2024/1/1 @@ -1640,25 +1637,26 @@ Journal is when you reorder multiple postings on the same day, to the same ac- count, which have balance assertions; those will likely need updating. - Assertions and multiple included files - Multiple files included with the include directive are processed as if - concatenated into one file, preserving their order and the posting or- - der within each file. It means that balance assertions in later files - will see balance from earlier files. + Assertions and multiple files + If an account has transactions appearing in multiple files, balance as- + sertions can still work - but only if those files are part of a hierar- + chy made by include directives. - And if you have multiple postings to an account on the same day, split - across multiple files, and you want to assert the account's balance on - that day, you'll need to put the assertion in the right file - the last - one in the sequence, probably. + If the same files are specified with two -f options on the command + line, the assertions in the second will not see the balances from the + first. - Assertions and multiple -f files - Unlike include, when multiple files are specified on the command line - with multiple -f/--file options, balance assertions will not see bal- - ance from earlier files. This can be useful when you do not want prob- - lems in earlier files to disrupt valid assertions in later files. + To work around this, arrange your files in a hierarchy with include. + Or, you could concatenate the files temporarily, and process them like + one big file. - If you do want assertions to see balance from earlier files, use in- - clude, or concatenate the files temporarily. + Why does it work this way ? It might be related to hledger's goal of + stable predictable reports. File hierarchy is considered "permanent", + part of your data, while the order of command line options/arguments is + not. We don't want transient changes to be able to change the meaning + of the data. Eg it would be frustrating if tomorrow all your balance + assertions broke because you wrote command line arguments in a differ- + ent order. (Discussion welcome.) Assertions and costs Balance assertions ignore costs, and should normally be written without @@ -1667,20 +1665,20 @@ Journal 2019/1/1 (a) $1 @ 1 = $1 - We do allow costs to be written in balance assertion amounts, however, - and print shows them, but they don't affect whether the assertion - passes or fails. This is for backward compatibility (hledger's close - command used to generate balance assertions with costs), and because + We do allow costs to be written in balance assertion amounts, however, + and print shows them, but they don't affect whether the assertion + passes or fails. This is for backward compatibility (hledger's close + command used to generate balance assertions with costs), and because balance assignments do use costs (see below). Assertions and commodities - The balance assertions described so far are "single commodity balance + The balance assertions described so far are "single commodity balance assertions": they assert and check the balance in one commodity, ignor- - ing any others that may be present. This is how balance assertions + ing any others that may be present. This is how balance assertions work in Ledger also. - If an account contains multiple commodities, you can assert their bal- - ances by writing multiple postings with balance assertions, one for + If an account contains multiple commodities, you can assert their bal- + ances by writing multiple postings with balance assertions, one for each commodity: 2013/1/1 @@ -1692,8 +1690,8 @@ Journal both 0 = $1 both 0 = 1 - In hledger you can make a stronger "sole commodity balance assertion" - by writing two equals signs (== EXPECTEDBALANCE). This also asserts + In hledger you can make a stronger "sole commodity balance assertion" + by writing two equals signs (== EXPECTEDBALANCE). This also asserts that there are no other commodities in the account besides the asserted one (or at least, that their current balance is zero): @@ -1703,12 +1701,12 @@ Journal both ;== $1 ; this one would fail because 'both' contains $ and It's less easy to make a "sole commodities balance assertion" (note the - plural) - ie, asserting that an account contains two or more specified + plural) - ie, asserting that an account contains two or more specified commodities and no others. It can be done by 1. isolating each commodity in a subaccount, and asserting those - 2. and also asserting there are no commodities in the parent account + 2. and also asserting there are no commodities in the parent account itself: 2013/1/1 @@ -1720,10 +1718,10 @@ Journal Assertions and subaccounts All of the balance assertions above (both = and ==) are "subaccount-ex- - clusive balance assertions"; they ignore any balances that exist in + clusive balance assertions"; they ignore any balances that exist in deeper subaccounts. - In hledger you can make "subaccount-inclusive balance assertions" by + In hledger you can make "subaccount-inclusive balance assertions" by adding a star after the equals (=* or ==*): 2019/1/1 @@ -1733,8 +1731,8 @@ Journal assets $0 ==* $20 ; assets + subaccounts contains $20 and nothing else Assertions and status - Balance assertions always consider postings of all statuses (unmarked, - pending, or cleared); they are not affected by the -U/--unmarked / + Balance assertions always consider postings of all statuses (unmarked, + pending, or cleared); they are not affected by the -U/--unmarked / -P/--pending / -C/--cleared flags or the status: query. Assertions and virtual postings @@ -1742,10 +1740,10 @@ Journal are not affected by the --real/-R flag or real: query. Assertions and auto postings - Balance assertions are affected by the --auto flag, which generates + Balance assertions are affected by the --auto flag, which generates auto postings, which can alter account balances. Because auto postings are optional in hledger, accounts affected by them effectively have two - balances. But balance assertions can only test one or the other of + balances. But balance assertions can only test one or the other of these. So to avoid making fragile assertions, either: o assert the balance calculated with --auto, and always use --auto with @@ -1758,11 +1756,26 @@ Journal avoid auto postings entirely). Assertions and precision - Balance assertions compare the exactly calculated amounts, which are - not always what is shown by reports. Eg a commodity directive may - limit the display precision, but this will not affect balance asser- + Balance assertions compare the exactly calculated amounts, which are + not always what is shown by reports. Eg a commodity directive may + limit the display precision, but this will not affect balance asser- tions. Balance assertion failure messages show exact amounts. + Assertions and hledger add + Balance assertions can be included in the amounts given in add. All + types of assertions are supported, and assertions can be used as in a + normal journal file. + + All transactions, not just those that have an explicit assertion, are + validated against the existing assertions in the journal. This means + it is possible for an added transaction to fail even if its assertions + are correct as of the transaction date. + + If this assertion checking is not desired, then it can be disabled with + -I. + + However, balance assignments are currently not supported. + Posting comments Text following ;, at the end of a posting line, and/or on indented lines immediately below it, form comments for that posting. They are @@ -2120,38 +2133,33 @@ Journal the other. Account types - hledger knows that accounts come in several types: assets, liabilities, - expenses and so on. This enables easy reports like balancesheet and - incomestatement, and filtering by account type with the type: query. + hledger knows that in accounting there are three main account types: - As a convenience, hledger will detect these account types automatically - if you are using common english-language top-level account names (de- - scribed below). But it's more robust to declare accounts' types ex- - plicitly, by adding type: tags to their account directives. The tag's - value should be one of the five main account types: + Asset A things you own + Liability L things you owe + Equity E owner's investment, + balances the two + above - o A or Asset (things you own) + and two more representing changes in these: - o L or Liability (things you owe) + Revenue R inflows (also known + as Income) + Expense X outflows - o E or Equity (investment/ownership; balanced counterpart of assets & - liabilities) + hledger also uses a couple of subtypes: - o R or Revenue (what you received money from, AKA income; technically - part of Equity) + Cash C liquid assets + Conversion V commodity conver- + sions equity - o X or Expense (what you spend money on; technically part of Equity) + As a convenience, hledger will detect these types automatically from + english account names. But it's better to declare them explicitly by + adding a type: tag in the account directives. The tag's value can be + any of the types or one-letter abbreviations above. - or, it can be (these are used less often): - - o C or Cash (a subtype of Asset, indicating liquid assets for the cash- - flow report) - - o V or Conversion (a subtype of Equity, for conversions (see Cost re- - porting).) - - Subaccounts inherit their parent's type, or they can override it. Here - is a typical set of account type declarations: + Here is a typical set of account type declarations. Subaccounts will + inherit their parent's type, or can override it: account assets ; type: A account liabilities ; type: L @@ -2164,14 +2172,25 @@ Journal account equity:conversion ; type: V - Here are some tips for working with account types. + This enables the easy balancesheet, balancesheetequity, cashflow and + incomestatement reports, and querying by type:. - o The rules for inferring types from account names are as follows. - These are just a convenience that sometimes help new users get going; - if they don't work for you, just ignore them and declare your account - types. See also Regular expressions. + Tips: - If account's name contains this (CI) regular expression: | its type is: + o You can list accounts and their types, for troubleshooting: + + $ hledger accounts --types [ACCTPAT] [type:TYPECODES] [-DEPTH] [--positions] + + o It's a good idea to declare at least one account for each account + type. Having some types declared and some inferred can disrupt cer- + tain reports. + + o The rules for inferring types from account names are as follows (us- + ing Regular expressions). + If they don't work for you, just ignore them and declare your types + with type: tags. + + If account's name contains this case insensitive regular expression | its type is --------------------------------------------------------------------|------------- ^assets?(:.+)?:(cash|bank|che(ck|que?)(ing)?|savings?|current)(:|$) | Cash ^assets?(:|$) | Asset @@ -2181,16 +2200,9 @@ Journal ^(income|revenue)s?(:|$) | Revenue ^expenses?(:|$) | Expense - o If you declare any account types, it's a good idea to declare an ac- - count for all of the account types, because a mixture of declared and - name-inferred types can disrupt certain reports. - - o Certain uses of account aliases can disrupt account types. See - Rewriting accounts > Aliases and account types. - o As mentioned above, subaccounts will inherit a type from their parent - account. More precisely, an account's type is decided by the first - of these that exists: + account. To be precise, an account's type is decided by the first of + these that exists: 1. A type: declaration for this account. @@ -2204,9 +2216,7 @@ Journal 5. Otherwise, it will have no type. - o For troubleshooting, you can list accounts and their types with: - - $ hledger accounts --types [ACCTPAT] [-DEPTH] [type:TYPECODES] + o Account aliases can disrupt account types. alias directive You can define account alias rules which rewrite your account names, or @@ -3164,29 +3174,28 @@ Journal o and rejects the rest. CSV - hledger can read CSV files (Character Separated Value - usually comma, - semicolon, or tab) containing dated records, automatically converting - each record into a transaction. + hledger can read transactions from CSV (comma-separated values) files. + More precisely, it can read DSV (delimiter-separated values), from a + file or standard input. Comma-separated, semicolon-separated and + tab-separated are the most common variants, and hledger will recognise + these three automatically based on a .csv, .ssv or .tsv file name ex- + tension or a csv:, ssv: or tsv: file path prefix. - (To learn about writing CSV, see CSV output.) + (To learn about producing CSV or TSV output, see Output format.) - For best error messages when reading CSV/TSV/SSV files, make sure they - have a corresponding .csv, .tsv or .ssv file extension or use a hledger - file prefix (see File Extension below). + Each CSV file must be described by a corresponding rules file. This + contains rules describing the CSV data (header line, fields layout, + date format etc.), how to construct hledger transactions from it, and + how to categorise transactions based on description or other attrib- + utes. - Each CSV file must be described by a corresponding rules file. - This contains rules describing the CSV data (header line, fields lay- - out, date format etc.), how to construct hledger transactions from it, - and how to categorise transactions based on description or other at- - tributes. - - By default, hledger expects this rules file to be named like the CSV - file, with an extra .rules extension added, in the same directory. Eg - when asked to read foo/FILE.csv, hledger looks for foo/FILE.csv.rules. + By default, hledger expects this rules file to be named like the CSV + file, with an extra .rules extension added, in the same directory. Eg + when asked to read foo/FILE.csv, hledger looks for foo/FILE.csv.rules. You can specify a different rules file with the --rules option. - At minimum, the rules file must identify the date and amount fields, - and often it also specifies the date format and how many header lines + At minimum, the rules file must identify the date and amount fields, + and often it also specifies the date format and how many header lines there are. Here's a simple CSV file and a rules file for it: Date, Description, Id, Amount @@ -3202,7 +3211,7 @@ CSV expenses:unknown 10.23 income:unknown -10.23 - There's an introductory Importing CSV data tutorial on hledger.org, and + There's an introductory Tutorial: Import CSV data on hledger.org, and more CSV rules examples below, and a larger collection at https://github.com/simonmichael/hledger/tree/master/examples/csv. @@ -3269,24 +3278,28 @@ CSV encoding encoding ENCODING - hledger normally expects non-ascii text to be UTF8-encoded. If you - need to read CSV files which have some other encoding, you can do it by - adding encoding ENCODING to your CSV rules. Eg: encoding ISO88591. + hledger normally expects non-ascii text to be using the system locale's + text encoding. If you need to read CSV files which have some other en- + coding, you can do it by adding encoding ENCODING to your CSV rules. + Eg: encoding iso-8859-1. - The following encodings are supported (these names are case-insensi- - tive, and can be written with inner spaces or hyphens if you prefer): - ASCII, UTF8, UTF16, UTF32, ISO88591, ISO88592, ISO88593, ISO88594, - ISO88595, ISO88596, ISO88597, ISO88598, ISO88599, ISO885910, ISO885911, - ISO885913, ISO885914, ISO885915, ISO885916, CP1250, CP1251, CP1252, - CP1253, CP1254, CP1255, CP1256, CP1257, CP1258, KOI8R, KOI8U, GB18030, - MacOSRoman, JISX0201, JISX0208, ISO2022JP, ShiftJIS, CP437, CP737, - CP775, CP850, CP852, CP855, CP857, CP860, CP861, CP862, CP863, CP864, - CP865, CP866, CP869, CP874, CP932. + The following encodings are supported: + + ascii, utf-8, utf-16, utf-32, iso-8859-1, iso-8859-2, iso-8859-3, + iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, + iso-8859-10, iso-8859-11, iso-8859-13, iso-8859-14, iso-8859-15, + iso-8859-16, cp1250, cp1251, cp1252, cp1253, cp1254, cp1255, cp1256, + cp1257, cp1258, koi8-r, koi8-u, gb18030, macintosh, jis-x-0201, + jis-x-0208, iso-2022-jp, shift-jis, cp437, cp737, cp775, cp850, cp852, + cp855, cp857, cp860, cp861, cp862, cp863, cp864, cp865, cp866, cp869, + cp874, cp932. + + Added in 1.42. separator - You can use the separator rule to read other kinds of character-sepa- - rated data. The argument is any single separator character, or the - words tab or space (case insensitive). Eg, for comma-separated values + You can use the separator rule to read other kinds of character-sepa- + rated data. The argument is any single separator character, or the + words tab or space (case insensitive). Eg, for comma-separated values (CSV): separator , @@ -3299,32 +3312,32 @@ CSV separator TAB - If the input file has a .csv, .ssv or .tsv file extension (or a csv:, + If the input file has a .csv, .ssv or .tsv file extension (or a csv:, ssv:, tsv: prefix), the appropriate separator will be inferred automat- ically, and you won't need this rule. skip skip N - The word skip followed by a number (or no number, meaning 1) tells - hledger to ignore this many non-empty lines at the start of the input - data. You'll need this whenever your CSV data contains header lines. - Note, empty and blank lines are skipped automatically, so you don't + The word skip followed by a number (or no number, meaning 1) tells + hledger to ignore this many non-empty lines at the start of the input + data. You'll need this whenever your CSV data contains header lines. + Note, empty and blank lines are skipped automatically, so you don't need to count those. - skip has a second meaning: it can be used inside if blocks (described - below), to skip one or more records whenever the condition is true. + skip has a second meaning: it can be used inside if blocks (described + below), to skip one or more records whenever the condition is true. Records skipped in this way are ignored, except they are still required to be valid CSV. date-format date-format DATEFMT - This is a helper for the date (and date2) fields. If your CSV dates - are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll - need to add a date-format rule describing them with a strptime-style - date parsing pattern - see https://hackage.haskell.org/pack- - age/time/docs/Data-Time-Format.html#v:formatTime. The pattern must + This is a helper for the date (and date2) fields. If your CSV dates + are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll + need to add a date-format rule describing them with a strptime-style + date parsing pattern - see https://hackage.haskell.org/pack- + age/time/docs/Data-Time-Format.html#v:formatTime. The pattern must parse the CSV date value completely. Some examples: # MM/DD/YY @@ -3344,33 +3357,33 @@ CSV timezone timezone TIMEZONE - When CSV contains date-times that are implicitly in some time zone + When CSV contains date-times that are implicitly in some time zone other than yours, but containing no explicit time zone information, you - can use this rule to declare the CSV's native time zone, which helps + can use this rule to declare the CSV's native time zone, which helps prevent off-by-one dates. - When the CSV date-times do contain time zone information, you don't - need this rule; instead, use %Z in date-format (or %z, %EZ, %Ez; see + When the CSV date-times do contain time zone information, you don't + need this rule; instead, use %Z in date-format (or %z, %EZ, %Ez; see the formatTime link above). In either of these cases, hledger will do a time-zone-aware conversion, localising the CSV date-times to your current system time zone. If you prefer to localise to some other time zone, eg for reproducibility, you - can (on unix at least) set the output timezone with the TZ environment + can (on unix at least) set the output timezone with the TZ environment variable, eg: $ TZ=-1000 hledger print -f foo.csv # or TZ=-1000 hledger import foo.csv - timezone currently does not understand timezone names, except "UTC", - "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", or "PDT". For + timezone currently does not understand timezone names, except "UTC", + "GMT", "EST", "EDT", "CST", "CDT", "MST", "MDT", "PST", or "PDT". For others, use numeric format: +HHMM or -HHMM. newest-first hledger tries to ensure that the generated transactions will be ordered chronologically, including same-day transactions. Usually it can - auto-detect how the CSV records are ordered. But if it encounters CSV + auto-detect how the CSV records are ordered. But if it encounters CSV where all records are on the same date, it assumes that the records are - oldest first. If in fact the CSV's records are normally newest first, + oldest first. If in fact the CSV's records are normally newest first, like: 2022-10-01, txn 3... @@ -3384,9 +3397,9 @@ CSV newest-first intra-day-reversed - If CSV records within a single day are ordered opposite to the overall - record order, you can add the intra-day-reversed rule to improve the - order of journal entries. Eg, here the overall record order is newest + If CSV records within a single day are ordered opposite to the overall + record order, you can add the intra-day-reversed rule to improve the + order of journal entries. Eg, here the overall record order is newest first, but same-day records are oldest first: 2022-10-02, txn 3... @@ -3404,10 +3417,10 @@ CSV decimal-mark , - hledger automatically accepts either period or comma as a decimal mark - when parsing numbers (cf Amounts). However if any numbers in the CSV - contain digit group marks, such as thousand-separating commas, you - should declare the decimal mark explicitly with this rule, to avoid + hledger automatically accepts either period or comma as a decimal mark + when parsing numbers (cf Amounts). However if any numbers in the CSV + contain digit group marks, such as thousand-separating commas, you + should declare the decimal mark explicitly with this rule, to avoid misparsed numbers. fields list @@ -3416,17 +3429,17 @@ CSV A fields list (the word fields followed by comma-separated field names) is optional, but convenient. It does two things: - 1. It names the CSV field in each column. This can be convenient if - you are referencing them in other rules, so you can say %SomeField + 1. It names the CSV field in each column. This can be convenient if + you are referencing them in other rules, so you can say %SomeField instead of remembering %13. - 2. Whenever you use one of the special hledger field names (described - below), it assigns the CSV value in this position to that hledger - field. This is the quickest way to populate hledger's fields and + 2. Whenever you use one of the special hledger field names (described + below), it assigns the CSV value in this position to that hledger + field. This is the quickest way to populate hledger's fields and build a transaction. - Here's an example that says "use the 1st, 2nd and 4th fields as the - transaction's date, description and amount; name the last two fields + Here's an example that says "use the 1st, 2nd and 4th fields as the + transaction's date, description and amount; name the last two fields for later reference; and ignore the others": fields date, description, , amount, , , somefield, anotherfield @@ -3436,35 +3449,35 @@ CSV o There must be least two items in the list (at least one comma). - o Field names may not contain spaces. Spaces before/after field names + o Field names may not contain spaces. Spaces before/after field names are optional. o Field names may contain _ (underscore) or - (hyphen). - o Fields you don't care about can be given a dummy name or an empty + o Fields you don't care about can be given a dummy name or an empty name. - If the CSV contains column headings, it's convenient to use these for - your field names, suitably modified (eg lower-cased with spaces re- + If the CSV contains column headings, it's convenient to use these for + your field names, suitably modified (eg lower-cased with spaces re- placed by underscores). - Sometimes you may want to alter a CSV field name to avoid assigning to - a hledger field with the same name. Eg you could call the CSV's "bal- - ance" field balance_ to avoid directly setting hledger's balance field + Sometimes you may want to alter a CSV field name to avoid assigning to + a hledger field with the same name. Eg you could call the CSV's "bal- + ance" field balance_ to avoid directly setting hledger's balance field (and generating a balance assertion). Field assignment HLEDGERFIELD FIELDVALUE - Field assignments are the more flexible way to assign CSV values to + Field assignments are the more flexible way to assign CSV values to hledger fields. They can be used instead of or in addition to a fields list (see above). - To assign a value to a hledger field, write the field name (any of the - standard hledger field/pseudo-field names, defined below), a space, - followed by a text value on the same line. This text value may inter- - polate CSV fields, referenced either by their 1-based position in the - CSV record (%N) or by the name they were given in the fields list + To assign a value to a hledger field, write the field name (any of the + standard hledger field/pseudo-field names, defined below), a space, + followed by a text value on the same line. This text value may inter- + polate CSV fields, referenced either by their 1-based position in the + CSV record (%N) or by the name they were given in the fields list (%CSVFIELD), and regular expression match groups (\N). Some examples: @@ -3477,26 +3490,26 @@ CSV Tips: - o Interpolation strips outer whitespace (so a CSV value like " 1 " be- + o Interpolation strips outer whitespace (so a CSV value like " 1 " be- comes 1 when interpolated) (#1051). - o Interpolations always refer to a CSV field - you can't interpolate a + o Interpolations always refer to a CSV field - you can't interpolate a hledger field. (See Referencing other fields below). Field names - Note the two kinds of field names mentioned here, and used only in + Note the two kinds of field names mentioned here, and used only in hledger CSV rules files: - 1. CSV field names (CSVFIELD in these docs): you can optionally name - the CSV columns for easy reference (since hledger doesn't yet auto- + 1. CSV field names (CSVFIELD in these docs): you can optionally name + the CSV columns for easy reference (since hledger doesn't yet auto- matically recognise column headings in a CSV file), by writing arbi- trary names in a fields list, eg: fields When, What, Some_Id, Net, Total, Foo, Bar - 2. Special hledger field names (HLEDGERFIELD in these docs): you must - set at least some of these to generate the hledger transaction from - a CSV record, by writing them as the left hand side of a field as- + 2. Special hledger field names (HLEDGERFIELD in these docs): you must + set at least some of these to generate the hledger transaction from + a CSV record, by writing them as the left hand side of a field as- signment, eg: date %When @@ -3511,7 +3524,7 @@ CSV currency $ comment %Foo %Bar - Here are all the special hledger field names available, and what hap- + Here are all the special hledger field names available, and what hap- pens when you assign values to them: date field @@ -3534,7 +3547,7 @@ CSV commentN, where N is a number, sets the Nth posting's comment. - You can assign multi-line comments by writing literal \n in the code. + You can assign multi-line comments by writing literal \n in the code. A comment starting with \n will begin on a new line. Comments can contain tags, as usual. @@ -3546,99 +3559,99 @@ CSV Assigning to accountN, where N is 1 to 99, sets the account name of the Nth posting, and causes that posting to be generated. - Most often there are two postings, so you'll want to set account1 and - account2. Typically account1 is associated with the CSV file, and is - set once with a top-level assignment, while account2 is set based on + Most often there are two postings, so you'll want to set account1 and + account2. Typically account1 is associated with the CSV file, and is + set once with a top-level assignment, while account2 is set based on each transaction's description, in conditional rules. - If a posting's account name is left unset but its amount is set (see - below), a default account name will be chosen (like "expenses:unknown" + If a posting's account name is left unset but its amount is set (see + below), a default account name will be chosen (like "expenses:unknown" or "income:unknown"). amount field - There are several ways to set posting amounts from CSV, useful in dif- + There are several ways to set posting amounts from CSV, useful in dif- ferent situations. - 1. amount is the oldest and simplest. Assigning to this sets the + 1. amount is the oldest and simplest. Assigning to this sets the amount of the first and second postings. In the second posting, the - amount will be negated; also, if it has a cost attached, it will be + amount will be negated; also, if it has a cost attached, it will be converted to cost. - 2. amount-in and amount-out work exactly like the above, but should be - used when the CSV has two amount fields (such as "Debit" and + 2. amount-in and amount-out work exactly like the above, but should be + used when the CSV has two amount fields (such as "Debit" and "Credit", or "Inflow" and "Outflow"). Whichever field has a - non-zero value will be used as the amount of the first and second + non-zero value will be used as the amount of the first and second postings. Here are some tips to avoid confusion: - o It's not "amount-in for posting 1 and amount-out for posting 2", - it is "extract a single amount from the amount-in or amount-out + o It's not "amount-in for posting 1 and amount-out for posting 2", + it is "extract a single amount from the amount-in or amount-out field, and use that for posting 1 and (negated) for posting 2". - o Don't use both amount and amount-in/amount-out in the same rules + o Don't use both amount and amount-in/amount-out in the same rules file; choose based on whether the amount is in a single CSV field or spread across two fields. - o In each record, at most one of the two CSV fields should contain - a non-zero amount; the other field must contain a zero or noth- + o In each record, at most one of the two CSV fields should contain + a non-zero amount; the other field must contain a zero or noth- ing. - o hledger assumes both CSV fields contain unsigned numbers, and it + o hledger assumes both CSV fields contain unsigned numbers, and it automatically negates the amount-out values. - o If the data doesn't fit these requirements, you'll probably need + o If the data doesn't fit these requirements, you'll probably need an if rule (see below). 3. amountN (where N is a number from 1 to 99) sets the amount of only a - single posting: the Nth posting in the transaction. You'll usually - need at least two such assignments to make a balanced transaction. + single posting: the Nth posting in the transaction. You'll usually + need at least two such assignments to make a balanced transaction. You can also generate more than two postings, to represent more com- - plex transactions. The posting numbers don't have to be consecu- - tive; with if rules, higher posting numbers can be useful to ensure + plex transactions. The posting numbers don't have to be consecu- + tive; with if rules, higher posting numbers can be useful to ensure a certain order of postings. - 4. amountN-in and amountN-out work exactly like the above, but should - be used when the CSV has two amount fields. This is analogous to + 4. amountN-in and amountN-out work exactly like the above, but should + be used when the CSV has two amount fields. This is analogous to amount-in and amount-out, and those tips also apply here. 5. Remember that a fields list can also do assignments. So in a fields - list if you name a CSV field "amount", that counts as assigning to - amount. (If you don't want that, call it something else in the + list if you name a CSV field "amount", that counts as assigning to + amount. (If you don't want that, call it something else in the fields list, like "amount_".) - 6. The above don't handle every situation; if you need more flexibil- + 6. The above don't handle every situation; if you need more flexibil- ity, use an if rule to set amounts conditionally. See "Working with - CSV > Setting amounts" below for more on this and on amount-setting + CSV > Setting amounts" below for more on this and on amount-setting generally. currency field - currency sets a currency symbol, to be prepended to all postings' - amounts. You can use this if the CSV amounts do not have a currency + currency sets a currency symbol, to be prepended to all postings' + amounts. You can use this if the CSV amounts do not have a currency symbol, eg if it is in a separate column. currencyN prepends a currency symbol to just the Nth posting's amount. balance field - balanceN sets a balance assertion amount (or if the posting amount is + balanceN sets a balance assertion amount (or if the posting amount is left empty, a balance assignment) on posting N. balance is a compatibility spelling for hledger <1.17; it is equivalent to balance1. - You can adjust the type of assertion/assignment with the balance-type + You can adjust the type of assertion/assignment with the balance-type rule (see below). - See the Working with CSV tips below for more about setting amounts and + See the Working with CSV tips below for more about setting amounts and currency. if block - Rules can be applied conditionally, depending on patterns in the CSV - data. This allows flexibility; in particular, it is how you can cate- - gorise transactions, selecting an appropriate account name based on - their description (for example). There are two ways to write condi- - tional rules: "if blocks", described here, and "if tables", described + Rules can be applied conditionally, depending on patterns in the CSV + data. This allows flexibility; in particular, it is how you can cate- + gorise transactions, selecting an appropriate account name based on + their description (for example). There are two ways to write condi- + tional rules: "if blocks", described here, and "if tables", described below. - An if block is the word if and one or more "matcher" expressions (can + An if block is the word if and one or more "matcher" expressions (can be a word or phrase), one per line, starting either on the same or next line; followed by one or more indented rules. Eg, @@ -3654,11 +3667,11 @@ CSV RULE RULE - If any of the matchers succeeds, all of the indented rules will be ap- - plied. They are usually field assignments, but the following special + If any of the matchers succeeds, all of the indented rules will be ap- + plied. They are usually field assignments, but the following special rules may also be used within an if block: - o skip - skips the matched CSV record (generating no transaction from + o skip - skips the matched CSV record (generating no transaction from it) o end - skips the rest of the current CSV file. @@ -3684,39 +3697,39 @@ CSV Matchers There are two kinds of matcher: - 1. A whole record matcher is simplest: it is just a word, single-line - text fragment, or other regular expression, which hledger will try + 1. A whole record matcher is simplest: it is just a word, single-line + text fragment, or other regular expression, which hledger will try to match case-insensitively anywhere within the CSV record. Eg: whole foods. - 2. A field matcher has a percent-prefixed CSV field number or name be- + 2. A field matcher has a percent-prefixed CSV field number or name be- fore the pattern. Eg: %3 whole foods or %description whole foods. hledger will try to match the pattern just within the named CSV field. When using these, there's two things to be aware of: - 1. Whole record matchers don't see the exact original record; they see - a reconstruction of it, in which values are comma-separated, and - quotes enclosing values and whitespace outside those quotes are re- + 1. Whole record matchers don't see the exact original record; they see + a reconstruction of it, in which values are comma-separated, and + quotes enclosing values and whitespace outside those quotes are re- moved. Eg when reading an SSV record like: 2023-01-01 ; "Acme, Inc. " ; 1,000 the whole record matcher sees instead: 2023-01-01,Acme, Inc. ,1,000 2. Field matchers expect either a CSV field number, or a CSV field name - declared with fields. (Don't use a hledger field name here, unless - it is also a CSV field name.) A non-CSV field name will cause the - matcher to match against "" (the empty string), and does not raise - an error, allowing easier reuse of common rules with different CSV + declared with fields. (Don't use a hledger field name here, unless + it is also a CSV field name.) A non-CSV field name will cause the + matcher to match against "" (the empty string), and does not raise + an error, allowing easier reuse of common rules with different CSV files. You can also prefix a matcher with ! (and optional space) to negate it. - Eg ! whole foods, ! %3 whole foods, !%description whole foods will + Eg ! whole foods, ! %3 whole foods, !%description whole foods will match if "whole foods" is NOT present. Added in 1.32. - The pattern is, as usual in hledger, a POSIX extended regular expres- - sion that also supports GNU word boundaries (\b, \B, \<, \>) and noth- - ing else. If you have trouble with it, see "Regular expressions" in + The pattern is, as usual in hledger, a POSIX extended regular expres- + sion that also supports GNU word boundaries (\b, \B, \<, \>) and noth- + ing else. If you have trouble with it, see "Regular expressions" in the hledger manual (https://hledger.org/hledger.html#regular-expres- sions). @@ -3725,28 +3738,28 @@ CSV o By default they are OR'd (any of them can match). - o Matcher lines beginning with & (or &&, since 1.42) are AND'ed with + o Matcher lines beginning with & (or &&, since 1.42) are AND'ed with the matcher above (all in the AND'ed group must match). - o Matcher lines beginning with & ! (since 1.41, or && !, since 1.42) + o Matcher lines beginning with & ! (since 1.41, or && !, since 1.42) are first negated and then AND'ed with the matcher above. - You can also combine multiple matchers one the same line separated by + You can also combine multiple matchers one the same line separated by && (AND) or && ! (AND NOT). Eg %description amazon && %date 2025-01-01 - will match only when the description field contains "amazon" and the + will match only when the description field contains "amazon" and the date field contains "2025-01-01". Added in 1.42. Match groups Added in 1.32 Matchers can define match groups: parenthesised portions of the regular - expression which are available for reference in field assignments. + expression which are available for reference in field assignments. Groups are enclosed in regular parentheses (( and )) and can be nested. - Each group is available in field assignments using the token \N, where - N is an index into the match groups for this conditional block (e.g. + Each group is available in field assignments using the token \N, where + N is an index into the match groups for this conditional block (e.g. \1, \2, etc.). - Example: Warp credit card payment postings to the beginning of the + Example: Warp credit card payment postings to the beginning of the billing period (Month start), to match how they are presented in state- ments, using posting dates: @@ -3760,8 +3773,8 @@ CSV account1 \1 if table - "if tables" are an alternative to if blocks; they can express many - matchers and field assignments in a more compact tabular format, like + "if tables" are an alternative to if blocks; they can express many + matchers and field assignments in a more compact tabular format, like this: if,HLEDGERFIELD1,HLEDGERFIELD2,... @@ -3772,21 +3785,21 @@ CSV The first character after if is taken to be this if table's field sepa- - rator. It is unrelated to the separator used in the CSV file. It + rator. It is unrelated to the separator used in the CSV file. It should be a non-alphanumeric character like , or | that does not appear - anywhere else in the table (it should not be used in field names or + anywhere else in the table (it should not be used in field names or matchers or values, and it cannot be escaped with a backslash). - Each line must contain the same number of separators; empty values are - allowed. Whitespace can be used in the matcher lines for readability - (but not in the if line, currently). You can use the comment lines in - the table body. The table must be terminated by an empty line (or end + Each line must contain the same number of separators; empty values are + allowed. Whitespace can be used in the matcher lines for readability + (but not in the if line, currently). You can use the comment lines in + the table body. The table must be terminated by an empty line (or end of file). - An if table like the above is interpreted as follows: try all of the + An if table like the above is interpreted as follows: try all of the lines with matchers; whenever a line with matchers succeeds, assign all of the values on that line to the corresponding hledger fields; If mul- - tiple lines match, later lines will override fields assigned by the + tiple lines match, later lines will override fields assigned by the earlier ones - just like the sequence of if blocks would behave. If table presented above is equivalent to this sequence of if blocks: @@ -3817,10 +3830,10 @@ CSV balance-type Balance assertions generated by assigning to balanceN are of the simple - = type by default, which is a single-commodity, subaccount-excluding + = type by default, which is a single-commodity, subaccount-excluding assertion. You may find the subaccount-including variants more useful, - eg if you have created some virtual subaccounts of checking to help - with budgeting. You can select a different type of assertion with the + eg if you have created some virtual subaccounts of checking to help + with budgeting. You can select a different type of assertion with the balance-type rule: # balance assertions will consider all commodities and all subaccounts @@ -3836,9 +3849,9 @@ CSV include include RULESFILE - This includes the contents of another CSV rules file at this point. - RULESFILE is an absolute file path or a path relative to the current - file's directory. This can be useful for sharing common rules between + This includes the contents of another CSV rules file at this point. + RULESFILE is an absolute file path or a path relative to the current + file's directory. This can be useful for sharing common rules between several rules files, eg: # someaccount.csv.rules @@ -3855,42 +3868,42 @@ CSV Some tips: Rapid feedback - It's a good idea to get rapid feedback while creating/troubleshooting + It's a good idea to get rapid feedback while creating/troubleshooting CSV rules. Here's a good way, using entr from eradman.com/entrproject: $ ls foo.csv* | entr bash -c 'echo ----; hledger -f foo.csv print desc:SOMEDESC' - A desc: query (eg) is used to select just one, or a few, transactions - of interest. "bash -c" is used to run multiple commands, so we can - echo a separator each time the command re-runs, making it easier to + A desc: query (eg) is used to select just one, or a few, transactions + of interest. "bash -c" is used to run multiple commands, so we can + echo a separator each time the command re-runs, making it easier to read the output. Valid CSV - Note that hledger will only accept valid CSV conforming to RFC 4180, + Note that hledger will only accept valid CSV conforming to RFC 4180, and equivalent SSV and TSV formats (like RFC 4180 but with semicolon or tab as separators). This means, eg: o Values may be enclosed in double quotes, or not. Enclosing in single quotes is not allowed. (Eg 'A','B' is rejected.) - o When values are enclosed in double quotes, spaces outside the quotes + o When values are enclosed in double quotes, spaces outside the quotes are not allowed. (Eg "A", "B" is rejected.) - o When values are not enclosed in quotes, they may not contain double + o When values are not enclosed in quotes, they may not contain double quotes. (Eg A"A, B is rejected.) - If your CSV/SSV/TSV is not valid in this sense, you'll need to trans- - form it before reading with hledger. Try using sed, or a more permis- + If your CSV/SSV/TSV is not valid in this sense, you'll need to trans- + form it before reading with hledger. Try using sed, or a more permis- sive CSV parser like python's csv lib. File Extension - To help hledger choose the CSV file reader and show the right error - messages (and choose the right field separator character by default), - it's best if CSV/SSV/TSV files are named with a .csv, .ssv or .tsv + To help hledger choose the CSV file reader and show the right error + messages (and choose the right field separator character by default), + it's best if CSV/SSV/TSV files are named with a .csv, .ssv or .tsv filename extension. (More about this at Data formats.) - When reading files with the "wrong" extension, you can ensure the CSV - reader (and the default field separator) by prefixing the file path + When reading files with the "wrong" extension, you can ensure the CSV + reader (and the default field separator) by prefixing the file path with csv:, ssv: or tsv:: Eg: $ hledger -f ssv:foo.dat print @@ -3899,29 +3912,29 @@ CSV if needed. Reading CSV from standard input - You'll need the file format prefix when reading CSV from stdin also, + You'll need the file format prefix when reading CSV from stdin also, since hledger assumes journal format by default. Eg: $ cat foo.dat | hledger -f ssv:- print Reading multiple CSV files - If you use multiple -f options to read multiple CSV files at once, - hledger will look for a correspondingly-named rules file for each CSV - file. But if you specify a rules file with --rules, that rules file + If you use multiple -f options to read multiple CSV files at once, + hledger will look for a correspondingly-named rules file for each CSV + file. But if you specify a rules file with --rules, that rules file will be used for all the CSV files. Reading files specified by rule Instead of specifying a CSV file in the command line, you can specify a - rules file, as in hledger -f foo.csv.rules CMD. By default this will - read data from foo.csv in the same directory, but you can add a source - rule to specify a different data file, perhaps located in your web + rules file, as in hledger -f foo.csv.rules CMD. By default this will + read data from foo.csv in the same directory, but you can add a source + rule to specify a different data file, perhaps located in your web browser's download directory. This feature was added in hledger 1.30, so you won't see it in most CSV - rules examples. But it helps remove some of the busywork of managing + rules examples. But it helps remove some of the busywork of managing CSV downloads. Most of your financial institutions's default CSV file- - names are different and can be recognised by a glob pattern. So you - can put a rule like source Checking1*.csv in foo-checking.csv.rules, + names are different and can be recognised by a glob pattern. So you + can put a rule like source Checking1*.csv in foo-checking.csv.rules, and then periodically follow a workflow like: 1. Download CSV from Foo's website, using your browser's defaults @@ -3929,45 +3942,45 @@ CSV 2. Run hledger import foo-checking.csv.rules to import any new transac- tions - After import, you can: discard the CSV, or leave it where it is for a - while, or move it into your archives, as you prefer. If you do noth- - ing, next time your browser will save something like Checking1-2.csv, - and hledger will use that because of the * wild card and because it is + After import, you can: discard the CSV, or leave it where it is for a + while, or move it into your archives, as you prefer. If you do noth- + ing, next time your browser will save something like Checking1-2.csv, + and hledger will use that because of the * wild card and because it is the most recent. Valid transactions After reading a CSV file, hledger post-processes and validates the gen- erated journal entries as it would for a journal file - balancing them, - applying balance assignments, and canonicalising amount styles. Any - errors at this stage will be reported in the usual way, displaying the + applying balance assignments, and canonicalising amount styles. Any + errors at this stage will be reported in the usual way, displaying the problem entry. There is one exception: balance assertions, if you have generated them, - will not be checked, since normally these will work only when the CSV - data is part of the main journal. If you do need to check balance as- + will not be checked, since normally these will work only when the CSV + data is part of the main journal. If you do need to check balance as- sertions generated from CSV right away, pipe into another hledger: $ hledger -f file.csv print | hledger -f- print Deduplicating, importing - When you download a CSV file periodically, eg to get your latest bank - transactions, the new file may overlap with the old one, containing + When you download a CSV file periodically, eg to get your latest bank + transactions, the new file may overlap with the old one, containing some of the same records. The import command will (a) detect the new transactions, and (b) append just those transactions to your main journal. It is idempotent, so you - don't have to remember how many times you ran it or with which version - of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This + don't have to remember how many times you ran it or with which version + of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This is the easiest way to import CSV data. Eg: # download the latest CSV files, then run this command. # Note, no -f flags needed here. $ hledger import *.csv [--dry] - This method works for most CSV files. (Where records have a stable + This method works for most CSV files. (Where records have a stable chronological order, and new records appear only at the new end.) - A number of other tools and workflows, hledger-specific and otherwise, + A number of other tools and workflows, hledger-specific and otherwise, exist for converting, deduplicating, classifying and managing CSV data. See: @@ -3976,16 +3989,16 @@ CSV o https://plaintextaccounting.org -> data import/conversion Setting amounts - Continuing from amount field above, here are more tips for amount-set- + Continuing from amount field above, here are more tips for amount-set- ting: 1. If the amount is in a single CSV field: a. If its sign indicates direction of flow: - Assign it to amountN, to set the Nth posting's amount. N is usu- + Assign it to amountN, to set the Nth posting's amount. N is usu- ally 1 or 2 but can go up to 99. b. If another field indicates direction of flow: - Use one or more conditional rules to set the appropriate amount + Use one or more conditional rules to set the appropriate amount sign. Eg: # assume a withdrawal unless Type contains "deposit": @@ -3993,15 +4006,15 @@ CSV if %Type deposit amount1 %Amount - 2. If the amount is in two CSV fields (such as Debit and Credit, or In + 2. If the amount is in two CSV fields (such as Debit and Credit, or In and Out): a. If both fields are unsigned: - Assign one field to amountN-in and the other to amountN-out. - hledger will automatically negate the "out" field, and will use + Assign one field to amountN-in and the other to amountN-out. + hledger will automatically negate the "out" field, and will use whichever field value is non-zero as posting N's amount. b. If either field is signed: - You will probably need to override hledger's sign for one or the + You will probably need to override hledger's sign for one or the other field, as in the following example: # Negate the -out value, but only if it is not empty: @@ -4009,12 +4022,12 @@ CSV if %amount1-out [1-9] amount1-out -%amount1-out - c. If both fields can contain a non-zero value (or both can be + c. If both fields can contain a non-zero value (or both can be empty): - The -in/-out rules normally choose the value which is - non-zero/non-empty. Some value pairs can be ambiguous, such as 1 + The -in/-out rules normally choose the value which is + non-zero/non-empty. Some value pairs can be ambiguous, such as 1 and none. For such cases, use conditional rules to help select the - amount. Eg, to handle the above you could select the value con- + amount. Eg, to handle the above you could select the value con- taining non-zero digits: fields date, description, in, out @@ -4027,8 +4040,8 @@ CSV Use the unnumbered amount (or amount-in and amount-out) syntax. 4. If the CSV has only balance amounts, not transaction amounts: - Assign to balanceN, to set a balance assignment on the Nth posting, - causing the posting's amount to be calculated automatically. balance + Assign to balanceN, to set a balance assignment on the Nth posting, + causing the posting's amount to be calculated automatically. balance with no number is equivalent to balance1. In this situation hledger is more likely to guess the wrong default account name, so you may need to set that explicitly. @@ -4044,20 +4057,20 @@ CSV o If an amount value is parenthesised: it will be de-parenthesised and sign-flipped: (AMT) becomes -AMT - o If an amount value has two minus signs (or two sets of parentheses, + o If an amount value has two minus signs (or two sets of parentheses, or a minus sign and parentheses): they cancel out and will be removed: --AMT or -(AMT) becomes AMT - o If an amount value contains just a sign (or just a set of parenthe- + o If an amount value contains just a sign (or just a set of parenthe- ses): - that is removed, making it an empty value. "+" or "-" or "()" becomes + that is removed, making it an empty value. "+" or "-" or "()" becomes "". - It's not possible (without preprocessing the CSV) to set an amount to + It's not possible (without preprocessing the CSV) to set an amount to its absolute value, ie discard its sign. Setting currency/commodity - If the currency/commodity symbol is included in the CSV's amount + If the currency/commodity symbol is included in the CSV's amount field(s): 2023-01-01,foo,$123.00 @@ -4076,7 +4089,7 @@ CSV 2023-01-01,foo,USD,123.00 You can assign that to the currency pseudo-field, which has the special - effect of prepending itself to every amount in the transaction (on the + effect of prepending itself to every amount in the transaction (on the left, with no separating space): fields date,description,currency,amount @@ -4085,7 +4098,7 @@ CSV expenses:unknown USD123.00 income:unknown USD-123.00 - Or, you can use a field assignment to construct the amount yourself, + Or, you can use a field assignment to construct the amount yourself, with more control. Eg to put the symbol on the right, and separated by a space: @@ -4096,38 +4109,38 @@ CSV expenses:unknown 123.00 USD income:unknown -123.00 USD - Note we used a temporary field name (cur) that is not currency - that + Note we used a temporary field name (cur) that is not currency - that would trigger the prepending effect, which we don't want here. Amount decimal places - When you are reading CSV data, eg with a command like hledger -f - foo.csv print, hledger will infer each commodity's decimal precision - (and other commodity display styles) from the amounts - much as when + When you are reading CSV data, eg with a command like hledger -f + foo.csv print, hledger will infer each commodity's decimal precision + (and other commodity display styles) from the amounts - much as when reading a journal file without commodity directives (see the link). - Note, the commodity styles are not inferred from the numbers in the + Note, the commodity styles are not inferred from the numbers in the original CSV data; rather, they are inferred from the amounts generated by the CSV rules. When you are importing CSV data with the import command, eg hledger im- - port foo.csv, there's another step: import tries to make the new en- - tries conform to the journal's existing styles. So for each commodity + port foo.csv, there's another step: import tries to make the new en- + tries conform to the journal's existing styles. So for each commodity - let's say it's EUR - import will choose: 1. the style declared for EUR by a commodity directive in the journal 2. otherwise, the style inferred from EUR amounts in the journal - 3. otherwise, the style inferred from EUR amounts generated by the CSV + 3. otherwise, the style inferred from EUR amounts generated by the CSV rules. - TLDR: if import is not generating the precisions or styles you want, + TLDR: if import is not generating the precisions or styles you want, add a commodity directive to specify them. Referencing other fields - In field assignments, you can interpolate only CSV fields, not hledger - fields. In the example below, there's both a CSV field and a hledger - field named amount1, but %amount1 always means the CSV field, not the + In field assignments, you can interpolate only CSV fields, not hledger + fields. In the example below, there's both a CSV field and a hledger + field named amount1, but %amount1 always means the CSV field, not the hledger field: # Name the third CSV field "amount1" @@ -4139,7 +4152,7 @@ CSV # Set comment to the CSV amount1 (not the amount1 assigned above) comment %amount1 - Here, since there's no CSV amount1 field, %amount1 will produce a lit- + Here, since there's no CSV amount1 field, %amount1 will produce a lit- eral "amount1": fields date,description,csvamount @@ -4147,7 +4160,7 @@ CSV # Can't interpolate amount1 here comment %amount1 - When there are multiple field assignments to the same hledger field, + When there are multiple field assignments to the same hledger field, only the last one takes effect. Here, comment's value will be be B, or C if "something" is matched, but never A: @@ -4157,45 +4170,57 @@ CSV comment C How CSV rules are evaluated - Here's how to think of CSV rules being evaluated (if you really need - to). First, + Here's how to think of CSV rules being evaluated. If you get a confus- + ing error while reading a CSV file, it may help to try to understand + which of these steps is failing: - o include - all includes are inlined, from top to bottom, depth first. - (At each include point the file is inlined and scanned for further - includes, recursively, before proceeding.) + 1. Any included rules files are inlined, from top to bottom, depth + first (scanning each included file for further includes, recur- + sively, before proceeding). - Then "global" rules are evaluated, top to bottom. If a rule is re- - peated, the last one wins: + 2. Top level rules (date-format, fields, newest-first, skip etc) are + read, top to bottom. "Top level rules" means non-conditional rules. + If a rule occurs more than once, the last one wins; except for + skip/end rules, where the first one wins. - o skip (at top level) + 3. The CSV file is read as text. Any non-ascii characters will be de- + coded using the text encoding specified by the encoding rule, other- + wise the system locale's text encoding. - o date-format + 4. Any top-level skip or end rule is applied. skip [N] immediately + skips the current or next N CSV records; end immediately skips all + remaining CSV records (not normally used at top level). - o newest-first + 5. Now any remaining CSV records are processed. For each CSV record, + in file order: - o fields - names the CSV fields, optionally sets up initial assignments - to hledger fields + o Is there a conditional skip/end rule that applies for this record + ? Search the if blocks, from top to bottom, for a succeeding one + containing a skip or end rule. If found, skip the specified num- + ber of CSV records, then continue at 5. + Otherwise... - Then for each CSV record in turn: + o Do some basic validation on this CSV record (eg, check that it + has at least two fields). - o test all if blocks. If any of them contain a end rule, skip all re- - maining CSV records. Otherwise if any of them contain a skip rule, - skip that many CSV records. If there are multiple matched skip - rules, the first one wins. + o For each hledger field (date, description, account1, etc.): - o collect all field assignments at top level and in matched if blocks. - When there are multiple assignments for a field, keep only the last - one. + 1. Get the field's assigned value, first searching top level as- + signments, made directly or by the fields rule, then assign- + ments made inside succeeding if blocks. If there are more + than one, the last one wins. - o compute a value for each hledger field - either the one that was as- - signed to it (and interpolate the %CSVFIELD references), or a default + 2. Compute the field's actual value (as text), by interpolating + any %CSVFIELD references within the assigned value; or by + choosing a default value if there was no assignment. - o generate a hledger transaction (journal entry) from these values. + o Generate a hledger transaction from the hledger field values, + parsing them if needed (eg from text to an amount). - This is all part of the CSV reader, one of several readers hledger can - use to parse input files. When all files have been read successfully, - the transactions are passed as input to whichever hledger command the - user specified. + This is all done by the CSV reader, one of several readers hledger can + use to read transactions from an input file. When all input files have + been read successfully, their transactions are passed to whichever + hledger command the user specified. Well factored rules Some things than can help reduce duplication and complexity in rules @@ -4495,11 +4520,18 @@ Timeclock o 2015/03/30 09:20:00 i 2015/03/31 22:21:45 another:account o 2015/04/01 02:00:34 + i 2015/04/02 12:00:00 another:account ; this demonstrates multple sessions being clocked in + i 2015/04/02 13:00:00 some account + o 2015/04/02 14:00:00 + o 2015/04/02 15:00:00 another:account hledger treats each clock-in/clock-out pair as a transaction posting - some number of hours to an account. Or if the session spans more than - one day, it is split into several transactions, one for each day. For - the above time log, hledger print generates these journal entries: + some number of hours to an account. Entries are paired by the account + name if the same name is given for a clock-in/clock-out pair. If no + name is given for a clock-out, then it is paired with the most recent + clock-in entry. If the session spans more than one day, it is split + into several transactions, one for each day. For the above time log, + hledger print generates these journal entries: $ hledger -f t.timeclock print 2015-03-30 * optional description after 2 spaces ; optional comment, tags: @@ -4511,6 +4543,12 @@ Timeclock 2015-04-01 * 00:00-02:00 (another:account) 2.01h + 2015-04-02 * 12:00-15:00 ; this demonstrates multiple sessions being clocked in + (another:account) 3.00h + + 2015-04-02 * 13:00-14:00 + (some account) 1.00h + Here is a sample.timeclock to download and some queries to try: $ hledger -f sample.timeclock balance # current time balances @@ -4528,13 +4566,13 @@ Timeclock perhaps the extras in ledgerutils.el o or use the old ti and to scripts in the ledger 2.x repository. These - rely on a "timeclock" executable which I think is just the ledger 2 + rely on a "timeclock" executable which I think is just the ledger 2 executable renamed. Timedot - timedot format is hledger's human-friendly time logging format. Com- - pared to timeclock format, it is more convenient for quick, approxi- - mate, and retroactive time logging, and more human-readable (you can + timedot format is hledger's human-friendly time logging format. Com- + pared to timeclock format, it is more convenient for quick, approxi- + mate, and retroactive time logging, and more human-readable (you can see at a glance where time was spent). A quick example: 2023-05-01 @@ -4553,59 +4591,59 @@ Timedot (per:admin:finance) 0 A timedot file contains a series of transactions (usually one per day). - Each begins with a simple date (Y-M-D, Y/M/D, or Y.M.D), optionally be + Each begins with a simple date (Y-M-D, Y/M/D, or Y.M.D), optionally be followed on the same line by a transaction description, and/or a trans- action comment following a semicolon. After the date line are zero or more time postings, consisting of: - o An account name - any hledger-style account name, optionally in- + o An account name - any hledger-style account name, optionally in- dented. - o Two or more spaces - required if there is an amount (as in journal + o Two or more spaces - required if there is an amount (as in journal format). o A timedot amount, which can be o empty (representing zero) - o a number, optionally followed by a unit s, m, h, d, w, mo, or y, - representing a precise number of seconds, minutes, hours, days + o a number, optionally followed by a unit s, m, h, d, w, mo, or y, + representing a precise number of seconds, minutes, hours, days weeks, months or years (hours is assumed by default), which will be - converted to hours according to 60s = 1m, 60m = 1h, 24h = 1d, 7d = + converted to hours according to 60s = 1m, 60m = 1h, 24h = 1d, 7d = 1w, 30d = 1mo, 365d = 1y. - o one or more dots (period characters), each representing 0.25. - These are the dots in "timedot". Spaces are ignored and can be + o one or more dots (period characters), each representing 0.25. + These are the dots in "timedot". Spaces are ignored and can be used for grouping/alignment. - o Added in 1.32 one or more letters. These are like dots but they - also generate a tag t: (short for "type") with the letter as its - value, and a separate posting for each of the values. This pro- - vides a second dimension of categorisation, viewable in reports + o Added in 1.32 one or more letters. These are like dots but they + also generate a tag t: (short for "type") with the letter as its + value, and a separate posting for each of the values. This pro- + vides a second dimension of categorisation, viewable in reports with --pivot t. - o An optional comment following a semicolon (a hledger-style posting + o An optional comment following a semicolon (a hledger-style posting comment). - There is some flexibility to help with keeping time log data and notes + There is some flexibility to help with keeping time log data and notes in the same file: o Blank lines and lines beginning with # or ; are ignored. - o After the first date line, lines which do not contain a double space + o After the first date line, lines which do not contain a double space are parsed as postings with zero amount. (hledger's register reports will show these if you add -E). - o Before the first date line, lines beginning with * (eg org headings) - are ignored. And from the first date line onward, Emacs org mode + o Before the first date line, lines beginning with * (eg org headings) + are ignored. And from the first date line onward, Emacs org mode heading prefixes at the start of lines (one or more *'s followed by a - space) will be ignored. This means the time log can also be a org + space) will be ignored. This means the time log can also be a org outline. Timedot files don't support directives like journal files. So a common - pattern is to have a main journal file (eg time.journal) that contains - any needed directives, and then includes the timedot file (include + pattern is to have a main journal file (eg time.journal) that contains + any needed directives, and then includes the timedot file (include time.timedot). Timedot examples @@ -4713,21 +4751,21 @@ Timedot PART 3: REPORTING CONCEPTS Time periods Report start & end date - Most hledger reports will by default show the full time period repre- - sented by the journal. The report start date will be the earliest + Most hledger reports will by default show the full time period repre- + sented by the journal. The report start date will be the earliest transaction or posting date, and the report end date will be the latest transaction, posting, or market price date. Often you will want to see a shorter period, such as the current month. - You can specify a start and/or end date with the -b/--begin, -e/--end, - or -p/--period options, or a date: query argument, described below. + You can specify a start and/or end date with the -b/--begin, -e/--end, + or -p/--period options, or a date: query argument, described below. All of these accept the smart date syntax, also described below. End dates are exclusive; specify the day after the last day you want to see in the report. When dates are specified by multiple options, the last (right-most) op- - tion wins. And when date: queries and date options are combined, the + tion wins. And when date: queries and date options are combined, the report period will be their intersection. Examples: @@ -4755,17 +4793,17 @@ Time periods -b and -e) Smart dates - In hledger's user interfaces (though not in the journal file), you can - optionally use "smart date" syntax. Smart dates can be written with - english words, can be relative, and can have parts omitted. Missing - parts are inferred as 1, when needed. Smart dates can be interpreted + In hledger's user interfaces (though not in the journal file), you can + optionally use "smart date" syntax. Smart dates can be written with + english words, can be relative, and can have parts omitted. Missing + parts are inferred as 1, when needed. Smart dates can be interpreted as dates or periods depending on context. Examples: 2004-01-01, 2004/10/1, 2004.9.1, 20240504 : - Exact dates. The year must have at least four digits, the month must - be 1-12, the day must be 1-31, the separator can be - or / or . or + Exact dates. The year must have at least four digits, the month must + be 1-12, the day must be 1-31, the separator can be - or / or . or nothing. 2004-10 @@ -4798,7 +4836,7 @@ Time periods 201812 6 digit YYYYMM with valid year and month - Dates with no separators are allowed but might give surprising results + Dates with no separators are allowed but might give surprising results if mistyped: o 20181301 (YYYYMMDD with an invalid month) is parsed as an eight-digit @@ -4806,20 +4844,20 @@ Time periods o 20181232 (YYYYMMDD with an invalid day) gives a parse error - o 201801012 (a valid YYYYMMDD followed by additional digits) gives a + o 201801012 (a valid YYYYMMDD followed by additional digits) gives a parse error - The meaning of relative dates depends on today's date. If you need to - test or reproduce old reports, you can use the --today option to over- - ride that. (Except for periodic transaction rules, which are not af- + The meaning of relative dates depends on today's date. If you need to + test or reproduce old reports, you can use the --today option to over- + ride that. (Except for periodic transaction rules, which are not af- fected by --today.) Report intervals - A report interval can be specified so that reports like register, bal- + A report interval can be specified so that reports like register, bal- ance or activity become multi-period, showing each subperiod as a sepa- rate row or column. - The following standard intervals can be enabled with command-line + The following standard intervals can be enabled with command-line flags: o -D/--daily @@ -4832,7 +4870,7 @@ Time periods o -Y/--yearly - More complex intervals can be specified using -p/--period, described + More complex intervals can be specified using -p/--period, described below. Date adjustments @@ -4843,17 +4881,17 @@ Time periods For example, if the journal's first transaction is on january 10th, - o hledger register (no report interval) will start the report on janu- + o hledger register (no report interval) will start the report on janu- ary 10th. - o hledger register --monthly will start the report on the previous + o hledger register --monthly will start the report on the previous month boundary, january 1st. o hledger register --monthly --begin 1/5 will start the report on janu- ary 5th [1]. - Also if you are generating transactions or budget goals with periodic - transaction rules, their start date may be adjusted in a similar way + Also if you are generating transactions or budget goals with periodic + transaction rules, their start date may be adjusted in a similar way (in certain situations). End date adjustment @@ -4864,7 +4902,7 @@ Time periods o hledger register will end the report on february 20th. - o hledger register --monthly will end the report at the end of febru- + o hledger register --monthly will end the report at the end of febru- ary. o hledger register --monthly --end 2/14 also will end the report at the @@ -4876,40 +4914,40 @@ Time periods [1] Since hledger 1.29. Period headings - With non-standard subperiods, hledger will show "STARTDATE..ENDDATE" + With non-standard subperiods, hledger will show "STARTDATE..ENDDATE" headings. With standard subperiods (ie, starting on a natural interval - boundary), you'll see more compact headings, which are usually prefer- + boundary), you'll see more compact headings, which are usually prefer- able. (Though month names will be in english, currently.) - So if you are specifying a start date and you want compact headings: + So if you are specifying a start date and you want compact headings: choose a start of year for yearly reports, a start of quarter for quar- - terly reports, a start of month for monthly reports, etc. (Remember, - you can write eg -b 2024 or 1/1 as a shortcut for a start of year, or + terly reports, a start of month for monthly reports, etc. (Remember, + you can write eg -b 2024 or 1/1 as a shortcut for a start of year, or 2024-04 or 202404 or Apr for a start of month or quarter.) - For weekly reports, choose a date that's a Monday. (You can try dif- - ferent dates until you see the short headings, or write eg -b '3 weeks + For weekly reports, choose a date that's a Monday. (You can try dif- + ferent dates until you see the short headings, or write eg -b '3 weeks ago'.) Period expressions - The -p/--period option specifies a period expression, which is a com- + The -p/--period option specifies a period expression, which is a com- pact way of expressing a start date, end date, and/or report interval. - Here's a period expression with a start and end date (specifying the + Here's a period expression with a start and end date (specifying the first quarter of 2009): -p "from 2009/1/1 to 2009/4/1" - Several keywords like "from" and "to" are supported for readability; - these are optional. "to" can also be written as ".." or "-". The - spaces are also optional, as long as you don't run two dates together. + Several keywords like "from" and "to" are supported for readability; + these are optional. "to" can also be written as ".." or "-". The + spaces are also optional, as long as you don't run two dates together. So the following are equivalent to the above: -p "2009/1/1 2009/4/1" -p2009/1/1to2009/4/1 -p2009/1/1..2009/4/1 - Dates are smart dates, so if the current year is 2009, these are also + Dates are smart dates, so if the current year is 2009, these are also equivalent to the above: -p "1/1 4/1" @@ -4921,28 +4959,28 @@ Time periods -p "from 2009/1/1" everything after january 1, 2009 - -p "since 2009/1" the same, since is a syn- + -p "since 2009/1" the same, since is a syn- onym -p "from 2009" the same - -p "to 2009" everything before january + -p "to 2009" everything before january 1, 2009 You can also specify a period by writing a single partial or full date: -p "2009" the year 2009; equivalent to "2009/1/1 to 2010/1/1" - -p "2009/1" the month of january 2009; equivalent to "2009/1/1 to + -p "2009/1" the month of january 2009; equivalent to "2009/1/1 to 2009/2/1" - -p "2009/1/1" the first day of 2009; equivalent to "2009/1/1 to + -p "2009/1/1" the first day of 2009; equivalent to "2009/1/1 to 2009/1/2" or by using the "Q" quarter-year syntax (case insensitive): - -p "2009Q1" first quarter of 2009, equivalent to "2009/1/1 to + -p "2009Q1" first quarter of 2009, equivalent to "2009/1/1 to 2009/4/1" -p "q4" fourth quarter of the current year Period expressions with a report interval - A period expression can also begin with a report interval, separated + A period expression can also begin with a report interval, separated from the start/end dates (if any) by a space or the word in: -p "weekly from 2009/1/1 to 2009/4/1" @@ -4965,15 +5003,15 @@ Time periods Weekly on a custom day: - o every Nth day of week (th, nd, rd, or st are all accepted after the + o every Nth day of week (th, nd, rd, or st are all accepted after the number) - o every WEEKDAYNAME (full or three-letter english weekday name, case + o every WEEKDAYNAME (full or three-letter english weekday name, case insensitive) Monthly on a custom day: - o every Nth day [of month] (31st day will be adjusted to each month's + o every Nth day [of month] (31st day will be adjusted to each month's last day) o every Nth WEEKDAYNAME [of month] @@ -4982,7 +5020,7 @@ Time periods o every MM/DD [of year] (month number and day of month number) - o every MONTHNAME DDth [of year] (full or three-letter english month + o every MONTHNAME DDth [of year] (full or three-letter english month name, case insensitive, and day of month number) o every DDth MONTHNAME [of year] (equivalent to the above) @@ -4995,21 +5033,21 @@ Time periods 2009/03" -p "every 2nd day of week" periods will go from Tue to Tue -p "every Tue" same - -p "every 15th day" period boundaries will be on 15th of each + -p "every 15th day" period boundaries will be on 15th of each month - -p "every 2nd Monday" period boundaries will be on second Monday + -p "every 2nd Monday" period boundaries will be on second Monday of each month - -p "every 11/05" yearly periods with boundaries on 5th of + -p "every 11/05" yearly periods with boundaries on 5th of November -p "every 5th November" same -p "every Nov 5th" same - Show historical balances at end of the 15th day of each month (N is an + Show historical balances at end of the 15th day of each month (N is an end date, exclusive as always): $ hledger balance -H -p "every 16th day" - Group postings from the start of wednesday to end of the following + Group postings from the start of wednesday to end of the following tuesday (N is both (inclusive) start date and (exclusive) end date): $ hledger register checking -p "every 3rd day of week" @@ -5020,10 +5058,10 @@ Time periods o every WEEKDAYNAME,WEEKDAYNAME,... (full or three-letter english week- day names, case insensitive) - Also, weekday and weekendday are shorthand for mon,tue,wed,thu,fri and + Also, weekday and weekendday are shorthand for mon,tue,wed,thu,fri and sat,sun. - This is mainly intended for use with --forecast, to generate periodic + This is mainly intended for use with --forecast, to generate periodic transactions on arbitrary days of the week. It may be less useful with -p, since it divides each week into subperiods of unequal length, which is unusual. (Related: #1632) @@ -5032,32 +5070,32 @@ Time periods -p "every dates will be Mon, Wed, Fri; periods will be mon,wed,fri" Mon-Tue, Wed-Thu, Fri-Sun - -p "every weekday" dates will be Mon, Tue, Wed, Thu, Fri; periods will + -p "every weekday" dates will be Mon, Tue, Wed, Thu, Fri; periods will be Mon, Tue, Wed, Thu, Fri-Sun -p "every weekend- dates will be Sat, Sun; periods will be Sat, Sun-Fri day" Depth - With the --depth NUM option (short form: -NUM), reports will show ac- - counts only to the specified depth, hiding deeper subaccounts. Use - this when you want a summary with less detail. This flag has the same + With the --depth NUM option (short form: -NUM), reports will show ac- + counts only to the specified depth, hiding deeper subaccounts. Use + this when you want a summary with less detail. This flag has the same effect as a depth: query argument: depth:2, --depth=2 or -2 are equiva- lent. - In place of a single number which limits the depth for all accounts, + In place of a single number which limits the depth for all accounts, you can also provide separate depth limits for different accounts using regular expressions (since 1.41). - For example, --depth assets=2 (or, equivalently: depth:assets=2) will - collapse accounts matching the regular expression assets to depth 2. + For example, --depth assets=2 (or, equivalently: depth:assets=2) will + collapse accounts matching the regular expression assets to depth 2. So assets:bank:savings would be collapsed to assets:bank, while liabil- - ities:bank:credit card would not be affected. This can be combined - with a flat depth to collapse other accounts not matching the regular - expression, so --depth assets=2 --depth 1 would collapse as- - sets:bank:savings to assets:bank and liabilities:bank:credit card to + ities:bank:credit card would not be affected. This can be combined + with a flat depth to collapse other accounts not matching the regular + expression, so --depth assets=2 --depth 1 would collapse as- + sets:bank:savings to assets:bank and liabilities:bank:credit card to liabilities. - You can supply multiple depth arguments and they will all be applied, + You can supply multiple depth arguments and they will all be applied, so --depth assets=2 --depth liabilities=3 --depth 1 would collapse: o accounts matching assets to depth 2, @@ -5066,39 +5104,38 @@ Depth o all other accounts to depth 1. - If an account is matched by more than one regular expression depth ar- - gument then the more specific one will used. For example, if --depth - assets=1 --depth assets:bank:savings=2 is provided, then as- - sets:bank:savings will be collapsed to depth 2 rather than depth 1. - This is because assets:bank:savings matches at level 3 in the account + If an account is matched by more than one regular expression depth ar- + gument then the more specific one will used. For example, if --depth + assets=1 --depth assets:bank:savings=2 is provided, then as- + sets:bank:savings will be collapsed to depth 2 rather than depth 1. + This is because assets:bank:savings matches at level 3 in the account name, while assets matches at level 1. The same would be true with the argument --depth assets=1 --depth savings=2. Queries - One of hledger's strengths is being able to quickly report on a precise - subset of your data. Most hledger commands accept query arguments, to - restrict their scope. Multiple query terms can be provided to build up - a more complex query. + Many hledger commands accept query arguments, which restrict their + scope and let you report on a precise subset of your data. Here's a + quick overview of hledger's queries: - o By default, a query term is interpreted as a case-insensitive sub- - string pattern for matching account names: + o By default, a query argument is treated as a case-insensitive sub- + string pattern for matching account names. Eg: - car:fuel dining groceries + car:fuel o Patterns containing spaces or other special characters must be en- closed in single or double quotes: 'personal care' - o These patterns are actually regular expressions, so you can add reg- - exp metacharacters for more precision (see "Regular expressions" - above for details): + o Patterns are actually regular expressions, so you can add regexp + metacharacters for more precision (or you may need to backslash-es- + cape certain characters; see "Regular expressions" above): '^expenses\b' 'food$' 'fuel|repair' 'accounts (payable|receivable)' - o To match something other than account name, add one of the query type - prefixes described in "Query types" below: + o To match something other than the account name, you can add a query + type prefix, such as: date:202312- status: @@ -5106,41 +5143,57 @@ Queries cur:USD cur:\\$ amt:'>0' - o Add a not: prefix to negate a term: + acct:groceries (but acct: is the default, so we usually don't bother + writing it) + o To negate a query, add a not: prefix: not:status:'*' not:desc:'opening|closing' not:cur:USD - o Terms with different types are AND-ed, terms with the same type are - OR-ed (mostly; see "Combining query terms" below). The following - query: + o Multiple query terms can be combined, as space-separated queries Eg: + hledger print date:2022 desc:amazon desc:amzn (show transactions + dated in 2022 whose description contains "amazon" or "amzn"). + o Or more flexibly as boolean queries. Eg: hledger print + expr:'date:2022 and (desc:amazon or desc:amzn) and not date:202210' + All hledger commands use the same query language, but different com- + mands may interpret the query in different ways. We haven't described + the commands yet (that's coming in PART 4: COMMANDS below) but here's + the gist of it: - date:2022 desc:amazon desc:amzn + o Transaction-oriented commands (print, aregister, close, import, de- + scriptions..) try to match transactions (including the transaction's + postings). - is interpreted as: + o Posting-oriented commands (register, balance, balancesheet, incomes- + tatement, accounts..) try to match postings. Postings inherit their + transaction's attributes for querying purposes, so transaction fields + like date or description can still be referenced in a posting query. - date is in 2022 AND ( transaction description contains "amazon" OR - "amzn" ) + o A few commands match in more specific ways. (Eg aregister, which has + a special first argument.) Query types - Here are the types of query term available. + Here are the query types available: acct: query acct:REGEX, or just REGEX - Match account names containing this case insensitive regular expres- + Match account names containing this case insensitive regular expres- sion. - This is the default query type, so we usually don't bother writing the + This is the default query type, so we usually don't bother writing the "acct:" prefix. amt: query amt:N, amt:'N', amt:'>=N' - Match postings with a single-commodity amount equal to, less than, or - greater than N. (Postings with multi-commodity amounts are not tested - and will always match.) The comparison has two modes: if N is preceded - by a + or - sign (or is 0), the two signed numbers are compared. Oth- - erwise, the absolute magnitudes are compared, ignoring sign. amt: - needs quotes to hide the less than/greater than sign from the command - line shell. + Match postings with a single-commodity amount equal to, less than, or + greater than N. (Postings with multi-commodity amounts are not tested + and will always match.) amt: needs quotes to hide the less + than/greater than sign from the command line shell. + + The comparison has two modes: if N is preceded by a + or - sign (or is + 0), the two signed numbers are compared. Otherwise, the absolute mag- + nitudes are compared, ignoring sign. + + Keep in mind that amt: matches posting amounts, not account balances. code: query code:REGEX @@ -5150,10 +5203,10 @@ Queries cur:REGEX Match postings or transactions including any amounts whose cur- rency/commodity symbol is fully matched by REGEX. (Contrary to - hledger's usual infix matching. To do infix matching, write + hledger's usual infix matching. To do infix matching, write .*REGEX.*.) Note, to match special characters which are regex-signifi- - cant, you need to escape them with \. And for characters which are - significant to your shell you will usually need one more level of es- + cant, you need to escape them with \. And for characters which are + significant to your shell you will usually need one more level of es- caping. Eg to match the dollar sign: cur:\\$ or cur:'\$' desc: query @@ -5162,37 +5215,22 @@ Queries date: query date:PERIODEXPR - Match dates (or with the --date2 flag, secondary dates) within the + Match dates (or with the --date2 flag, secondary dates) within the specified period. PERIODEXPR is a period expression with no report in- terval. Examples: date:2016, date:thismonth, date:2/1-2/15, date:2021-07-27..nextquarter. date2: query date2:PERIODEXPR - If you use secondary dates: this matches secondary dates within the + If you use secondary dates: this matches secondary dates within the specified period. It is not affected by the --date2 flag. depth: query depth:[REGEXP=]N - Match (or display, depending on command) accounts at or above this + Match (or display, depending on command) accounts at or above this depth, optionally only for accounts matching a provided regular expres- sion. See Depth for detailed rules. - expr: query - expr:'QUERYEXPR' - expr lets you write more complicated query expressions with AND, OR, - NOT, and parentheses. - Eg: expr:'date:lastmonth and not (food or rent)' - The expression should be enclosed in quotes. See Combining query terms - below. - - not: query - not:QUERYTERM - You can prepend not: to any other query term to negate the match. - Eg: not:equity, not:desc:apple - (Also, a trick: not:not:... can sometimes solve query problems conve- - niently..) - note: query note:REGEX Match transaction notes (the part of the description right of |, or the @@ -5200,7 +5238,7 @@ Queries payee: query payee:REGEX - Match transaction payee/payer names (the part of the description left + Match transaction payee/payer names (the part of the description left of |, or the whole description if there's no |). real: query @@ -5213,18 +5251,18 @@ Queries type: query type:TYPECODES - Match by account type (see Declaring accounts > Account types). TYPE- - CODES is one or more of the single-letter account type codes ALERXCV, + Match by account type (see Declaring accounts > Account types). TYPE- + CODES is one or more of the single-letter account type codes ALERXCV, case insensitive. Note type:A and type:E will also match their respec- - tive subtypes C (Cash) and V (Conversion). Certain kinds of account - alias can disrupt account types, see Rewriting accounts > Aliases and + tive subtypes C (Cash) and V (Conversion). Certain kinds of account + alias can disrupt account types, see Rewriting accounts > Aliases and account types. tag: query tag:NAMEREGEX[=VALREGEX] Match by tag name, and optionally also by tag value. Note: - o Both regular expressions do infix matching. If you need a complete + o Both regular expressions do infix matching. If you need a complete match, use ^ and $. Eg: tag:'^fullname$', tag:'^fullname$=^fullvalue$ @@ -5237,7 +5275,15 @@ Queries o Transactions also acquire the tags of their postings. - Combining query terms + Negative queries + not: query + not:QUERY + You can prepend not: to a query to negate the match. + Eg: not:equity, not:desc:apple + (Also, a trick: not:not:... can sometimes solve query problems conve- + niently.) + + Space-separated queries When given multiple space-separated query terms, most commands select things which match: @@ -5259,58 +5305,87 @@ Queries o match all the other terms. - We also support more complex boolean queries with the expr: prefix. - This allows one to combine query terms using and, or, not keywords - (case insensitive), and to group them by enclosing in parentheses. + Boolean queries + You can write more complicated "boolean" query expressions, enclosed in + quotes and prefixed with expr:. These can combine subqueries with NOT, + AND, OR operators (case insensitive), and parentheses for grouping. + Eg, to show transactions involving both cash and expense accounts: - Some examples: + hledger print expr:'cash AND expenses' - o Exclude account names containing 'food': + The prefix and enclosing quotes are required, so don't write hledger + print cash AND expenses. That would be a space-separated query showing + transactions involving accounts with any of "cash", "and", "expenses" + in their names. - expr:"not food" (not:food is equivalent) + You can write space-separated queries inside a boolean query, and they + will combine as described above, but it might be confusing and best + avoided. Eg these are equivalent, showing transactions involving cash + or expenses accounts: - o Match things which have 'cool' in the description and the 'A' tag: + hledger print expr:'cash expenses' + hledger print cash expenses - expr:"desc:cool and tag:A" (expr:"desc:cool tag:A" is equivalent) + There is a restriction with date: queries: they may not be used inside + OR expressions. - o Match things which either do not reference the 'expenses:food' ac- - count, or do have the 'A' tag: + Actually, there are three types of boolean query: expr: for general + use, and any: and all: variants which can be useful with print. - expr:"not expenses:food or tag:A" + expr: query + expr:'QUERYEXPR' + For example, expr:'date:lastmonth AND NOT (food OR rent)' means "match + things which are dated in the last month and do not have food or rent + in the account name". - o Match things which either do not reference the 'expenses:food' ac- - count, or which reference the 'expenses:drink' account and also have - the 'A' tag: + When using expr: with transaction-oriented commands like print, post- + ing-oriented query terms like acct: and amt: are considered to match + the transaction if they match any of its postings. + So, hledger print expr:'cash and amt:>0' means "show transactions with + (at least one posting involving a cash account) and (at least one post- + ing with a positive amount)". - expr:"expenses:food or (expenses:drink and tag:A)" + any: query + any:'QUERYEXPR' + Like expr:, but when used with transaction-oriented commands like + print, it matches the transaction only if a posting can be matched by + all of QUERYEXPR. + So, hledger print any:'cash and amt:>0' means "show transactions where + at least one posting posts a positive amount to a cash account". - expr: has a restriction: date: queries may not be used inside or ex- - pressions. That would allow disjoint report periods or disjoint result - sets, with unclear semantics for our reports. + all: query + all:'QUERYEXPR' + Like expr:, but when used with transaction-oriented commands like + print, it matches the transaction only if all postings are matched by + all of QUERYEXPR. + So, hledger print all:'cash and amt:0' means "show transactions where + all postings involve a cash account and have a zero amount". + Or, hledger print all:'cash or checking' means "show transactions which + touch only cash and/or checking accounts". Queries and command options - Some queries can also be expressed as command-line options: depth:2 is + Some queries can also be expressed as command-line options: depth:2 is equivalent to --depth 2, date:2023 is equivalent to -p 2023, etc. When - you mix command options and query arguments, generally the resulting + you mix command options and query arguments, generally the resulting query is their intersection. Queries and account aliases - When account names are rewritten with --alias or alias, acct: will + When account names are rewritten with --alias or alias, acct: will match either the old or the new account name. Queries and valuation - When amounts are converted to other commodities in cost or value re- - ports, cur: and amt: match the old commodity symbol and the old amount + When amounts are converted to other commodities in cost or value re- + ports, cur: and amt: match the old commodity symbol and the old amount quantity, not the new ones. (Except in hledger 1.22, #1625.) Pivoting - Normally, hledger groups amounts and displays their totals by account - (name). With --pivot PIVOTEXPR, some other field's (or multiple - fields') value is used as a synthetic account name, causing different + Normally, hledger groups amounts and displays their totals by account + (name). With --pivot PIVOTEXPR, some other field's (or multiple + fields') value is used as a synthetic account name, causing different grouping and display. PIVOTEXPR can be - o any of these standard transaction or posting fields (their value is - substituted): status, code, desc, payee, note, acct, comm/cur, amt, + o any of these standard transaction or posting fields (their value is + substituted): status, code, desc, payee, note, acct, comm/cur, amt, cost o or a tag name @@ -5322,10 +5397,10 @@ Pivoting o Colons appearing in PIVOTEXPR or in a pivoted tag value will generate account hierarchy. - o When pivoting a posting has multiple values for a tag, the pivoted + o When pivoting a posting has multiple values for a tag, the pivoted value of that tag will be the first value. - o When a posting has multiple commodities, the pivoted value of + o When a posting has multiple commodities, the pivoted value of "comm"/"cur" will be "". Also when an unrecognised tag name or field is provided, its pivoted value will be "". (If this causes confusing output, consider excluding those postings from the report.) @@ -5359,7 +5434,7 @@ Pivoting -------------------- -2 EUR - Another way (the acct: query matches against the pivoted "account + Another way (the acct: query matches against the pivoted "account name"): $ hledger balance --pivot member acct:. @@ -5375,78 +5450,78 @@ Pivoting -2 EUR Generating data - hledger can enrich the data provided to it, or generate new data, in a + hledger can enrich the data provided to it, or generate new data, in a number of ways. Mostly, this is done only if you request it: - o Missing amounts or missing costs in transactions are inferred auto- + o Missing amounts or missing costs in transactions are inferred auto- matically when possible. - o The --infer-equity flag infers missing conversion equity postings + o The --infer-equity flag infers missing conversion equity postings from @/@@ costs. - o The --infer-costs flag infers missing costs from conversion equity + o The --infer-costs flag infers missing costs from conversion equity postings. o The --infer-market-prices flag infers P price directives from costs. - o The --auto flag adds extra postings to transactions matched by auto + o The --auto flag adds extra postings to transactions matched by auto posting rules. - o The --forecast option generates transactions from periodic transac- + o The --forecast option generates transactions from periodic transac- tion rules. - o The balance --budget report infers budget goals from periodic trans- + o The balance --budget report infers budget goals from periodic trans- action rules. - o Commands like close, rewrite, and hledger-interest generate transac- + o Commands like close, rewrite, and hledger-interest generate transac- tions or postings. - o CSV data is converted to transactions by applying CSV conversion + o CSV data is converted to transactions by applying CSV conversion rules.. etc. - Such generated data is temporary, existing only at report time. You - can convert it to permanent recorded data by, eg, capturing the output - of hledger print and saving it in your journal file. This can some- + Such generated data is temporary, existing only at report time. You + can convert it to permanent recorded data by, eg, capturing the output + of hledger print and saving it in your journal file. This can some- times be useful as a data entry aid. - If you are curious what data is being generated and why, run hledger - print -x --verbose-tags. -x/--explicit shows inferred amounts and - --verbose-tags adds tags like generated-transaction (from periodic + If you are curious what data is being generated and why, run hledger + print -x --verbose-tags. -x/--explicit shows inferred amounts and + --verbose-tags adds tags like generated-transaction (from periodic rules) and generated-posting, modified (from auto posting rules). Sim- - ilar hidden tags (with an underscore prefix) are always present, also, - so you can always match such data with queries like tag:generated or + ilar hidden tags (with an underscore prefix) are always present, also, + so you can always match such data with queries like tag:generated or tag:modified. Forecasting - Forecasting, or speculative future reporting, can be useful for esti- + Forecasting, or speculative future reporting, can be useful for esti- mating future balances, or for exploring different future scenarios. The simplest and most flexible way to do it with hledger is to manually record a bunch of future-dated transactions. You could keep these in a - separate future.journal and include that with -f only when you want to + separate future.journal and include that with -f only when you want to see them. --forecast - There is another way: with the --forecast option, hledger can generate - temporary "forecast transactions" for reporting purposes, according to - periodic transaction rules defined in the journal. Each rule can gen- - erate multiple recurring transactions, so by changing one rule you can + There is another way: with the --forecast option, hledger can generate + temporary "forecast transactions" for reporting purposes, according to + periodic transaction rules defined in the journal. Each rule can gen- + erate multiple recurring transactions, so by changing one rule you can change many forecasted transactions. - Forecast transactions usually start after ordinary transactions end. + Forecast transactions usually start after ordinary transactions end. By default, they begin after your latest-dated ordinary transaction, or - today, whichever is later, and they end six months from today. (The + today, whichever is later, and they end six months from today. (The exact rules are a little more complicated, and are given below.) This is the "forecast period", which need not be the same as the report - period. You can override it - eg to forecast farther into the future, + period. You can override it - eg to forecast farther into the future, or to force forecast transactions to overlap your ordinary transactions - - by giving the --forecast option a period expression argument, like - --forecast=..2099 or --forecast=2023-02-15... Note that the = is re- + - by giving the --forecast option a period expression argument, like + --forecast=..2099 or --forecast=2023-02-15... Note that the = is re- quired. Inspecting forecast transactions - print is the best command for inspecting and troubleshooting forecast + print is the best command for inspecting and troubleshooting forecast transactions. Eg: ~ monthly from 2022-12-20 rent @@ -5480,7 +5555,7 @@ Forecasting expenses:rent $1000 Here there are no ordinary transactions, so the forecasted transactions - begin on the first occurrence after today's date. (You won't normally + begin on the first occurrence after today's date. (You won't normally use --today; it's just to make these examples reproducible.) Forecast reports @@ -5504,19 +5579,19 @@ Forecasting || $1000 $1000 $1000 $1000 $1000 Forecast tags - Forecast transactions generated by --forecast have a hidden tag, _gen- - erated-transaction. So if you ever need to match forecast transac- + Forecast transactions generated by --forecast have a hidden tag, _gen- + erated-transaction. So if you ever need to match forecast transac- tions, you could use tag:_generated-transaction (or just tag:generated) in a query. - For troubleshooting, you can add the --verbose-tags flag. Then, visi- + For troubleshooting, you can add the --verbose-tags flag. Then, visi- ble generated-transaction tags will be added also, so you can view them - with the print command. Their value indicates which periodic rule was + with the print command. Their value indicates which periodic rule was responsible. Forecast period, in detail Forecast start/end dates are chosen so as to do something useful by de- - fault in almost all situations, while also being flexible. Here are + fault in almost all situations, while also being flexible. Here are (with luck) the exact rules, to help with troubleshooting: The forecast period starts on: @@ -5548,7 +5623,7 @@ Forecasting o otherwise: 180 days (~6 months) from today. Forecast troubleshooting - When --forecast is not doing what you expect, one of these tips should + When --forecast is not doing what you expect, one of these tips should help: o Remember to use the --forecast option. @@ -5558,22 +5633,22 @@ Forecasting o Test with print --forecast. - o Check for typos or too-restrictive start/end dates in your periodic + o Check for typos or too-restrictive start/end dates in your periodic transaction rule. - o Leave at least 2 spaces between the rule's period expression and de- + o Leave at least 2 spaces between the rule's period expression and de- scription fields. - o Check for future-dated ordinary transactions suppressing forecasted + o Check for future-dated ordinary transactions suppressing forecasted transactions. o Try setting explicit report start and/or end dates with -b, -e, -p or date: - o Try adding the -E flag to encourage display of empty periods/zero + o Try adding the -E flag to encourage display of empty periods/zero transactions. - o Try setting explicit forecast start and/or end dates with --fore- + o Try setting explicit forecast start and/or end dates with --fore- cast=START..END o Consult Forecast period, in detail, above. @@ -5581,13 +5656,13 @@ Forecasting o Check inside the engine: add --debug=2 (eg). Budgeting - With the balance command's --budget report, each periodic transaction - rule generates recurring budget goals in specified accounts, and goals - and actual performance can be compared. See the balance command's doc + With the balance command's --budget report, each periodic transaction + rule generates recurring budget goals in specified accounts, and goals + and actual performance can be compared. See the balance command's doc below. - You can generate budget goals and forecast transactions at the same - time, from the same or different periodic transaction rules: hledger + You can generate budget goals and forecast transactions at the same + time, from the same or different periodic transaction rules: hledger bal -M --budget --forecast ... See also: Budgeting and Forecasting. @@ -5595,17 +5670,17 @@ Budgeting Amount formatting Commodity display style For the amounts in each commodity, hledger chooses a consistent display - style (symbol placement, decimal mark and digit group marks, number of + style (symbol placement, decimal mark and digit group marks, number of decimal digits) to use in most reports. This is inferred as follows: - First, if there's a D directive declaring a default commodity, that - commodity symbol and amount format is applied to all no-symbol amounts + First, if there's a D directive declaring a default commodity, that + commodity symbol and amount format is applied to all no-symbol amounts in the journal. - Then each commodity's display style is determined from its commodity - directive. We recommend always declaring commodities with commodity + Then each commodity's display style is determined from its commodity + directive. We recommend always declaring commodities with commodity directives, since they help ensure consistent display styles and preci- - sions, and bring other benefits such as error checking for commodity + sions, and bring other benefits such as error checking for commodity symbols. Here's an example: # Set display styles (and decimal marks, for parsing, if there is no decimal-mark directive) @@ -5615,9 +5690,9 @@ Amount formatting commodity INR 9,99,99,999.00 commodity 1 000 000.9455 - But for convenience, if a commodity directive is not present, hledger - infers a commodity's display styles from its amounts as they are writ- - ten in the journal (excluding cost amounts and amounts in periodic + But for convenience, if a commodity directive is not present, hledger + infers a commodity's display styles from its amounts as they are writ- + ten in the journal (excluding cost amounts and amounts in periodic transaction rules or auto posting rules). It uses o the symbol placement and decimal mark of the first amount seen @@ -5626,7 +5701,7 @@ Amount formatting o and the maximum number of decimal digits seen across all amounts. - And as fallback if no applicable amounts are found, it would use a de- + And as fallback if no applicable amounts are found, it would use a de- fault style, like $1000.00 (symbol on the left with no space, period as decimal mark, and two decimal digits). @@ -5635,16 +5710,16 @@ Amount formatting Rounding Amounts are stored internally as decimal numbers with up to 255 decimal - places. They are displayed with their original journal precisions by - print and print-like reports, and rounded to their display precision + places. They are displayed with their original journal precisions by + print and print-like reports, and rounded to their display precision (the number of decimal digits specified by the commodity display style) - by other reports. When rounding, hledger uses banker's rounding (it + by other reports. When rounding, hledger uses banker's rounding (it rounds to the nearest even digit). So eg 0.5 displayed with zero deci- mal digits appears as "0". Trailing decimal marks If you're wondering why your print report sometimes shows trailing dec- - imal marks, with no decimal digits; it does this when showing amounts + imal marks, with no decimal digits; it does this when showing amounts that have digit group marks but no decimal digits, to disambiguate them and allow them to be re-parsed reliably (see Decimal marks). Eg: @@ -5658,7 +5733,7 @@ Amount formatting (a) $1,000. If this is a problem (eg when exporting to Ledger), you can avoid it by - disabling digit group marks, eg with -c/--commodity (for each affected + disabling digit group marks, eg with -c/--commodity (for each affected commodity): $ hledger print -c '$1000.00' @@ -5675,19 +5750,19 @@ Amount formatting More generally, hledger output falls into three rough categories, which format amounts a little bit differently to suit different consumers: - 1. "hledger-readable output" - should be readable by hledger (and by + 1. "hledger-readable output" - should be readable by hledger (and by humans) - o This is produced by reports that show full journal entries: print, + o This is produced by reports that show full journal entries: print, import, close, rewrite etc. - o It shows amounts with their original journal precisions, which may - not be consistent. + o It shows amounts with their original journal precisions, which may + not be consistent from one amount to the next. - o It adds a trailing decimal mark when needed to avoid showing ambigu- + o It adds a trailing decimal mark when needed to avoid showing ambigu- ous amounts. - o It can be parsed reliably (by hledger and ledger2beancount at least, + o It can be parsed reliably (by hledger and ledger2beancount at least, but perhaps not by Ledger..) 2. "human-readable output" - usually for humans @@ -5699,13 +5774,13 @@ Amount formatting o It shows ambiguous amounts unmodified. - o It can be parsed reliably in the context of a known report (when you + o It can be parsed reliably in the context of a known report (when you know decimals are consistently not being shown, you can assume a sin- gle mark is a digit group mark). 3. "machine-readable output" - usually for other software - o This is produced by all reports when an output format like csv, tsv, + o This is produced by all reports when an output format like csv, tsv, json, or sql is selected. o It shows amounts as 1 or 2 do, but without digit group marks. @@ -5715,17 +5790,17 @@ Amount formatting Cost reporting In some transactions - for example a currency conversion, or a purchase - or sale of stock - one commodity is exchanged for another. In these - transactions there is a conversion rate, also called the cost (when - buying) or selling price (when selling). (In hledger docs we just say - "cost" generically for convenience.) With the -B/--cost flag, hledger + or sale of stock - one commodity is exchanged for another. In these + transactions there is a conversion rate, also called the cost (when + buying) or selling price (when selling). (In hledger docs we just say + "cost" generically for convenience.) With the -B/--cost flag, hledger can show amounts "at cost", converted to the cost's commodity. Recording costs - We'll explore several ways of recording transactions involving costs. + We'll explore several ways of recording transactions involving costs. These are also summarised at hledger Cookbook > Cost notation. - Costs can be recorded explicitly in the journal, using the @ UNITCOST + Costs can be recorded explicitly in the journal, using the @ UNITCOST or @@ TOTALCOST notation described in Journal > Costs: Variant 1 @@ -5740,11 +5815,11 @@ Cost reporting assets:dollars $-135 assets:euros 100 @@ $135 ; $135 total cost - Typically, writing the unit cost (variant 1) is preferable; it can be + Typically, writing the unit cost (variant 1) is preferable; it can be more effort, requiring more attention to decimal digits; but it reveals the per-unit cost basis, and makes stock sales easier. - Costs can also be left implicit, and hledger will infer the cost that + Costs can also be left implicit, and hledger will infer the cost that is consistent with a balanced transaction: Variant 3 @@ -5753,49 +5828,49 @@ Cost reporting assets:dollars $-135 assets:euros 100 - Here, hledger will attach a @@ 100 cost to the first amount (you can - see it with hledger print -x). This form looks convenient, but there + Here, hledger will attach a @@ 100 cost to the first amount (you can + see it with hledger print -x). This form looks convenient, but there are downsides: - o It sacrifices some error checking. For example, if you accidentally + o It sacrifices some error checking. For example, if you accidentally wrote 10 instead of 100, hledger would not be able to detect the mis- take. - o It is sensitive to the order of postings - if they were reversed, a + o It is sensitive to the order of postings - if they were reversed, a different entry would be inferred and reports would be different. o The per-unit cost basis is not easy to read. - So generally this kind of entry is not recommended. You can make sure + So generally this kind of entry is not recommended. You can make sure you have none of these by using -s (strict mode), or by running hledger check balanced. Reporting at cost - Now when you add the -B/--cost flag to reports ("B" is from Ledger's - -B/--basis/--cost flag), any amounts which have been annotated with - costs will be converted to their cost's commodity (in the report out- + Now when you add the -B/--cost flag to reports ("B" is from Ledger's + -B/--basis/--cost flag), any amounts which have been annotated with + costs will be converted to their cost's commodity (in the report out- put). Ie they will be displayed "at cost" or "at sale price". Some things to note: - o Costs are attached to specific posting amounts in specific transac- - tions, and once recorded they do not change. This contrasts with + o Costs are attached to specific posting amounts in specific transac- + tions, and once recorded they do not change. This contrasts with market prices, which are ambient and fluctuating. - o Conversion to cost is performed before conversion to market value + o Conversion to cost is performed before conversion to market value (described below). Equity conversion postings - There is a problem with the entries above - they are not conventional - Double Entry Bookkeeping (DEB) notation, and because of the "magical" - transformation of one commodity into another, they cause an imbalance + There is a problem with the entries above - they are not conventional + Double Entry Bookkeeping (DEB) notation, and because of the "magical" + transformation of one commodity into another, they cause an imbalance in the Accounting Equation. This shows up as a non-zero grand total in balance reports like hledger bse. - For most hledger users, this doesn't matter in practice and can safely + For most hledger users, this doesn't matter in practice and can safely be ignored ! But if you'd like to learn more, keep reading. - Conventional DEB uses an extra pair of equity postings to balance the + Conventional DEB uses an extra pair of equity postings to balance the transaction. Of course you can do this in hledger as well: Variant 4 @@ -5806,10 +5881,10 @@ Cost reporting equity:conversion $135 equity:conversion -100 - Now the transaction is perfectly balanced according to standard DEB, + Now the transaction is perfectly balanced according to standard DEB, and hledger bse's total will not be disrupted. - And, hledger can still infer the cost for cost reporting, but it's not + And, hledger can still infer the cost for cost reporting, but it's not done by default - you must add the --infer-costs flag like so: $ hledger print --infer-costs @@ -5831,14 +5906,14 @@ Cost reporting o Instead of -B you must remember to type -B --infer-costs. - o --infer-costs works only where hledger can identify the two eq- - uity:conversion postings and match them up with the two non-equity - postings. So writing the journal entry in a particular format be- + o --infer-costs works only where hledger can identify the two eq- + uity:conversion postings and match them up with the two non-equity + postings. So writing the journal entry in a particular format be- comes more important. More on this below. Inferring equity conversion postings Can we go in the other direction ? Yes, if you have transactions writ- - ten with the @/@@ cost notation, hledger can infer the missing equity + ten with the @/@@ cost notation, hledger can infer the missing equity postings, if you add the --infer-equity flag. Eg: 2022-01-01 @@ -5852,18 +5927,18 @@ Cost reporting equity:conversion:$-: -100 equity:conversion:$-:$ $135.00 - The equity account names will be "equity:conversion:A-B:A" and "eq- - uity:conversion:A-B:B" where A is the alphabetically first commodity + The equity account names will be "equity:conversion:A-B:A" and "eq- + uity:conversion:A-B:B" where A is the alphabetically first commodity symbol. You can customise the "equity:conversion" part by declaring an account with the V/Conversion account type. - Note you will need to add account declarations for these to your jour- + Note you will need to add account declarations for these to your jour- nal, if you use check accounts or check --strict. Combining costs and equity conversion postings Finally, you can use both the @/@@ cost notation and equity postings at - the same time. This in theory gives the best of all worlds - preserv- - ing the accounting equation, revealing the per-unit cost basis, and + the same time. This in theory gives the best of all worlds - preserv- + ing the accounting equation, revealing the per-unit cost basis, and providing more flexibility in how you write the entry: Variant 5 @@ -5874,15 +5949,15 @@ Cost reporting equity:conversion -100 assets:euros 100 @ $1.35 - All the other variants above can (usually) be rewritten to this final + All the other variants above can (usually) be rewritten to this final form with: $ hledger print -x --infer-costs --infer-equity Downsides: - o The precise format of the journal entry becomes more important. If - hledger can't detect and match up the cost and equity postings, it + o The precise format of the journal entry becomes more important. If + hledger can't detect and match up the cost and equity postings, it will give a transaction balancing error. o The add command does not yet accept this kind of entry (#2056). @@ -5890,34 +5965,34 @@ Cost reporting o This is the most verbose form. Requirements for detecting equity conversion postings - --infer-costs has certain requirements (unlike --infer-equity, which + --infer-costs has certain requirements (unlike --infer-equity, which always works). It will infer costs only in transactions with: - o Two non-equity postings, in different commodities. Their order is + o Two non-equity postings, in different commodities. Their order is significant: the cost will be added to the first of them. - o Two postings to equity conversion accounts, next to one another, + o Two postings to equity conversion accounts, next to one another, which balance the two non-equity postings. This balancing is checked - to the same precision (number of decimal places) used in the conver- + to the same precision (number of decimal places) used in the conver- sion posting's amount. Equity conversion accounts are: o any accounts declared with account type V/Conversion, or their sub- accounts - o otherwise, accounts named equity:conversion, equity:trade, or eq- + o otherwise, accounts named equity:conversion, equity:trade, or eq- uity:trading, or their subaccounts. - And multiple such four-posting groups can coexist within a single - transaction. When --infer-costs fails, it does not infer a cost in - that transaction, and does not raise an error (ie, it infers costs + And multiple such four-posting groups can coexist within a single + transaction. When --infer-costs fails, it does not infer a cost in + that transaction, and does not raise an error (ie, it infers costs where it can). - Reading variant 5 journal entries, combining cost notation and equity - postings, has all the same requirements. When reading such an entry + Reading variant 5 journal entries, combining cost notation and equity + postings, has all the same requirements. When reading such an entry fails, hledger raises an "unbalanced transaction" error. Infer cost and equity by default ? - Should --infer-costs and --infer-equity be enabled by default ? Try + Should --infer-costs and --infer-equity be enabled by default ? Try using them always, eg with a shell alias: alias h="hledger --infer-equity --infer-costs" @@ -5925,104 +6000,104 @@ Cost reporting and let us know what problems you find. Value reporting - hledger can also show amounts "at market value", converted to some - other commodity using the market price or conversion rate on a certain + hledger can also show amounts "at market value", converted to some + other commodity using the market price or conversion rate on a certain date. - This is controlled by the --value=TYPE[,COMMODITY] option. We also - provide simpler -V and -X COMMODITY aliases for this, which are often + This is controlled by the --value=TYPE[,COMMODITY] option. We also + provide simpler -V and -X COMMODITY aliases for this, which are often sufficient. The market prices are declared with a special P directive, and/or they can be inferred from the costs recorded in transactions, by using the --infer-market-prices flag. -V: Value - The -V/--market flag converts amounts to market value in their default + The -V/--market flag converts amounts to market value in their default valuation commodity, using the market prices in effect on the valuation date(s), if any. More on these in a minute. -X: Value in specified commodity The -X/--exchange=COMM option is like -V, except you tell it which cur- - rency you want to convert to, and it tries to convert everything to + rency you want to convert to, and it tries to convert everything to that. Valuation date - Market prices can change from day to day. hledger will use the prices - on a particular valuation date (or on more than one date). By default + Market prices can change from day to day. hledger will use the prices + on a particular valuation date (or on more than one date). By default hledger uses "end" dates for valuation. More specifically: - o For single period reports (including normal print and register re- + o For single period reports (including normal print and register re- ports): o If an explicit report end date is specified, that is used - o Otherwise the latest transaction date or P directive date is used + o Otherwise the latest transaction date or P directive date is used (even if it's in the future) o For multiperiod reports, each period is valued on its last day. - This can be customised with the --value option described below, which + This can be customised with the --value option described below, which can select either "then", "end", "now", or "custom" dates. (Note, this has a bug in hledger-ui <=1.31: turning on valuation with the V key al- ways resets it to "end".) Finding market price - To convert a commodity A to its market value in another commodity B, - hledger looks for a suitable market price (exchange rate) as follows, + To convert a commodity A to its market value in another commodity B, + hledger looks for a suitable market price (exchange rate) as follows, in this order of preference: - 1. A declared market price or inferred market price: A's latest market + 1. A declared market price or inferred market price: A's latest market price in B on or before the valuation date as declared by a P direc- tive, or (with the --infer-market-prices flag) inferred from costs. 2. A reverse market price: the inverse of a declared or inferred market price from B to A. - 3. A forward chain of market prices: a synthetic price formed by com- + 3. A forward chain of market prices: a synthetic price formed by com- bining the shortest chain of "forward" (only 1 above) market prices, leading from A to B. - 4. Any chain of market prices: a chain of any market prices, including - both forward and reverse prices (1 and 2 above), leading from A to + 4. Any chain of market prices: a chain of any market prices, including + both forward and reverse prices (1 and 2 above), leading from A to B. - There is a limit to the length of these price chains; if hledger - reaches that length without finding a complete chain or exhausting all - possibilities, it will give up (with a "gave up" message visible in + There is a limit to the length of these price chains; if hledger + reaches that length without finding a complete chain or exhausting all + possibilities, it will give up (with a "gave up" message visible in --debug=2 output). That limit is currently 1000. - Amounts for which no suitable market price can be found, are not con- + Amounts for which no suitable market price can be found, are not con- verted. --infer-market-prices: market prices from transactions Normally, market value in hledger is fully controlled by, and requires, P directives in your journal. Since adding and updating those can be a - chore, and since transactions usually take place at close to market - value, why not use the recorded costs as additional market prices (as - Ledger does) ? Adding the --infer-market-prices flag to -V, -X or + chore, and since transactions usually take place at close to market + value, why not use the recorded costs as additional market prices (as + Ledger does) ? Adding the --infer-market-prices flag to -V, -X or --value enables this. - So for example, hledger bs -V --infer-market-prices will get market - prices both from P directives and from transactions. If both occur on + So for example, hledger bs -V --infer-market-prices will get market + prices both from P directives and from transactions. If both occur on the same day, the P directive takes precedence. There is a downside: value reports can sometimes be affected in confus- - ing/undesired ways by your journal entries. If this happens to you, - read all of this Value reporting section carefully, and try adding + ing/undesired ways by your journal entries. If this happens to you, + read all of this Value reporting section carefully, and try adding --debug or --debug=2 to troubleshoot. --infer-market-prices can infer market prices from: o multicommodity transactions with explicit prices (@/@@) - o multicommodity transactions with implicit prices (no @, two commodi- - ties, unbalanced). (With these, the order of postings matters. + o multicommodity transactions with implicit prices (no @, two commodi- + ties, unbalanced). (With these, the order of postings matters. hledger print -x can be useful for troubleshooting.) o multicommodity transactions with equity postings, if cost is inferred with --infer-costs. - There is a limitation (bug) currently: when a valuation commodity is - not specified, prices inferred with --infer-market-prices do not help + There is a limitation (bug) currently: when a valuation commodity is + not specified, prices inferred with --infer-market-prices do not help select a default valuation commodity, as P prices would. So conversion might not happen because no valuation commodity was detected (--debug=2 will show this). To be safe, specify the valuation commmodity, eg: @@ -6032,8 +6107,8 @@ Value reporting o --value=then,EUR --infer-market-prices, not --value=then --infer-mar- ket-prices - Signed costs and market prices can be confusing. For reference, here - is the current behaviour, since hledger 1.25. (If you think it should + Signed costs and market prices can be confusing. For reference, here + is the current behaviour, since hledger 1.25. (If you think it should work differently, see #1870.) 2022-01-01 Positive Unit prices @@ -6063,7 +6138,7 @@ Value reporting b B -1 @@ A -1 All of the transactions above are considered balanced (and on each day, - the two transactions are considered equivalent). Here are the market + the two transactions are considered equivalent). Here are the market prices inferred for B: $ hledger -f- --infer-market-prices prices @@ -6076,34 +6151,34 @@ Value reporting Valuation commodity When you specify a valuation commodity (-X COMM or --value TYPE,COMM): - hledger will convert all amounts to COMM, wherever it can find a suit- + hledger will convert all amounts to COMM, wherever it can find a suit- able market price (including by reversing or chaining prices). - When you leave the valuation commodity unspecified (-V or --value + When you leave the valuation commodity unspecified (-V or --value TYPE): - For each commodity A, hledger picks a default valuation commodity as + For each commodity A, hledger picks a default valuation commodity as follows, in this order of preference: 1. The price commodity from the latest P-declared market price for A on or before valuation date. 2. The price commodity from the latest P-declared market price for A on - any date. (Allows conversion to proceed when there are inferred + any date. (Allows conversion to proceed when there are inferred prices before the valuation date.) - 3. If there are no P directives at all (any commodity or date) and the - --infer-market-prices flag is used: the price commodity from the + 3. If there are no P directives at all (any commodity or date) and the + --infer-market-prices flag is used: the price commodity from the latest transaction-inferred price for A on or before valuation date. This means: - o If you have P directives, they determine which commodities -V will + o If you have P directives, they determine which commodities -V will convert, and to what. - o If you have no P directives, and use the --infer-market-prices flag, + o If you have no P directives, and use the --infer-market-prices flag, costs determine it. - Amounts for which no valuation commodity can be found are not con- + Amounts for which no valuation commodity can be found are not con- verted. --value: Flexible valuation @@ -6120,26 +6195,26 @@ Value reporting The TYPE part selects cost or value and valuation date: --value=then - Convert amounts to their value in the default valuation commod- + Convert amounts to their value in the default valuation commod- ity, using market prices on each posting's date. --value=end - Convert amounts to their value in the default valuation commod- - ity, using market prices on the last day of the report period - (or if unspecified, the journal's end date); or in multiperiod + Convert amounts to their value in the default valuation commod- + ity, using market prices on the last day of the report period + (or if unspecified, the journal's end date); or in multiperiod reports, market prices on the last day of each subperiod. --value=now - Convert amounts to their value in the default valuation commod- - ity using current market prices (as of when report is gener- + Convert amounts to their value in the default valuation commod- + ity using current market prices (as of when report is gener- ated). --value=YYYY-MM-DD - Convert amounts to their value in the default valuation commod- + Convert amounts to their value in the default valuation commod- ity using market prices on this date. To select a different valuation commodity, add the optional ,COMM part: - a comma, then the target commodity's symbol. Eg: --value=now,EUR. + a comma, then the target commodity's symbol. Eg: --value=now,EUR. hledger will do its best to convert amounts to this commodity, deducing market prices as described above. @@ -6167,13 +6242,13 @@ Value reporting $ hledger -f t.j bal -N euros -V -e 2016/11/4 $110.00 assets:euros - What are they worth after 2016/12/21 ? (no report end date specified, + What are they worth after 2016/12/21 ? (no report end date specified, defaults to today) $ hledger -f t.j bal -N euros -V $103.00 assets:euros - Here are some examples showing the effect of --value, as seen with + Here are some examples showing the effect of --value, as seen with print: P 2000-01-01 A 1 B @@ -6211,7 +6286,7 @@ Value reporting 2000-02-01 (a) 2 B - With no report period specified, that shows the value as of the last + With no report period specified, that shows the value as of the last day of the journal (2000-03-01): $ hledger -f- print --value=end @@ -6249,7 +6324,7 @@ Value reporting (a) 1 B Interaction of valuation and queries - When matching postings based on queries in the presence of valuation, + When matching postings based on queries in the presence of valuation, the following happens: 1. The query is separated into two parts: @@ -6263,45 +6338,45 @@ Value reporting 3. Valuation is applied to the postings. - 4. The postings are matched to the other parts of the query based on + 4. The postings are matched to the other parts of the query based on post-valued amounts. Related: #1625 Effect of valuation on reports - Here is a reference for how valuation is supposed to affect each part - of hledger's reports. (It's wide, you may need to scroll sideways.) - It may be useful when troubleshooting. If you find problems, please - report them, ideally with a reproducible example. Related: #329, + Here is a reference for how valuation is supposed to affect each part + of hledger's reports. (It's wide, you may need to scroll sideways.) + It may be useful when troubleshooting. If you find problems, please + report them, ideally with a reproducible example. Related: #329, #1083. First, a quick glossary: cost calculated using price(s) recorded in the transaction(s). - value market value using available market price declarations, or the + value market value using available market price declarations, or the unchanged amount if no conversion rate can be found. report start - the first day of the report period specified with -b or -p or + the first day of the report period specified with -b or -p or date:, otherwise today. report or journal start - the first day of the report period specified with -b or -p or - date:, otherwise the earliest transaction date in the journal, + the first day of the report period specified with -b or -p or + date:, otherwise the earliest transaction date in the journal, otherwise today. report end - the last day of the report period specified with -e or -p or + the last day of the report period specified with -e or -p or date:, otherwise today. report or journal end - the last day of the report period specified with -e or -p or - date:, otherwise the latest transaction date in the journal, + the last day of the report period specified with -e or -p or + date:, otherwise the latest transaction date in the journal, otherwise today. report interval - a flag (-D/-W/-M/-Q/-Y) or period expression that activates the + a flag (-D/-W/-M/-Q/-Y) or period expression that activates the report's multi-period mode (whether showing one or many subperi- ods). @@ -6309,8 +6384,8 @@ Value reporting type --value=now -------------------------------------------------------------------------------------------- print - posting cost value at re- value at posting value at re- value at - amounts port end or date port or DATE/today + posting cost value at re- value at posting value at re- value at + amounts port end or date port or DATE/today today journal end balance unchanged unchanged unchanged unchanged unchanged asser- @@ -6326,7 +6401,7 @@ Value reporting (-H) with port or posting was made port or report journal journal interval start start - posting cost value at re- value at posting value at re- value at + posting cost value at re- value at posting value at re- value at amounts port or date port or DATE/today journal end journal end summary summarised value at pe- sum of postings value at pe- value at @@ -6342,8 +6417,8 @@ Value reporting balance (bs, bse, cf, is) - balance sums of value at re- value at posting value at re- value at - changes costs port end or date port or DATE/today of + balance sums of value at re- value at posting value at re- value at + changes costs port end or date port or DATE/today of today of journal end sums of post- sums of of sums of ings postings postings @@ -6351,7 +6426,7 @@ Value reporting amounts changes changes changes ances changes (--bud- get) - grand to- sum of dis- sum of dis- sum of displayed sum of dis- sum of dis- + grand to- sum of dis- sum of dis- sum of displayed sum of dis- sum of dis- tal played val- played val- valued played val- played values ues ues ues @@ -6377,7 +6452,7 @@ Value reporting end bal- sums of same as sums of values of period end value at ances costs of --value=end postings from be- balances, DATE/today of (bal -H, postings fore period start valued at sums of post- - is --H, from before to period end at period ends ings + is --H, from before to period end at period ends ings bs, cf) report start respective post- to period ing dates end @@ -6386,10 +6461,10 @@ Value reporting (--bud- balances balances ances balances get) row to- sums, aver- sums, aver- sums, averages of sums, aver- sums, aver- - tals, row ages of dis- ages of dis- displayed values ages of dis- ages of dis- + tals, row ages of dis- ages of dis- displayed values ages of dis- ages of dis- averages played val- played val- played val- played values (-T, -A) ues ues ues - column sums of dis- sums of dis- sums of displayed sums of dis- sums of dis- + column sums of dis- sums of dis- sums of displayed sums of dis- sums of dis- totals played val- played val- values played val- played values ues ues ues grand to- sum, average sum, average sum, average of sum, average sum, average @@ -6402,17 +6477,23 @@ Value reporting starting balance. PART 4: COMMANDS - Here are the standard commands, which you can list by running hledger. + Here are the standard commands, which you can list by running hledger. If you have installed more add-on commands, they also will be listed. Help commands - o help - show the hledger manual with info/man/pager + o commands - show the hledger commands list (default) o demo - show small hledger demos in the terminal + o help - show the hledger manual with info, man, or pager + User interface commands + o repl - run commands from an interactive prompt + + o run - run commands from a script + o ui - (if installed) run hledger's terminal UI o web - (if installed) run hledger's web UI @@ -6451,7 +6532,7 @@ PART 4: COMMANDS o aregister (areg) - show transactions in a particular account - o register (reg) - show postings in one or more accounts & running to- + o register (reg) - show postings in one or more accounts & running to- tal o balancesheet (bs) - show assets, liabilities and net worth @@ -6484,6 +6565,8 @@ PART 4: COMMANDS o diff - compare account transactions in two journal files + o setup - check and show the status of the hledger installation + o test - run self tests Next, these commands are described in detail. @@ -6502,19 +6585,19 @@ Help commands -s --speed=SPEED playback speed (1 is original speed, .5 is half, 2 is double, etc (default: 2)) - Run this command with no argument to list the demos. To play a demo, + Run this command with no argument to list the demos. To play a demo, write its number or a prefix or substring of its title. Tips: Make your terminal window large enough to see the demo clearly. - Use the -s/--speed SPEED option to set your preferred playback speed, + Use the -s/--speed SPEED option to set your preferred playback speed, eg -s4 to play at 4x original speed or -s.5 to play at half speed. The default speed is 2x. - Other asciinema options can be added following a double dash, eg -- + Other asciinema options can be added following a double dash, eg -- -i.1 to limit pauses or -- -h to list asciinema's other options. - During playback, several keys are available: SPACE to pause/unpause, . + During playback, several keys are available: SPACE to pause/unpause, . to step forward (while paused), CTRL-c quit. Examples: @@ -6526,7 +6609,7 @@ Help commands This command is experimental: there aren't many useful demos yet. help - Show the hledger user manual with info, man, or a pager. With a (case + Show the hledger user manual with info, man, or a pager. With a (case insensitive) TOPIC argument, try to open it at that section heading. Flags: @@ -6535,23 +6618,23 @@ Help commands -p show the manual with $PAGER or less (less is always used if TOPIC is specified) - This command shows the hledger manual built in to your hledger exe- - cutable. It can be useful when offline, or when you prefer the termi- + This command shows the hledger manual built in to your hledger exe- + cutable. It can be useful when offline, or when you prefer the termi- nal to a web browser, or when the appropriate hledger manual or viewers are not installed properly on your system. - By default it chooses the best viewer found in $PATH, trying in this - order: info, man, $PAGER, less, more, stdout. (If a TOPIC is speci- - fied, $PAGER and more are not tried.) You can force the use of info, - man, or a pager with the -i, -m, or -p flags. If no viewer can be - found, or if running non-interactively, it just prints the manual to + By default it chooses the best viewer found in $PATH, trying in this + order: info, man, $PAGER, less, more, stdout. (If a TOPIC is speci- + fied, $PAGER and more are not tried.) You can force the use of info, + man, or a pager with the -i, -m, or -p flags. If no viewer can be + found, or if running non-interactively, it just prints the manual to stdout. - When using info, TOPIC can match either the full heading or a prefix. + When using info, TOPIC can match either the full heading or a prefix. If your info --version is < 6, you'll need to upgrade it, eg with 'brew install texinfo' on mac. - When using man or less, TOPIC must match the full heading. For a pre- + When using man or less, TOPIC must match the full heading. For a pre- fix match, you can write 'TOPIC.*'. Examples @@ -6563,7 +6646,7 @@ Help commands User interface commands repl - Start an interactive prompt, where you can run any of hledger's com- + Start an interactive prompt, where you can run any of hledger's com- mands. Data files are parsed just once, so the commands run faster. Flags: @@ -6571,21 +6654,21 @@ User interface commands This command is experimental and could change in the future. - hledger repl starts a read-eval-print loop (REPL) where you can enter - commands interactively. As with the run command, each input file (or + hledger repl starts a read-eval-print loop (REPL) where you can enter + commands interactively. As with the run command, each input file (or each input file/input options combination) is parsed just once, so com- - mands will run more quickly than if you ran them individually at the + mands will run more quickly than if you ran them individually at the command line. Also like run, the input file(s) specified for the repl command will be - the default input for all interactive commands. You can override this - temporarily by specifying an -f option in particular commands. But - note that commands will not see any changes made to input files (eg by + the default input for all interactive commands. You can override this + temporarily by specifying an -f option in particular commands. But + note that commands will not see any changes made to input files (eg by add) until you exit and restart the REPL. The command syntax is the same as with run: - o enter one hledger command at a time, without the usual hledger first + o enter one hledger command at a time, without the usual hledger first word o empty lines and comment text from # to end of line are ignored @@ -6594,7 +6677,7 @@ User interface commands o type exit or quit or control-D to exit the REPL. - While it is running, the REPL remembers your command history, and you + While it is running, the REPL remembers your command history, and you can navigate in the usual ways: o Keypad or Emacs navigation keys to edit the current command line @@ -6605,9 +6688,9 @@ User interface commands o TAB to complete file paths. - Generally repl command lines should feel much like the normal hledger - CLI, but you may find differences. repl is a little stricter; eg it - requires full command names or official abbreviations (as seen in the + Generally repl command lines should feel much like the normal hledger + CLI, but you may find differences. repl is a little stricter; eg it + requires full command names or official abbreviations (as seen in the commands list). The commands and help commands, and the command help flags (CMD --tldr, @@ -6616,7 +6699,7 @@ User interface commands You can type control-C to cancel a long-running command (but only once; typing it a second time will exit the REPL). - And in most shells you can type control-Z to temporarily exit to the + And in most shells you can type control-Z to temporarily exit to the shell (and then fg to return to the REPL). Examples @@ -6646,8 +6729,8 @@ User interface commands ... run - Run a sequence of hledger commands, provided as files or command line - arguments. Data files are parsed just once, so the commands run + Run a sequence of hledger commands, provided as files or command line + arguments. Data files are parsed just once, so the commands run faster. Flags: @@ -6657,52 +6740,52 @@ User interface commands You can use run in three ways: - o hledger run -- CMD1 -- CMD2 -- CMD3 - read commands from the command + o hledger run -- CMD1 -- CMD2 -- CMD3 - read commands from the command line, separated by -- - o hledger run SCRIPTFILE1 SCRIPTFILE2 - read commands from one or more + o hledger run SCRIPTFILE1 SCRIPTFILE2 - read commands from one or more files o cat SCRIPTFILE1 | hledger run - read commands from standard input. run first loads the input file(s) specified by LEDGER_FILE or by -f op- tions, in the usual way. Then it runs each command in turn, each using - the same input data. But if you want a particular command to use dif- - ferent input, you can specify an -f option within that command. This + the same input data. But if you want a particular command to use dif- + ferent input, you can specify an -f option within that command. This will override (not add to) the default input, just for that command. Each input file (more precisely, each combination of input file and in- - put options) is parsed only once. This means that commands will not - see any changes made to these files, until the next run. But the com- - mands will run more quickly than if run individually (typically about + put options) is parsed only once. This means that commands will not + see any changes made to these files, until the next run. But the com- + mands will run more quickly than if run individually (typically about twice as fast). Command scripts, whether in a file or written on the command line, have a simple syntax: - o each line may contain a single hledger command and its arguments, + o each line may contain a single hledger command and its arguments, without the usual hledger first word o empty lines are ignored o text from # to end of line is a comment, and ignored - o you can use single or double quotes to quote arguments when needed, + o you can use single or double quotes to quote arguments when needed, as on the command line - o these extra commands are available: echo TEXT prints some text, and + o these extra commands are available: echo TEXT prints some text, and exit or quit ends the run. - On unix systems you can use #!/usr/bin/env hledger run in the first - line of a command file to make it a runnable script. If that gives an + On unix systems you can use #!/usr/bin/env hledger run in the first + line of a command file to make it a runnable script. If that gives an error, use #!/usr/bin/env -S hledger run. It's ok to use the run command recursively within a command script. - You may find some differences in behaviour between run command lines - and normal hledger command lines. run is a little stricter; eg it re- - quires full command names or official abbreviations (as seen in the - commands list), and command options must be written after the command + You may find some differences in behaviour between run command lines + and normal hledger command lines. run is a little stricter; eg it re- + quires full command names or official abbreviations (as seen in the + commands list), and command options must be written after the command name. Examples @@ -6710,8 +6793,8 @@ User interface commands hledger -f some.journal run -- balance assets --depth 2 -- balance liabilities -f /some/other.journal --depth 3 --transpose -- stats - This would load some.journal, run balance assets --depth 2 on it, then - run balance liabilities --depth 3 --transpose on /some/other.journal, + This would load some.journal, run balance assets --depth 2 on it, then + run balance liabilities --depth 3 --transpose on /some/other.journal, and finally run stats on some.journal Run commands from standard input: @@ -6753,30 +6836,30 @@ Data entry commands Flags: --no-new-accounts don't allow creating new accounts - 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 trans- - actions, and appends them to the main journal file (which should be in - journal format). Existing transactions are not changed. This is one - of the few hledger commands that writes to the journal file (see also + 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 trans- + actions, and appends them to the main journal file (which should be in + journal format). Existing transactions are not changed. This is one + of the few hledger commands that writes to the journal file (see also import). 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 + many transactions as you like; when you are finished, enter . or press control-d or control-c to exit. Features: - o add tries to provide useful defaults, using the most similar (by de- - scription) recent transaction (filtered by the query, if any) as a + o add tries to provide useful defaults, using the most similar (by de- + scription) recent transaction (filtered by the query, if any) as a template. o You can also set the initial defaults with command line arguments. o Readline-style edit keys can be used during data entry. - o The tab key will auto-complete whenever possible - accounts, pay- - ees/descriptions, dates (yesterday, today, tomorrow). If the input + o The tab key will auto-complete whenever possible - accounts, pay- + ees/descriptions, dates (yesterday, today, tomorrow). If the input area is empty, it will insert the default value. o A parenthesised transaction code may be entered following a date. @@ -6785,15 +6868,15 @@ Data entry commands o If you make a mistake, enter < at any prompt to go one step backward. - o Input prompts are displayed in a different colour when the terminal + o Input prompts are displayed in a different colour when the terminal supports it. Notes: o If you enter a number with no commodity symbol, and you have declared - a default commodity with a D directive, you might expect add to add - this symbol for you. It does not do this; we assume that if you are - using a D directive you prefer not to see the commodity symbol re- + a default commodity with a D directive, you might expect add to add + this symbol for you. It does not do this; we assume that if you are + using a D directive you prefer not to see the commodity symbol re- peated on amounts in the journal. Examples: @@ -6814,22 +6897,22 @@ Data entry commands There is a detailed tutorial at https://hledger.org/add.html. import - Import new transactions from one or more data files to the main jour- + Import new transactions from one or more data files to the main jour- nal. Flags: --catchup just mark all transactions as already imported --dry-run just show the transactions to be imported - This command detects new transactions in one or more data files speci- + This command detects new transactions in one or more data files speci- fied as arguments, and appends them to the main journal. - You can import from any input file format hledger supports, but + You can import from any input file format hledger supports, but CSV/SSV/TSV files, downloaded from financial institutions, are the most common import source. - The import destination is the default journal file, or another speci- - fied in the usual way with $LEDGER_FILE or -f/--file. It should be in + The import destination is the default journal file, or another speci- + fied in the usual way with $LEDGER_FILE or -f/--file. It should be in journal format. Examples: @@ -6839,44 +6922,44 @@ Data entry commands $ hledger import *.csv Import preview - It's useful to preview the import by running first with --dry-run, to + It's useful to preview the import by running first with --dry-run, to sanity check the range of dates being imported, and to check the effect of your conversion rules if converting from CSV. Eg: $ hledger import bank.csv --dry-run The dry run output is valid journal format, so hledger can re-parse it. - If the output is large, you could show just the uncategorised transac- + If the output is large, you could show just the uncategorised transac- tions like so: $ hledger import --dry-run bank.csv | hledger -f- -I print unknown - You could also run this repeatedly to see the effect of edits to your + You could also run this repeatedly to see the effect of edits to your conversion rules: $ watchexec -- 'hledger import --dry-run bank.csv | hledger -f- -I print unknown' - Once the conversion and dates look good enough to import to your jour- + Once the conversion and dates look good enough to import to your jour- nal, perhaps with some manual fixups to follow, you would do the actual import: $ hledger import bank.csv Overlap detection - Reading CSV files is built in to hledger, and not specific to import; - so you could also import by doing hledger -f bank.csv print + Reading CSV files is built in to hledger, and not specific to import; + so you could also import by doing hledger -f bank.csv print >>$LEDGER_FILE. - But import is easier and provides some advantages. The main one is - that it avoids re-importing transactions it has seen on previous runs. + But import is easier and provides some advantages. The main one is + that it avoids re-importing transactions it has seen on previous runs. This means you don't have to worry about overlapping data in successive - downloads of your bank CSV; just download and import as often as you + downloads of your bank CSV; just download and import as often as you like, and only the new transactions will be imported each time. - We don't call this "deduplication", as it's generally not possible to - reliably detect duplicates in bank CSV. Instead, import remembers the - latest date processed previously in each CSV file (saving it in a hid- - den file), and skips any records prior to that date. This works well + We don't call this "deduplication", as it's generally not possible to + reliably detect duplicates in bank CSV. Instead, import remembers the + latest date processed previously in each CSV file (saving it in a hid- + den file), and skips any records prior to that date. This works well for most real-world CSV, where: 1. the data file name is stable (does not change) across imports @@ -6887,115 +6970,115 @@ Data entry commands 4. the newest items have the newest dates - (Occasional violations of 2-4 are often harmless; you can reduce the + (Occasional violations of 2-4 are often harmless; you can reduce the chance of disruption by downloading and importing more often.) - Overlap detection is automatic, and shouldn't require much attention - from you, except perhaps at first import (see below). But here's how + Overlap detection is automatic, and shouldn't require much attention + from you, except perhaps at first import (see below). But here's how it works: o For each FILE being imported from: - 1. hledger reads a file named .latest.FILE file in the same direc- - tory, if any. This file contains the latest record date previ- - ously imported from FILE, in YYYY-MM-DD format. If multiple - records with that date were imported, the date is repeated on N + 1. hledger reads a file named .latest.FILE file in the same direc- + tory, if any. This file contains the latest record date previ- + ously imported from FILE, in YYYY-MM-DD format. If multiple + records with that date were imported, the date is repeated on N lines. - 2. hledger reads records from FILE. If a latest date was found in - step 1, any records before that date, and the first N records on + 2. hledger reads records from FILE. If a latest date was found in + step 1, any records before that date, and the first N records on that date, are skipped. - o After a successful import from all FILEs, without error and without + o After a successful import from all FILEs, without error and without --dry-run, hledger updates each FILE's .latest.FILE for next time. If this goes wrong, it's relatively easy to repair: - o You'll notice it before import when you preview with import + o You'll notice it before import when you preview with import --dry-run. - o Or after import when you try to reconcile your hledger account bal- + o Or after import when you try to reconcile your hledger account bal- ances with your bank. - o hledger print -f FILE.csv will show all recently downloaded transac- + o hledger print -f FILE.csv will show all recently downloaded transac- tions. Compare these with your journal. Copy/paste if needed. o Update your conversion rules and print again, if needed. - o You can manually update or remove the .latest file, or use import + o You can manually update or remove the .latest file, or use import --catchup FILE. - o Download and import more often, eg twice a week, at least while you - are learning. It's easier to review and troubleshoot when there are + o Download and import more often, eg twice a week, at least while you + are learning. It's easier to review and troubleshoot when there are fewer transactions. First import - The first time you import from a file, when no corresponding .latest + The first time you import from a file, when no corresponding .latest file has been created yet, all of the records will be imported. - But perhaps you have been entering the data manually, so you know that + But perhaps you have been entering the data manually, so you know that all of these transactions are already recorded in the journal. In this - case you can run hledger import --catchup once. This will create a - .latest file containing the latest CSV record date, so that none of + case you can run hledger import --catchup once. This will create a + .latest file containing the latest CSV record date, so that none of those records will be re-imported. - Or, if you know that some but not all of the transactions are in the - journal, you can create the .latest file yourself. Eg, let's say you - previously recorded foobank transactions up to 2024-10-31 in the jour- - nal. Then in the directory where you'll be saving foobank.csv, you + Or, if you know that some but not all of the transactions are in the + journal, you can create the .latest file yourself. Eg, let's say you + previously recorded foobank transactions up to 2024-10-31 in the jour- + nal. Then in the directory where you'll be saving foobank.csv, you would create a .latest.foobank.csv file containing 2024-10-31 - Or if you had three foobank transactions recorded with that date, you + Or if you had three foobank transactions recorded with that date, you would repeat the date that many times: 2024-10-31 2024-10-31 2024-10-31 - Then hledger import foobank.csv [--dry-run] will import only the newer + Then hledger import foobank.csv [--dry-run] will import only the newer records. Importing balance assignments - Journal entries added by import will have all posting amounts made ex- + Journal entries added by import will have all posting amounts made ex- plicit (like print -x). - This means that any balance assignments in the imported entries would - need to be evaluated. But this generally isn't possible, as the main + This means that any balance assignments in the imported entries would + need to be evaluated. But this generally isn't possible, as the main file's account balances are not visible during import. So try to avoid generating balance assignments with your CSV rules, or importing from a - journal that contains balance assignments. (Balance assignments are + journal that contains balance assignments. (Balance assignments are best avoided anyway.) - But if you must use them, eg because your CSV includes only balances: - you can import with print, which leaves implicit amounts implicit. + But if you must use them, eg because your CSV includes only balances: + you can import with print, which leaves implicit amounts implicit. (print can also do overlap detection like import, with the --new flag): $ hledger print --new -f bank.csv >> $LEDGER_FILE - (If you think import should preserve implicit balances, please test + (If you think import should preserve implicit balances, please test that and send a pull request.) Import and commodity styles - Amounts in entries added by import will be formatted according to the - journal's canonical commodity styles, as declared by commodity direc- + Amounts in entries added by import will be formatted according to the + journal's canonical commodity styles, as declared by commodity direc- tives or inferred from the journal's amounts. Related: CSV > Amount decimal places. Import special cases If you have a download whose file name varies, you could rename it to a - fixed name after each download. Or you could use a CSV source rule - with a suitable glob pattern, and import from the .rules file instead + fixed name after each download. Or you could use a CSV source rule + with a suitable glob pattern, and import from the .rules file instead of the data file. - Here's a situation where you would need to run import with care: say - you download bank.csv, but forget to import it or delete it. And next + Here's a situation where you would need to run import with care: say + you download bank.csv, but forget to import it or delete it. And next month you download it again. This time your web browser may save it as - bank (2).csv. So now each of these may have data not included in the + bank (2).csv. So now each of these may have data not included in the other. And a source rule with a glob pattern would match only the most - recent file. So in this case you should import from each one in turn, + recent file. So in this case you should import from each one in turn, in the correct order, taking care to use the same filename each time: $ hledger import bank.csv @@ -7003,13 +7086,13 @@ Data entry commands $ hledger import bank.csv Here are two kinds of "deduplication" which import does not handle (and - generally should not, since these can happen legitimately in financial + generally should not, since these can happen legitimately in financial data): - o Two or more of the new CSV records are identical, and generate iden- + o Two or more of the new CSV records are identical, and generate iden- tical new journal entries. - o A new CSV record generates a journal entry identical to one(s) al- + o A new CSV record generates a journal entry identical to one(s) al- ready in the journal. Basic report commands @@ -7032,38 +7115,38 @@ Basic report commands -t --tree list/tree mode: show accounts as a tree --drop=N flat mode: omit N leading account name parts - This command lists account names. By default it shows all known ac- - counts, either used in transactions or declared with account direc- + This command lists account names. By default it shows all known ac- + counts, either used in transactions or declared with account direc- tives. With query arguments, only matched account names and account names ref- erenced by matched postings are shown. - Or it can show just the used accounts (--used/-u), the declared ac- - counts (--declared/-d), the accounts declared but not used (--unused), + Or it can show just the used accounts (--used/-u), the declared ac- + counts (--declared/-d), the accounts declared but not used (--unused), the accounts used but not declared (--undeclared), or the first account matched by an account name pattern, if any (--find). - 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. Account names can be + 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. Account names can be depth-clipped with depth:N or --depth N or -N. - With --types, it also shows each account's type, if it's known. (See + With --types, it also shows each account's type, if it's known. (See Declaring accounts > Account types.) - With --positions, it also shows the file and line number of each ac- - count's declaration, if any, and the account's overall declaration or- + With --positions, it also shows the file and line number of each ac- + count's declaration, if any, and the account's overall declaration or- der; these may be useful when troubleshooting account display order. - With --directives, it adds the account keyword, showing valid account + With --directives, it adds the account keyword, showing valid account directives which can be pasted into a journal file. This is useful to- - gether with --undeclared when updating your account declarations to + gether with --undeclared when updating your account declarations to satisfy hledger check accounts. - The --find flag can be used to look up a single account name, in the - same way that the aregister command does. It returns the alphanumeri- - cally-first matched account name, or if none can be found, it fails + The --find flag can be used to look up a single account name, in the + same way that the aregister command does. It returns the alphanumeri- + cally-first matched account name, or if none can be found, it fails with a non-zero exit code. Examples: @@ -7087,13 +7170,13 @@ Basic report commands Flags: no command-specific flags - This command prints the value of each transaction's code field, in the - order transactions were parsed. The transaction code is an optional - value written in parentheses between the date and description, often + This command prints the value of each transaction's code field, in the + order transactions were parsed. The transaction code is an optional + value written in parentheses between the date and description, often used to store a cheque number, order number or similar. Transactions aren't required to have a code, and missing or empty codes - will not be shown by default. With the -E/--empty flag, they will be + will not be shown by default. With the -E/--empty flag, they will be printed as blank lines. You can add a query to select a subset of transactions. @@ -7140,7 +7223,7 @@ Basic report commands no command-specific flags This command lists the unique descriptions that appear in transactions, - in alphabetic order. You can add a query to select a subset of trans- + in alphabetic order. You can add a query to select a subset of trans- actions. Example: @@ -7151,7 +7234,7 @@ Basic report commands Person A files - List all files included in the journal. With a REGEX argument, only + List all files included in the journal. With a REGEX argument, only file names matching the regular expression (case sensitive) are shown. Flags: @@ -7164,8 +7247,8 @@ Basic report commands no command-specific flags This command lists the unique notes that appear in transactions, in al- - phabetic order. You can add a query to select a subset of transac- - tions. The note is the part of the transaction description after a | + phabetic order. You can add a query to select a subset of transac- + tions. The note is the part of the transaction description after a | character (or if there is no |, the whole description). Example: @@ -7181,14 +7264,14 @@ Basic report commands --declared show payees declared with payee directives --used show payees referenced by transactions - This command lists unique payee/payer names which have been declared - with payee directives (--declared), used in transaction descriptions + This command lists unique payee/payer names which have been declared + with payee directives (--declared), used in transaction descriptions (--used), or both (the default). - The payee/payer is the part of the transaction description before a | + The payee/payer is the part of the transaction description before a | character (or if there is no |, the whole description). - You can add query arguments to select a subset of transactions. This + You can add query arguments to select a subset of transactions. This implies --used. Example: @@ -7199,8 +7282,8 @@ Basic report commands Person A prices - Print the market prices declared with P directives. With --infer-mar- - ket-prices, also show any additional prices inferred from costs. With + Print the market prices declared with P directives. With --infer-mar- + ket-prices, also show any additional prices inferred from costs. With --show-reverse, also show additional prices inferred by reversing known prices. @@ -7208,14 +7291,14 @@ Basic report commands --show-reverse also show the prices inferred by reversing known prices - Price amounts are always displayed with their full precision, except + Price amounts are always displayed with their full precision, except for reverse prices which are limited to 8 decimal digits. Prices can be filtered by a date:, cur: or amt: query. Generally if you run this command with --infer-market-prices --show-re- - verse, it will show the same prices used internally to calculate value - reports. But if in doubt, you can inspect those directly by running + verse, it will show the same prices used internally to calculate value + reports. But if in doubt, you can inspect those directly by running the value report with --debug=2. stats @@ -7226,10 +7309,10 @@ Basic report commands -o --output-file=FILE write output to FILE. The stats command shows summary information for the whole journal, or a - matched part of it. With a reporting interval, it shows a report for + matched part of it. With a reporting interval, it shows a report for each report period. - The default output is fairly impersonal, though it reveals the main + The default output is fairly impersonal, though it reveals the main file name. With -v/--verbose, more details are shown, like file paths, included files, and commodity names. @@ -7241,8 +7324,8 @@ Basic report commands o live: the peak memory in use by the program to do its work - o alloc: the peak memory allocation from the OS as seen by GHC. Mea- - suring this externally, eg with GNU time, is more accurate; usually + o alloc: the peak memory allocation from the OS as seen by GHC. Mea- + suring this externally, eg with GNU time, is more accurate; usually that will be a larger number; sometimes (with swapping?) smaller. The stats command's run time is similar to that of a balance report. @@ -7263,7 +7346,7 @@ Basic report commands Market prices : 1000 Runtime stats : 0.12 s elapsed, 8266 txns/s, 4 MB live, 16 MB alloc - This command supports the -o/--output-file option (but not -O/--out- + This command supports the -o/--output-file option (but not -O/--out- put-format). tags @@ -7277,22 +7360,22 @@ Basic report commands This command lists the tag names used in the journal, whether on trans- actions, postings, or account declarations. - With a TAGREGEX argument, only tag names matching this regular expres- + With a TAGREGEX argument, only tag names matching this regular expres- sion (case insensitive, infix matched) are shown. - With QUERY arguments, only transactions and accounts matching this + With QUERY arguments, only transactions and accounts matching this query are considered. If the query involves transaction fields (date:, desc:, amt:, ...), the search is restricted to the matched transactions and their accounts. - With the --values flag, the tags' unique non-empty values are listed + With the --values flag, the tags' unique non-empty values are listed instead. With -E/--empty, blank/empty values are also shown. - With --parsed, tags or values are shown in the order they were parsed, - with duplicates included. (Except, tags from account declarations are + With --parsed, tags or values are shown in the order they were parsed, + with duplicates included. (Except, tags from account declarations are always shown first.) - Tip: remember, accounts also acquire tags from their parents, postings + Tip: remember, accounts also acquire tags from their parents, postings also acquire tags from their account and transaction, transactions also acquire tags from their postings. @@ -7326,13 +7409,14 @@ Standard report commands txt, beancount, csv, tsv, html, fods, json, sql. -o --output-file=FILE write output to FILE. A file extension matching one of the above formats selects that format. + --location add file/line number tags to print output. The print command displays full journal entries (transactions) from the journal file, sorted by date (or with --date2, by secondary date). - Directives and inter-transaction comments are not shown, currently. + Directives and inter-transaction comments are not shown, currently. This means the print command is somewhat lossy, and if you are using it - to reformat/regenerate your journal you should take care to also copy + to reformat/regenerate your journal you should take care to also copy over the directives and inter-transaction comments. Eg: @@ -7352,55 +7436,55 @@ Standard report commands assets:cash $-2 print explicitness - Normally, whether posting amounts are implicit or explicit is pre- + Normally, whether posting amounts are implicit or explicit is pre- served. For example, when an amount is omitted in the journal, it will - not appear in the output. Similarly, if a conversion cost is implied + not appear in the output. Similarly, if a conversion cost is implied but not written, it will not appear in the output. - You can use the -x/--explicit flag to force explicit display of all - amounts and costs. This can be useful for troubleshooting or for mak- - ing your journal more readable and robust against data entry errors. + You can use the -x/--explicit flag to force explicit display of all + amounts and costs. This can be useful for troubleshooting or for mak- + ing your journal more readable and robust against data entry errors. -x is also implied by using any of -B,-V,-X,--value. - The -x/--explicit flag will cause any postings with a multi-commodity - amount (which can arise when a multi-commodity transaction has an im- - plicit amount) to be split into multiple single-commodity postings, + The -x/--explicit flag will cause any postings with a multi-commodity + amount (which can arise when a multi-commodity transaction has an im- + plicit amount) to be split into multiple single-commodity postings, keeping the output parseable. print amount style - Amounts are shown right-aligned within each transaction (but not - aligned across all transactions; you can do that with ledger-mode in + Amounts are shown right-aligned within each transaction (but not + aligned across all transactions; you can do that with ledger-mode in Emacs). - Amounts will be (mostly) normalised to their commodity display style: - their symbol placement, decimal mark, and digit group marks will be - made consistent. By default, decimal digits are shown as they are + Amounts will be (mostly) normalised to their commodity display style: + their symbol placement, decimal mark, and digit group marks will be + made consistent. By default, decimal digits are shown as they are written in the journal. - With the --round (Added in 1.32) option, print will try increasingly - hard to display decimal digits according to the commodity display + With the --round (Added in 1.32) option, print will try increasingly + hard to display decimal digits according to the commodity display styles: o --round=none show amounts with original precisions (default) o --round=soft add/remove decimal zeros in amounts (except costs) - o --round=hard round amounts (except costs), possibly hiding signifi- + o --round=hard round amounts (except costs), possibly hiding signifi- cant digits o --round=all round all amounts and costs - soft is good for non-lossy cleanup, formatting amounts more consis- + soft is good for non-lossy cleanup, formatting amounts more consis- tently where it's safe to do so. - hard and all can cause print to show invalid unbalanced journal en- - tries; they may be useful eg for stronger cleanup, with manual fixups + hard and all can cause print to show invalid unbalanced journal en- + tries; they may be useful eg for stronger cleanup, with manual fixups when needed. print parseability - print's output is usually a valid hledger journal, and you can process + print's output is usually a valid hledger journal, and you can process it again with a second hledger command. This can be useful for certain - kinds of search (though the same can be achieved with expr: queries + kinds of search (though the same can be achieved with expr: queries now): # Show running total of food expenses paid from cash. @@ -7409,7 +7493,7 @@ Standard report commands There are some situations where print's output can become unparseable: - o Value reporting affects posting amounts but not balance assertion or + o Value reporting affects posting amounts but not balance assertion or balance assignment amounts, potentially causing those to fail. o Auto postings can generate postings with too many missing amounts. @@ -7419,19 +7503,22 @@ Standard report commands print, other features With -B/--cost, amounts with costs are shown converted to cost. - With --invert, posting amounts are shown with their sign flipped. It - could be useful if you have accidentally recorded some transactions + With --invert, posting amounts are shown with their sign flipped. It + could be useful if you have accidentally recorded some transactions with the wrong signs. With --new, print shows only transactions it has not seen on a previous - run. This uses the same deduplication system as the import command. + run. This uses the same deduplication system as the import command. (See import's docs for details.) With -m DESC/--match=DESC, print shows one recent transaction whose de- - scription is most similar to DESC. DESC should contain at least two - characters. If there is no similar-enough match, no transaction will + scription is most similar to DESC. DESC should contain at least two + characters. If there is no similar-enough match, no transaction will be shown and the program exit code will be non-zero. + With --location, print adds the source file and line number to every + transaction, as a tag. + print output format This command also supports the output destination and output format op- tions The output formats supported are txt, beancount (Added in 1.32), @@ -8229,15 +8316,15 @@ Advanced report commands more, during one time period or many. Generally it shows a table, with rows representing accounts, and columns representing periods. - Note there are some higher-level variants of the balance command with - convenient defaults, which can be simpler to use: balancesheet, bal- - ancesheetequity, cashflow and incomestatement. When you need more con- - trol, then use balance. + Note there are some variants of the balance command with convenient de- + faults, which are simpler to use: balancesheet, balancesheetequity, + cashflow and incomestatement. When you need more control, then use + balance. balance features Here's a quick overview of the balance command's features, followed by more detailed descriptions and examples. Many of these work with the - higher-level commands as well. + other balance-like commands as well (bs, cf, is..). balance can show.. @@ -8513,8 +8600,9 @@ Advanced report commands Revenues and liability balances are typically negative, however, so -S shows these in reverse order. To work around this, you can add --in- - vert to flip the signs. (Or, use one of the higher-level reports, - which flip the sign automatically. Eg: hledger incomestatement -MAS). + vert to flip the signs. Or you could use one of the higher-level bal- + ance reports (bs, is..), which flip the sign automatically (eg: hledger + is -MAS). Percentages With -%/--percent, balance reports show each account's value expressed @@ -8636,7 +8724,7 @@ Advanced report commands flag. (-H causes report start date to be ignored when summing post- ings.) - Balance report types + Balance report modes The balance command is quite flexible; here is the full detail on how to control what it reports. If the following seems complicated, don't worry - this is for advanced reporting, and it does take time and ex- @@ -8644,10 +8732,10 @@ Advanced report commands There are three important option groups: - hledger balance [CALCULATIONTYPE] [ACCUMULATIONTYPE] [VALUATIONTYPE] + hledger balance [CALCULATIONMODE] [ACCUMULATIONMODE] [VALUATIONMODE] ... - Calculation type + Calculation mode The basic calculation to perform for each table cell. It is one of: o --sum : sum the posting amounts (default) @@ -8664,7 +8752,7 @@ Advanced report commands o --count : show the count of postings - Accumulation type + Accumulation mode How amounts should accumulate across a report's subperiods/columns. Another way to say it: which time period's postings should contribute to each cell's calculation. It is one of: @@ -8683,11 +8771,14 @@ Advanced report commands sets/liabilities/equity. (default for balancesheet, balancesheete- quity) - Valuation type + Valuation mode Which kind of value or cost conversion should be applied, if any, be- - fore displaying the report. It is one of: + fore displaying the report. See Cost reporting and Value reporting for + more about conversions. - o no valuation type : don't convert to cost or value (default) + A valuation (or cost) mode can be selected with the --value option: + + o no conversion : don't convert to cost or value (default) o --value=cost[,COMM] : convert amounts to cost (then optionally to some other commodity) @@ -8704,25 +8795,27 @@ Advanced report commands o --value=YYYY-MM-DD[,COMM] : convert amounts to market value on an- other date - or one of the equivalent simpler flags: + or with the legacy -B/-V/-X options, which are equivalent and easier to + type: - o -B/--cost : like --value=cost (though, note --cost and --value are - independent options which can both be used at once) + o -B/--cost : like --value=cost o -V/--market : like --value=end o -X COMM/--exchange COMM : like --value=end,COMM - See Cost reporting and Value reporting for more about these. + Note that --value can also convert to cost, as a convenience; but actu- + ally --cost and --value are independent options, and could be used to- + gether. - Combining balance report types - Most combinations of these options should produce reasonable reports, - but if you find any that seem wrong or misleading, let us know. The - following restrictions are applied: + Combining balance report modes + Most combinations of these modes should produce reasonable reports, but + if you find any that seem wrong or misleading, let us know. The fol- + lowing restrictions are applied: o --valuechange implies --value=end - o --valuechange makes --change the default when used with the bal- + o --valuechange makes --change the default when used with the bal- ancesheet/balancesheetequity commands o --cumulative or --historical disables --row-total/-T @@ -8735,33 +8828,33 @@ Advanced report commands Accumu- /now lation:v ----------------------------------------------------------------------------------- - --change change in period sum of post- period-end DATE-value of - ing-date market value of change change in pe- + --change change in period sum of post- period-end DATE-value of + ing-date market value of change change in pe- values in period in period riod - --cumu- change from re- sum of post- period-end DATE-value of - lative port start to ing-date market value of change change from + --cumu- change from re- sum of post- period-end DATE-value of + lative port start to ing-date market value of change change from period end values from re- from report report start port start to pe- start to period to period end riod end end - --his- change from sum of post- period-end DATE-value of + --his- change from sum of post- period-end DATE-value of torical journal start to ing-date market value of change change from /-H period end (his- values from jour- from journal journal start - torical end bal- nal start to pe- start to period to period end + torical end bal- nal start to pe- start to period to period end ance) riod end end Budget report - The --budget report type is like a regular balance report, but with two - main differences: + The --budget report is like a regular balance report, but with two main + differences: o Budget goals and performance percentages are also shown, in brackets o Accounts which don't have budget goals are hidden by default. - This is useful for comparing planned and actual income, expenses, time + This is useful for comparing planned and actual income, expenses, time usage, etc. - Periodic transaction rules are used to define budget goals. For exam- - ple, here's a periodic rule defining monthly goals for bus travel and + Periodic transaction rules are used to define budget goals. For exam- + ple, here's a periodic rule defining monthly goals for bus travel and food expenses: ;; Budget @@ -8803,66 +8896,66 @@ Advanced report commands || 0 [ 0% of $430] 0 [ 0% of $430] This is "goal-based budgeting"; you define goals for accounts and peri- - ods, often recurring, and hledger shows performance relative to the - goals. This contrasts with "envelope budgeting", which is more de- - tailed and strict - useful when cash is tight, but also quite a bit - more work. https://plaintextaccounting.org/Budgeting has more on this + ods, often recurring, and hledger shows performance relative to the + goals. This contrasts with "envelope budgeting", which is more de- + tailed and strict - useful when cash is tight, but also quite a bit + more work. https://plaintextaccounting.org/Budgeting has more on this topic. Using the budget report - Historically this report has been confusing and fragile. hledger's - version should be relatively robust and intuitive, but you may still - find surprises. Here are more notes to help with learning and trou- + Historically this report has been confusing and fragile. hledger's + version should be relatively robust and intuitive, but you may still + find surprises. Here are more notes to help with learning and trou- bleshooting. - o In the above example, expenses:bus and expenses:food are shown be- + o In the above example, expenses:bus and expenses:food are shown be- cause they have budget goals during the report period. - o Their parent expenses is also shown, with budget goals aggregated + o Their parent expenses is also shown, with budget goals aggregated from the children. - o The subaccounts expenses:food:groceries and expenses:food:dining are - not shown since they have no budget goal of their own, but they con- + o The subaccounts expenses:food:groceries and expenses:food:dining are + not shown since they have no budget goal of their own, but they con- tribute to expenses:food's actual amount. - o Unbudgeted accounts expenses:movies and expenses:gifts are also not + o Unbudgeted accounts expenses:movies and expenses:gifts are also not shown, but they contribute to expenses's actual amount. - o The other unbudgeted accounts income and assets:bank:checking are + o The other unbudgeted accounts income and assets:bank:checking are grouped as . - o --depth or depth: can be used to limit report depth in the usual way + o --depth or depth: can be used to limit report depth in the usual way (but will not reveal unbudgeted subaccounts). o Amounts are always inclusive of subaccounts (even in -l/--list mode). o Numbers displayed in a --budget report will not always agree with the - totals, because of hidden unbudgeted accounts; this is normal. + totals, because of hidden unbudgeted accounts; this is normal. -E/--empty can be used to reveal the hidden accounts. o In the periodic rules used for setting budget goals, unbalanced post- ings are convenient. - o You can filter budget reports with the usual queries, eg to focus on - particular accounts. It's common to restrict them to just expenses. - (The account is occasionally hard to exclude; this is + o You can filter budget reports with the usual queries, eg to focus on + particular accounts. It's common to restrict them to just expenses. + (The account is occasionally hard to exclude; this is because of date surprises, discussed below.) - o When you have multiple currencies, you may want to convert them to - one (-X COMM --infer-market-prices) and/or show just one at a time - (cur:COMM). If you do need to show multiple currencies at once, + o When you have multiple currencies, you may want to convert them to + one (-X COMM --infer-market-prices) and/or show just one at a time + (cur:COMM). If you do need to show multiple currencies at once, --layout bare can be helpful. - o You can "roll over" amounts (actual and budgeted) to the next period + o You can "roll over" amounts (actual and budgeted) to the next period with --cumulative. See also: https://hledger.org/budgeting.html. Budget date surprises - With small data, or when starting out, some of the generated budget - goal transaction dates might fall outside the report periods. Eg with - the following journal and report, the first period appears to have no - expenses:food budget. (Also the account should be ex- + With small data, or when starting out, some of the generated budget + goal transaction dates might fall outside the report periods. Eg with + the following journal and report, the first period appears to have no + expenses:food budget. (Also the account should be ex- cluded by the expenses query, but isn't.): ~ monthly in 2020 @@ -8882,64 +8975,64 @@ Advanced report commands ---------------++-------------------- || $400 [80% of $500] - In this case, the budget goal transactions are generated on first days - of of month (this can be seen with hledger print --forecast tag:gener- - ated expenses). Whereas the report period defaults to just the 15th - day of january (this can be seen from the report table's column head- + In this case, the budget goal transactions are generated on first days + of of month (this can be seen with hledger print --forecast tag:gener- + ated expenses). Whereas the report period defaults to just the 15th + day of january (this can be seen from the report table's column head- ings). - To fix this kind of thing, be more explicit about the report period - (and/or the periodic rules' dates). In this case, adding -b 2020 does + To fix this kind of thing, be more explicit about the report period + (and/or the periodic rules' dates). In this case, adding -b 2020 does the trick. Selecting budget goals - By default, the budget report uses all available periodic transaction - rules to generate goals. This includes rules with a different report - interval from your report. Eg if you have daily, weekly and monthly - periodic rules, all of these will contribute to the goals in a monthly + By default, the budget report uses all available periodic transaction + rules to generate goals. This includes rules with a different report + interval from your report. Eg if you have daily, weekly and monthly + periodic rules, all of these will contribute to the goals in a monthly budget report. - You can select a subset of periodic rules by providing an argument to - the --budget flag. --budget=DESCPAT will match all periodic rules + You can select a subset of periodic rules by providing an argument to + the --budget flag. --budget=DESCPAT will match all periodic rules whose description contains DESCPAT, a case-insensitive substring (not a - regular expression or query). This means you can give your periodic - rules descriptions (remember that two spaces are needed between period - expression and description), and then select from multiple budgets de- + regular expression or query). This means you can give your periodic + rules descriptions (remember that two spaces are needed between period + expression and description), and then select from multiple budgets de- fined in your journal. Budgeting vs forecasting - --forecast and --budget both use the periodic transaction rules in the - journal to generate temporary transactions for reporting purposes. - However they are separate features - though you can use both at the + --forecast and --budget both use the periodic transaction rules in the + journal to generate temporary transactions for reporting purposes. + However they are separate features - though you can use both at the same time if you want. Here are some differences between them: --forecast --budget -------------------------------------------------------------------------- - is a general option; it enables fore- is a balance command option; it - casting with all reports selects the balance report's + is a general option; it enables fore- is a balance command option; it + casting with all reports selects the balance report's budget mode - generates visible transactions which generates invisible transactions + generates visible transactions which generates invisible transactions appear in reports which produce goal amounts - generates forecast transactions from generates budget goal transac- - after the last regular transaction, to tions throughout the report pe- - the end of the report period; or with riod, optionally restricted by - an argument --forecast=PERIODEXPR gen- periods specified in the peri- - erates them throughout the specified odic transaction rules - period, both optionally restricted by - periods specified in the periodic + generates forecast transactions from generates budget goal transac- + after the last regular transaction, to tions throughout the report pe- + the end of the report period; or with riod, optionally restricted by + an argument --forecast=PERIODEXPR gen- periods specified in the peri- + erates them throughout the specified odic transaction rules + period, both optionally restricted by + periods specified in the periodic transaction rules uses all periodic rules uses all periodic rules; or with an argument --budget=DESCPAT - uses just the rules matched by + uses just the rules matched by DESCPAT Balance report layout The --layout option affects how balance and the other balance-like com- - mands show multi-commodity amounts and commodity symbols. It can im- + mands show multi-commodity amounts and commodity symbols. It can im- prove readability, for humans and/or machines (other software). It has four possible values: - o --layout=wide[,WIDTH]: commodities are shown on a single line, op- + o --layout=wide[,WIDTH]: commodities are shown on a single line, op- tionally elided to WIDTH o --layout=tall: each commodity is shown on a separate line @@ -8947,11 +9040,11 @@ Advanced report commands o --layout=bare: commodity symbols are in their own column, amounts are bare numbers - o --layout=tidy: data is normalised to easily-consumed "tidy" form, - with one row per data value. (This one is currently supported only + o --layout=tidy: data is normalised to easily-consumed "tidy" form, + with one row per data value. (This one is currently supported only by the balance command.) - Here are the --layout modes supported by each output format Only CSV + Here are the --layout modes supported by each output format Only CSV output supports all of them: - txt csv html json sql @@ -8987,7 +9080,7 @@ Advanced report commands || 10.00 ITOT, 337.18 USD, 2 more.. 70.00 GLD, 18.00 ITOT, 3 more.. -11.00 ITOT, 3 more.. 70.00 GLD, 17.00 ITOT, 3 more.. Tall layout - Each commodity gets a new line (may be different in each column), and + Each commodity gets a new line (may be different in each column), and account names are repeated: $ hledger -f examples/bcexample.hledger bal assets:us:etrade -3 -T -Y --layout=tall @@ -9008,7 +9101,7 @@ Advanced report commands || 18.00 VHT 294.00 VHT Bare layout - Commodity symbols are kept in one column, each commodity has its own + Commodity symbols are kept in one column, each commodity has its own row, amounts are bare numbers, account names are repeated: $ hledger -f examples/bcexample.hledger bal assets:us:etrade -3 -T -Y --layout=bare @@ -9044,15 +9137,15 @@ Advanced report commands "Total:","VEA","36.00" "Total:","VHT","294.00" - Bare layout will sometimes display an extra row for the no-symbol com- - modity, because of zero amounts (hledger treats zeroes as commod- + Bare layout will sometimes display an extra row for the no-symbol com- + modity, because of zero amounts (hledger treats zeroes as commod- ity-less, usually). This can break hledger-bar confusingly (workaround: add a cur: query to exclude the no-symbol row). Tidy layout This produces normalised "tidy data" (see https://cran.r-project.org/web/packages/tidyr/vignettes/tidy-data.html) - where every variable has its own column and each row represents a sin- + where every variable has its own column and each row represents a sin- gle data point. This is the easiest kind of data for other software to consume: @@ -9075,41 +9168,40 @@ Advanced report commands "Assets:US:ETrade","2014","2014-01-01","2014-12-31","VHT","170.00" Balance report output - As noted in Output format, if you choose HTML output (by using -O html - or -o somefile.html), it will use the UTF-8 text encoding, And you can - create a hledger.css file in the same directory to customise the re- - port's appearance. + As noted in Output format, if you choose HTML output (by using -O html + or -o somefile.html), you can create a hledger.css file in the same di- + rectory to customise the report's appearance. The HTML and FODS output formats can generate hyperlinks to a - hledger-web register view for each account and period. E.g. if your + hledger-web register view for each account and period. E.g. if your hledger-web server is reachable at http://localhost:5000 then you might - run the balance command with the extra option --base-url=http://local- - host:5000. You can also produce relative links, like + run the balance command with the extra option --base-url=http://local- + host:5000. You can also produce relative links, like --base-url="some/path" or --base-url="".) Some useful balance reports Some frequently used balance options/reports are: o bal -M revenues expenses - Show revenues/expenses in each month. Also available as the incomes- + Show revenues/expenses in each month. Also available as the incomes- tatement command. o bal -M -H assets liabilities - Show historical asset/liability balances at each month end. Also + Show historical asset/liability balances at each month end. Also available as the balancesheet command. o bal -M -H assets liabilities equity - Show historical asset/liability/equity balances at each month end. + Show historical asset/liability/equity balances at each month end. Also available as the balancesheetequity command. o bal -M assets not:receivable - Show changes to liquid assets in each month. Also available as the + Show changes to liquid assets in each month. Also available as the cashflow command. Also: o bal -M expenses -2 -SA - Show monthly expenses summarised to depth 2 and sorted by average + Show monthly expenses summarised to depth 2 and sorted by average amount. o bal -M --budget expenses @@ -9123,7 +9215,7 @@ Advanced report commands Show top gainers [or losers] last week roi - Shows the time-weighted (TWR) and money-weighted (IRR) rate of return + Shows the time-weighted (TWR) and money-weighted (IRR) rate of return on your investments. Flags: @@ -9133,38 +9225,38 @@ Advanced report commands --profit-loss=QUERY --pnl query to select profit-and-loss or appreciation/valuation transactions - At a minimum, you need to supply a query (which could be just an ac- - count name) to select your investment(s) with --inv, and another query + At a minimum, you need to supply a query (which could be just an ac- + count name) to select your investment(s) with --inv, and another query to identify your profit and loss transactions with --pnl. - If you do not record changes in the value of your investment manually, - or do not require computation of time-weighted return (TWR), --pnl + If you do not record changes in the value of your investment manually, + or do not require computation of time-weighted return (TWR), --pnl could be an empty query (--pnl "" or --pnl STR where STR does not match any of your accounts). - This command will compute and display the internalized rate of return - (IRR, also known as money-weighted rate of return) and time-weighted - rate of return (TWR) for your investments for the time period re- - quested. IRR is always annualized due to the way it is computed, but - TWR is reported both as a rate over the chosen reporting period and as + This command will compute and display the internalized rate of return + (IRR, also known as money-weighted rate of return) and time-weighted + rate of return (TWR) for your investments for the time period re- + quested. IRR is always annualized due to the way it is computed, but + TWR is reported both as a rate over the chosen reporting period and as an annual rate. - Price directives will be taken into account if you supply appropriate + Price directives will be taken into account if you supply appropriate --cost or --value flags (see VALUATION). Note, in some cases this report can fail, for these reasons: - o Error (NotBracketed): No solution for Internal Rate of Return (IRR). - Possible causes: IRR is huge (>1000000%), balance of investment be- + o Error (NotBracketed): No solution for Internal Rate of Return (IRR). + Possible causes: IRR is huge (>1000000%), balance of investment be- comes negative at some point in time. - o Error (SearchFailed): Failed to find solution for Internal Rate of + o Error (SearchFailed): Failed to find solution for Internal Rate of Return (IRR). Either search does not converge to a solution, or con- verges too slowly. Examples: - o Using roi to compute total return of investment in stocks: + o Using roi to compute total return of investment in stocks: https://github.com/simonmichael/hledger/blob/master/examples/invest- ing/roi-unrealised.ledger @@ -9174,28 +9266,28 @@ Advanced report commands Note that --inv and --pnl's argument is a query, and queries could have several space-separated terms (see QUERIES). - To indicate that all search terms form single command-line argument, + To indicate that all search terms form single command-line argument, you will need to put them in quotes (see Special characters): $ hledger roi --inv 'term1 term2 term3 ...' - If any query terms contain spaces themselves, you will need an extra + If any query terms contain spaces themselves, you will need an extra level of nested quoting, eg: $ hledger roi --inv="'Assets:Test 1'" --pnl="'Equity:Unrealized Profit and Loss'" Semantics of --inv and --pnl - Query supplied to --inv has to match all transactions that are related + Query supplied to --inv has to match all transactions that are related to your investment. Transactions not matching --inv will be ignored. In these transactions, ROI will conside postings that match --inv to be - "investment postings" and other postings (not matching --inv) will be - sorted into two categories: "cash flow" and "profit and loss", as ROI - needs to know which part of the investment value is your contributions + "investment postings" and other postings (not matching --inv) will be + sorted into two categories: "cash flow" and "profit and loss", as ROI + needs to know which part of the investment value is your contributions and which is due to the return on investment. o "Cash flow" is depositing or withdrawing money, buying or selling as- - sets, or otherwise converting between your investment commodity and + sets, or otherwise converting between your investment commodity and any other commodity. Example: 2019-01-01 Investing in Snake Oil @@ -9212,12 +9304,12 @@ Advanced report commands investment:snake oil = $57 equity:unrealized profit or loss - All non-investment postings are assumed to be "cash flow", unless they - match --pnl query. Changes in value of your investment due to "profit - and loss" postings will be considered as part of your investment re- + All non-investment postings are assumed to be "cash flow", unless they + match --pnl query. Changes in value of your investment due to "profit + and loss" postings will be considered as part of your investment re- turn. - Example: if you use --inv snake --pnl equity:unrealized, then postings + Example: if you use --inv snake --pnl equity:unrealized, then postings in the example below would be classifed as: 2019-01-01 Snake Oil #1 @@ -9234,58 +9326,58 @@ Advanced report commands snake oil $50 ; investment posting IRR and TWR explained - "ROI" stands for "return on investment". Traditionally this was com- - puted as a difference between current value of investment and its ini- + "ROI" stands for "return on investment". Traditionally this was com- + puted as a difference between current value of investment and its ini- tial value, expressed in percentage of the initial value. However, this approach is only practical in simple cases, where invest- - ments receives no in-flows or out-flows of money, and where rate of + ments receives no in-flows or out-flows of money, and where rate of growth is fixed over time. For more complex scenarios you need differ- - ent ways to compute rate of return, and this command implements two of + ent ways to compute rate of return, and this command implements two of them: IRR and TWR. - Internal rate of return, or "IRR" (also called "money-weighted rate of - return") takes into account effects of in-flows and out-flows, and the - time between them. Investment at a particular fixed interest rate is - going to give you more interest than the same amount invested at the - same interest rate, but made later in time. If you are withdrawing - from your investment, your future gains would be smaller (in absolute - numbers), and will be a smaller percentage of your initial investment, + Internal rate of return, or "IRR" (also called "money-weighted rate of + return") takes into account effects of in-flows and out-flows, and the + time between them. Investment at a particular fixed interest rate is + going to give you more interest than the same amount invested at the + same interest rate, but made later in time. If you are withdrawing + from your investment, your future gains would be smaller (in absolute + numbers), and will be a smaller percentage of your initial investment, so your IRR will be smaller. And if you are adding to your investment, you will receive bigger absolute gains, which will be a bigger percent- age of your initial investment, so your IRR will be larger. - As mentioned before, in-flows and out-flows would be any cash that you + As mentioned before, in-flows and out-flows would be any cash that you personally put in or withdraw, and for the "roi" command, these are the - postings that match the query in the--inv argument and NOT match the + postings that match the query in the--inv argument and NOT match the query in the--pnl argument. - If you manually record changes in the value of your investment as - transactions that balance them against "profit and loss" (or "unreal- - ized gains") account or use price directives, then in order for IRR to - compute the precise effect of your in-flows and out-flows on the rate - of return, you will need to record the value of your investement on or + If you manually record changes in the value of your investment as + transactions that balance them against "profit and loss" (or "unreal- + ized gains") account or use price directives, then in order for IRR to + compute the precise effect of your in-flows and out-flows on the rate + of return, you will need to record the value of your investement on or close to the days when in- or out-flows occur. - In technical terms, IRR uses the same approach as computation of net + In technical terms, IRR uses the same approach as computation of net present value, and tries to find a discount rate that makes net present value of all the cash flows of your investment to add up to zero. This - could be hard to wrap your head around, especially if you haven't done + could be hard to wrap your head around, especially if you haven't done discounted cash flow analysis before. Implementation of IRR in hledger should produce results that match the =XIRR formula in Excel. - Second way to compute rate of return that roi command implements is - called "time-weighted rate of return" or "TWR". Like IRR, it will ac- - count for the effect of your in-flows and out-flows, but unlike IRR it - will try to compute the true rate of return of the underlying asset, - compensating for the effect that deposits and withdrawas have on the + Second way to compute rate of return that roi command implements is + called "time-weighted rate of return" or "TWR". Like IRR, it will ac- + count for the effect of your in-flows and out-flows, but unlike IRR it + will try to compute the true rate of return of the underlying asset, + compensating for the effect that deposits and withdrawas have on the apparent rate of growth of your investment. - TWR represents your investment as an imaginary "unit fund" where - in-flows/ out-flows lead to buying or selling "units" of your invest- - ment and changes in its value change the value of "investment unit". - Change in "unit price" over the reporting period gives you rate of re- - turn of your investment, and make TWR less sensitive than IRR to the + TWR represents your investment as an imaginary "unit fund" where + in-flows/ out-flows lead to buying or selling "units" of your invest- + ment and changes in its value change the value of "investment unit". + Change in "unit price" over the reporting period gives you rate of re- + turn of your investment, and make TWR less sensitive than IRR to the effects of cash in-flows and out-flows. References: @@ -9298,7 +9390,7 @@ Advanced report commands o IRR vs TWR - o Examples of computing IRR and TWR and discussion of the limitations + o Examples of computing IRR and TWR and discussion of the limitations of both metrics Chart commands @@ -9308,8 +9400,8 @@ Chart commands Flags: no command-specific flags - The activity command displays an ascii histogram showing transaction - counts by day, week, month or other reporting interval (by day is the + 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. Examples: @@ -9324,10 +9416,10 @@ Data generation commands close (equity) - close prints several kinds of "closing" and/or "opening" transactions, + close prints several kinds of "closing" and/or "opening" transactions, useful in various situations: migrating balances to a new journal file, - retaining earnings into equity, consolidating balances, viewing lot - costs.. Like print, it prints valid journal entries. You can copy + retaining earnings into equity, consolidating balances, viewing lot + costs.. Like print, it prints valid journal entries. You can copy these into your journal file(s) when you are happy with how they look. Flags: @@ -9358,13 +9450,13 @@ Data generation commands all - also round cost amounts to precision (can unbalance transactions) - close has six modes, selected by choosing one of the mode flags - (--close is the default). They all do much the same operation, but + close has six modes, selected by choosing one of the mode flags + (--close is the default). They all do much the same operation, but with different defaults, useful in different situations. close --clopen This is useful if migrating balances to a new journal file at the start - of a new year. It prints a "closing balances" transaction that zeroes + of a new year. It prints a "closing balances" transaction that zeroes out account balances (Asset and Liability accounts, by default), and an opposite "opening balances" transaction that restores them again. Typ- ically, you would run @@ -9375,45 +9467,45 @@ Data generation commands (and probably also update your LEDGER_FILE environment variable). Why might you do this ? If your reports are fast, you may not need it. - But at some point you will probably want to partition your data by - time, for performance or data integrity or regulatory reasons. A new - file or set of files per year is common. Then, having each file/file- - set "bookended" with opening and closing balance transactions will al- - low you to freely pick and choose which files to read - just the cur- + But at some point you will probably want to partition your data by + time, for performance or data integrity or regulatory reasons. A new + file or set of files per year is common. Then, having each file/file- + set "bookended" with opening and closing balance transactions will al- + low you to freely pick and choose which files to read - just the cur- rent year, any past year, any sequence of years, or all of them - while - showing correct account balances in each case. The earliest opening - balances transaction sets correct starting balances, and any later + showing correct account balances in each case. The earliest opening + balances transaction sets correct starting balances, and any later closing/opening pairs will harmlessly cancel each other out. - The balances will be transferred to and from equity:opening/closing - balances by default. You can override this by using --close-acct + The balances will be transferred to and from equity:opening/closing + balances by default. You can override this by using --close-acct and/or --open-acct. - You can select a different set of accounts to close/open by providing - an account query. Eg to add Equity accounts, provide arguments like - assets liabilities equity or type:ALE. When migrating to a new file, - you'll usually want to bring along the AL or ALE accounts, but not the + You can select a different set of accounts to close/open by providing + an account query. Eg to add Equity accounts, provide arguments like + assets liabilities equity or type:ALE. When migrating to a new file, + you'll usually want to bring along the AL or ALE accounts, but not the RX accounts (Revenue, Expense). - Assertions will be added indicating and checking the new balances of + Assertions will be added indicating and checking the new balances of the closed/opened accounts. - The generated transactions will have a clopen: tag. If the main jour- - nal's base file name contains a number (eg a year number), the tag's - value will be that base file name with the number incremented. Or you + The generated transactions will have a clopen: tag. If the main jour- + nal's base file name contains a number (eg a year number), the tag's + value will be that base file name with the number incremented. Or you can choose the tag value yourself, by using --clopen=TAGVAL. close --close - This prints just the closing balances transaction of --clopen. It is + This prints just the closing balances transaction of --clopen. It is the default if you don't specify a mode. - More customisation options are described below. Among other things, + More customisation options are described below. Among other things, you can use close --close to generate a transaction moving the balances from any set of accounts, to a different account. (If you need to move just a portion of the balance, see hledger-move.) close --open - This prints just the opening balances transaction of --clopen. (It is + This prints just the opening balances transaction of --clopen. (It is similar to Ledger's equity command.) close --assert @@ -9423,29 +9515,29 @@ Data generation commands close --assign This prints a transaction that assigns the account balances as they are - on the end date (and adds an "assign:" tag). Unlike balance asser- + on the end date (and adds an "assign:" tag). Unlike balance asser- tions, assignments will post changes to balances as needed to reach the specified amounts. - This is another way to set starting balances when migrating to a new - file, and it will set them correctly even in the presence of earlier - files which do not have a closing balances transaction. However, it - can hide errors, and disturb the accounting equation, so --clopen is + This is another way to set starting balances when migrating to a new + file, and it will set them correctly even in the presence of earlier + files which do not have a closing balances transaction. However, it + can hide errors, and disturb the accounting equation, so --clopen is usually recommended. close --retain - This is like --close, but it closes Revenue and Expense account bal- - ances by default. They will be transferred to equity:retained earn- + This is like --close, but it closes Revenue and Expense account bal- + ances by default. They will be transferred to equity:retained earn- ings, or another account specified with --close-acct. - Revenues and expenses correspond to changes in equity. They are cate- + Revenues and expenses correspond to changes in equity. They are cate- gorised separately for reporting purposes, but traditionally at the end - of each accounting period, businesses consolidate them into equity, + of each accounting period, businesses consolidate them into equity, This is called "retaining earnings", or "closing the books". - In personal accounting, there's not much reason to do this, and most - people don't. (One reason to do it is to help the balancesheetequity - report show a zero total, demonstrating that the accounting equation + In personal accounting, there's not much reason to do this, and most + people don't. (One reason to do it is to help the balancesheetequity + report show a zero total, demonstrating that the accounting equation (A-L=E) is satisfied.) close customisation @@ -9455,57 +9547,57 @@ Data generation commands o the balancing account, with --close-acct=ACCT and/or --open-acct=ACCT - o the transaction descriptions, with --close-desc=DESC and + o the transaction descriptions, with --close-desc=DESC and --open-desc=DESC o the transaction's tag value, with a --MODE=NEW option argument o the closing/opening dates, with -e OPENDATE - By default, the closing date is yesterday, or the journal's end date, - whichever is later; and the opening date is always one day after the - closing date. You can change these by specifying a report end date; + By default, the closing date is yesterday, or the journal's end date, + whichever is later; and the opening date is always one day after the + closing date. You can change these by specifying a report end date; the closing date will be the last day of the report period. Eg -e 2024 means "close on 2023-12-31, open on 2024-01-01". With --x/--explicit, the balancing amount will be shown explicitly, and - if it involves multiple commodities, a separate posting will be gener- + if it involves multiple commodities, a separate posting will be gener- ated for each of them (similar to print -x). - With --interleaved, each individual transfer is shown with source and - destination postings next to each other (perhaps useful for trou- + With --interleaved, each individual transfer is shown with source and + destination postings next to each other (perhaps useful for trou- bleshooting). With --show-costs, balances' costs are also shown, with different costs - kept separate. This may generate very large journal entries, if you - have many currency conversions or investment transactions. close - --show-costs is currently the best way to view investment lots with - hledger. (To move or dispose of lots, see the more capable + kept separate. This may generate very large journal entries, if you + have many currency conversions or investment transactions. close + --show-costs is currently the best way to view investment lots with + hledger. (To move or dispose of lots, see the more capable hledger-move script.) close and balance assertions close adds balance assertions verifying that the accounts have been re- set to zero in a closing transaction or restored to their previous bal- - ances in an opening transaction. These provide useful error checking, + ances in an opening transaction. These provide useful error checking, but you can ignore them temporarily with -I, or remove them if you pre- fer. - Single-commodity, subaccount-exclusive balance assertions (=) are gen- - erated by default. This can be changed with --assertion-type='==*' + Single-commodity, subaccount-exclusive balance assertions (=) are gen- + erated by default. This can be changed with --assertion-type='==*' (eg). - When running close you should probably avoid using -C, -R, status: - (filtering by status or realness) or --auto (generating postings), + When running close you should probably avoid using -C, -R, status: + (filtering by status or realness) or --auto (generating postings), since the generated balance assertions would then require these. - Transactions with multiple dates (eg posting dates) spanning the file + Transactions with multiple dates (eg posting dates) spanning the file boundary also can disrupt the balance assertions: 2023-12-30 a purchase made in december, cleared in january expenses:food 5 assets:bank:checking -5 ; date: 2023-01-02 - To solve this you can transfer the money to and from a temporary ac- + To solve this you can transfer the money to and from a temporary ac- count, splitting the multi-day transaction into two single-day transac- tions: @@ -9526,7 +9618,7 @@ Data generation commands $ hledger close --retain -f 2022.journal -p 2022 >> 2022.journal - After this, to see 2022's revenues and expenses you must exclude the + After this, to see 2022's revenues and expenses you must exclude the retain earnings transaction: $ hledger -f 2022.journal is not:desc:'retain earnings' @@ -9538,12 +9630,12 @@ Data generation commands # copy/paste the closing transaction to the end of 2022.journal # copy/paste the opening transaction to the start of 2023.journal - After this, to see 2022's end-of-year balances you must exclude the + After this, to see 2022's end-of-year balances you must exclude the closing balances transaction: $ hledger -f 2022.journal bs not:desc:'closing balances' - For more flexibility, it helps to tag closing and opening transactions + For more flexibility, it helps to tag closing and opening transactions with eg clopen:NEWYEAR, then you can ensure correct balances by exclud- ing all opening/closing transactions except the first, like so: @@ -9559,7 +9651,7 @@ Data generation commands rewrite Print all transactions, rewriting the postings of matched transactions. - For now the only rewrite available is adding new postings, like print + For now the only rewrite available is adding new postings, like print --auto. Flags: @@ -9573,9 +9665,9 @@ Data generation commands patch tool This is a start at a generic rewriter of transaction entries. It reads - the default journal and prints the transactions, like print, but adds + the default journal and prints the transactions, like print, but adds one or more specified postings to any transactions matching QUERY. The - posting amounts can be fixed, or a multiplier of the existing transac- + posting amounts can be fixed, or a multiplier of the existing transac- tion's first posting amount. Examples: @@ -9591,7 +9683,7 @@ Data generation commands (reserve:grocery) *0.25 ; reserve 25% for grocery (reserve:) *0.25 ; reserve 25% for grocery - Note the single quotes to protect the dollar sign from bash, and the + Note the single quotes to protect the dollar sign from bash, and the two spaces between account and amount. More: @@ -9601,16 +9693,16 @@ Data generation commands $ hledger rewrite -- expenses:gifts --add-posting '(budget:gifts) *-1"' $ hledger rewrite -- ^income --add-posting '(budget:foreign currency) *0.25 JPY; diversify' - Argument for --add-posting option is a usual posting of transaction - with an exception for amount specification. More precisely, you can + Argument for --add-posting option is a usual posting of transaction + with an exception for amount specification. More precisely, you can use '*' (star symbol) before the amount to indicate that that this is a - factor for an amount of original matched posting. If the amount in- + factor for an amount of original matched posting. If the amount in- cludes a commodity name, the new posting amount will be in the new com- - modity; otherwise, it will be in the matched posting amount's commod- + modity; otherwise, it will be in the matched posting amount's commod- ity. Re-write rules in a file - During the run this tool will execute so called "Automated Transac- + During the run this tool will execute so called "Automated Transac- tions" found in any journal it process. I.e instead of specifying this operations in command line you can put them in a journal file. @@ -9625,7 +9717,7 @@ Data generation commands budget:gifts *-1 assets:budget *1 - Note that '=' (equality symbol) that is used instead of date in trans- + Note that '=' (equality symbol) that is used instead of date in trans- actions you usually write. It indicates the query by which you want to match the posting to add new ones. @@ -9638,12 +9730,12 @@ Data generation commands --add-posting 'assets:budget *1' \ > rewritten-tidy-output.journal - It is important to understand that relative order of such entries in - journal is important. You can re-use result of previously added post- + It is important to understand that relative order of such entries in + journal is important. You can re-use result of previously added post- ings. Diff output format - To use this tool for batch modification of your journal files you may + To use this tool for batch modification of your journal files you may find useful output in form of unified diff. $ hledger rewrite -- --diff -f examples/sample.journal '^income' --add-posting '(liabilities:tax) *.33' @@ -9667,10 +9759,10 @@ Data generation commands If you'll pass this through patch tool you'll get transactions contain- ing the posting that matches your query be updated. Note that multiple - files might be update according to list of input files specified via + files might be update according to list of input files specified via --file options and include directives inside of these files. - Be careful. Whole transaction being re-formatted in a style of output + Be careful. Whole transaction being re-formatted in a style of output from hledger print. See also: @@ -9678,17 +9770,17 @@ Data generation commands https://github.com/simonmichael/hledger/issues/99 rewrite vs. print --auto - This command predates print --auto, and currently does much the same + This command predates print --auto, and currently does much the same thing, but with these differences: - o with multiple files, rewrite lets rules in any file affect all other - files. print --auto uses standard directive scoping; rules affect + o with multiple files, rewrite lets rules in any file affect all other + files. print --auto uses standard directive scoping; rules affect only child files. - o rewrite's query limits which transactions can be rewritten; all are + o rewrite's query limits which transactions can be rewritten; all are printed. print --auto's query limits which transactions are printed. - o rewrite applies rules specified on command line or in the journal. + o rewrite applies rules specified on command line or in the journal. print --auto applies rules specified in the journal. Maintenance commands @@ -9698,103 +9790,105 @@ Maintenance commands Flags: no command-specific flags - hledger provides a number of built-in correctness checks to help vali- - date your data and prevent errors. Some are run automatically, some - when you enable --strict mode; or you can run any of them on demand by - providing them as arguments to the check command. check produces no + hledger provides a number of built-in correctness checks to help vali- + date your data and prevent errors. Some are run automatically, some + when you enable --strict mode; or you can run any of them on demand by + providing them as arguments to the check command. check produces no output and a zero exit code if all is well. Eg: hledger check # run basic checks hledger check -s # run basic and strict checks hledger check ordereddates payees # run basic checks and two others - If you are an Emacs user, you can also configure flycheck-hledger to + If you are an Emacs user, you can also configure flycheck-hledger to run these checks, providing instant feedback as you edit the journal. Here are the checks currently available. Generally, they are performed - in the order they are shown here (and only the first failure is re- + in the order they are shown here (and only the first failure is re- ported). Basic checks - These important checks are performed by default, by almost all hledger + These important checks are performed by default, by almost all hledger commands: - o parseable - data files are in a supported format, with no syntax er- - rors and no invalid include directives. This ensures that all files + o parseable - data files are in a supported format, with no syntax er- + rors and no invalid include directives. This ensures that all files exist and are readable. - o autobalanced - all transactions are balanced, after inferring missing - amounts and conversion costs where possible, and then converting to - cost. This ensures that each individual transaction is well formed. + o autobalanced - all transactions are balanced, after automatically in- + ferring missing amounts and conversion rates and then converting + amounts to cost. This ensures that each transaction's entry is well + formed. o assertions - all balance assertions in the journal are passing. Bal- - ance assertions are like canaries in your journal, they catch many - problems. They can get in the way sometimes; you can disable them - temporarily with -I/--ignore-assertions (unless overridden with - -s/--strict or hledger check assertions). + ance assertions are a strong defense against errors; they help catch + many problems. If this check gets in your way, you can disable it + with -I/--ignore-assertions. Or you can add that to your config file + to disable it by default (and then use -s/--strict or hledger check + assertions to enable it). Strict checks - These additional checks are performed by any command when the - -s/--strict flag is used (strict mode). Strict mode always enables the - balance assertions check, also. These provide extra error-catching - power when you are serious about keeping your data clean and free of - typos: + These additional checks are performed by all commands when the + -s/--strict flag is used (strict mode). They provide extra er- + ror-catching power to keep your data clean and correct. Strict mode + also always enables the assertions check. - o balanced - like autobalanced, but in conversion transactions, costs - must be written explicitly. This ensures some redundancy in the en- - try, which helps prevent typos. + o balanced - like autobalanced, but all conversions between commodities + must use explicit cost notation or equity postings. This prevents + wrong conversions caused by typos. - o commodities - all commodity symbols used must be declared. This - guards against mistyping or omitting commodity symbols. + o commodities - all commodity symbols used must be declared. This + guards against mistyping or omitting commodity symbols. Declaring + commodities also sets their precision for display and transaction + balancing. - o accounts - all account names used must be declared. This prevents + o accounts - all account names used must be declared. This prevents the use of mis-spelled or outdated account names. Other checks - These other checks are not wanted by everyone, but can be run using the - check command: + These are not wanted by everyone, but can be run using the check com- + mand: - o ordereddates - within each file, transactions are ordered by date. - This is a simple and effective error catcher, and you should use it. - Alas! not everyone wants it. If you do, use hledger check -s or- - dereddates. When enabled, this check is performed early, before bal- - ance assertions (because copy-pasted dates are often the root cause - of balance assertion failures). + o tags - all tags used must be declared. This prevents mis-spelled tag + names. Note hledger fairly often finds unintended tags in comments. - o payees - all payees used by transactions must be declared. This will - force you to always use known/declared payee names. For most people - this is a bit too restrictive. + o payees - all payees used in transactions must be declared. This will + force you to declare any new payee name before using it. Most people + will probably find this a bit too strict. - o tags - all tags used by transactions must be declared. This prevents - mistyped tag names. + o ordereddates - within each file, transactions must be ordered by + date. This is a simple and effective error catcher. It's not in- + cluded in strict mode, but you can add it by running hledger check -s + ordereddates. If enabled, this check is performed before balance as- + sertions. - o recentassertions - all accounts with balance assertions must have a - balance assertion within the last 7 days before their latest posting. - This encourages you to add balance assertions fairly regularly for - your active asset/liability accounts, which in turn should encourage - you to check and reconcile with their real world balances fairly reg- - ularly. close --assert can be helpful. (The older balance asser- - tions become redundant; you can remove them periodically, or leave - them in place, perhaps commented, as documentation.) + o recentassertions - all accounts with balance assertions must have one + that's within the 7 days before their latest posting. This will en- + courage adding balance assertions for your active asset/liability ac- + counts, which in turn should encourage you to reconcile regularly + with those real world balances - another strong defense against er- + rors. hledger close --assert can help generate assertion entries. + Over time the older assertions become somewhat redundant, and you can + remove them if you like (they don't affect performance much, but they + add some noise to the journal). - o uniqueleafnames - no two accounts may have the same leaf name. The - leaf name is the last colon-separated part of an account name, eg - checking in assets:bank:checking. This encourages you to keep those - unique, effectively giving each account a short name which is easier - to remember and to type in reporting commands. + o uniqueleafnames - no two accounts may have the same last account name + part (eg the checking in assets:bank:checking). This ensures each + account can be matched by a unique short name, easier to remember and + to type. Custom checks - You can build your own custom checks with add-on command scripts. See + You can build your own custom checks with add-on command scripts. See also Cookbook > Scripting. Here are some examples from hledger/bin/: - o hledger-check-tagfiles - all tag values containing / (a forward + o hledger-check-tagfiles - all tag values containing / (a forward slash) exist as file paths - o hledger-check-fancyassertions - more complex balance assertions are + o hledger-check-fancyassertions - more complex balance assertions are passing diff - Compares a particular account's transactions in two input files. It + Compares a particular account's transactions in two input files. It shows any transactions to this account which are in one file but not in the other. @@ -9802,16 +9896,16 @@ Maintenance commands no command-specific flags More precisely: for each posting affecting this account in either file, - this command looks for a corresponding posting in the other file which - posts the same amount to the same account (ignoring date, description, + this command looks for a corresponding posting in the other file which + posts the same amount to the same account (ignoring date, description, etc). Since it compares postings, not transactions, this also works when mul- tiple bank transactions have been combined into a single journal entry. - This command is useful eg if you have downloaded an account's transac- - tions from your bank (eg as CSV data): when hledger and your bank dis- - agree about the account balance, you can compare the bank data with + This command is useful eg if you have downloaded an account's transac- + tions from your bank (eg as CSV data): when hledger and your bank dis- + agree about the account balance, you can compare the bank data with your journal to find out the cause. Examples: @@ -9826,29 +9920,91 @@ Maintenance commands These transactions are in the second file only: + setup + Check the status of the hledger installation. + + Flags: + no command-specific flags + + setup tests your hledger installation and prints a list of results, + sometimes with helpful hints. This is a good first command to run af- + ter installing hledger. Also after upgrading, or when something's not + working, or just when you want a reminder of where things are. + + It makes one network request to detect the latest hledger release ver- + sion. It's ok if this fails or times out. It will use ANSI color by + default, unless disabled by NO_COLOR or --color=n. It does not use a + pager or a config file. + + It expects that the hledger version you are running is installed in + your PATH. If not, it will stop until you have done that (to keep + things simple). + + Example: + + $ hledger setup + Checking your hledger setup.. + Legend: good, neutral, unknown, warning + + hledger + * is a released version ? no hledger 1.42.99-gbca4b39c5-20250425, mac-aarch64 + * is up to date ? yes 1.42.99 installed, latest is 1.42.1 + * is a native binary for this machine ? yes aarch64 + * is installed in PATH ? yes /Users/simon/.local/bin/hledger + * has a system text encoding configured ? yes UTF-8, data files should use this encoding + * has a user config file ? (optional) no + * current directory has a local config ? yes /Users/simon/src/hledger/hledger.conf + * the config file is readable ? yes /Users/simon/src/hledger/hledger.conf + + terminal + * the NO_COLOR variable is defined ? no + * --color is configured by config file ? no + * hledger will use color by default ? yes + * the PAGER variable is defined ? yes less + * --pager is configured by config file ? no + * hledger will use a pager when needed ? yes /opt/homebrew/bin/less + * the LESS variable is defined ? yes + * the HLEDGER_LESS variable is defined ? no + * adjusting LESS variable for color etc. ? yes + * --pretty is enabled by config file ? no tables will use ASCII characters + * bash shell completions are installed ? ? + * zsh shell completions are installed ? ? + + journal + * the LEDGER_FILE variable is defined ? yes /Users/simon/finance/2025/2025.journal + * a default journal file is readable ? yes /Users/simon/finance/2025/2025.journal + * it includes additional files ? yes 15 + * all commodities are declared ? yes 10 + * all accounts are declared ? yes 160 + * all accounts have types ? no 14 untyped + * accounts of each type were detected ? yes ALERXCV + * commodities/accounts are checked ? no use -s to check commodities/accounts + * balance assertions are checked ? yes use -I to ignore assertions + test Run built-in unit tests. Flags: no command-specific flags - This command runs the unit tests built in to hledger and hledger-lib, - printing the results on stdout. If any test fails, the exit code will + This command runs the unit tests built in to hledger and hledger-lib, + printing the results on stdout. If any test fails, the exit code will be non-zero. - This is mainly used by hledger developers, but you can also use it to - sanity-check the installed hledger executable on your platform. All - tests are expected to pass - if you ever see a failure, please report + This is mainly used by hledger developers, but you can also use it to + sanity-check the installed hledger executable on your platform. All + tests are expected to pass - if you ever see a failure, please report as a bug! - This command also accepts tasty test runner options, written after a -- - (double hyphen). Eg to run only the tests in Hledger.Data.Amount, with - ANSI colour codes disabled: + Any arguments before a -- argument will be passed to the tasty test + runner as test-selecting -p patterns, and any arguments after -- will + be passed to tasty unchanged. - $ hledger test -- -pData.Amount --color=never + Examples: - For help on these, see https://github.com/feuerbach/tasty#options (-- - --help currently doesn't show them). + $ hledger test # run all unit tests + $ hledger test balance # run tests with "balance" in their name + $ hledger test -- -h # show tasty's options PART 5: COMMON TASKS Here are some quick examples of how to do some basic tasks with @@ -10259,8 +10415,8 @@ Migrating to a new file If using version control, don't forget to git add the new file. BUGS - We welcome bug reports in the hledger issue tracker (shortcut: - https://bugs.hledger.org), or on the hledger chat or mail list + We welcome bug reports in the hledger issue tracker + (https://bugs.hledger.org), or on the hledger chat or mail list (https://hledger.org/support). Some known issues and limitations: @@ -10268,8 +10424,8 @@ BUGS The need to precede add-on command options with -- when invoked from hledger is awkward. (See Command options, Constructing command lines.) - A UTF-8-aware system locale must be configured to work with non-ascii - data. (See Unicode characters, Troubleshooting.) + A system locale with a suitable text encoding must be configured to + work with non-ascii data. (See Text encoding, Troubleshooting.) On Microsoft Windows, depending whether you are running in a CMD window or a Cygwin/MSYS/Mintty window and how you installed hledger, non-ascii @@ -10301,30 +10457,11 @@ BUGS o You may need to force your shell to see the new configuration. A simple way is to close your terminal window and open a new one. - LANG issues: I get errors like "Illegal byte sequence" or "Invalid or - incomplete multibyte or wide character" or "commitAndReleaseBuffer: in- - valid argument (invalid character)" - Programs compiled with GHC (hledger, haskell build tools, etc.) need - the system locale to be UTF-8-aware, or they will fail when they en- - counter non-ascii characters. To fix it, set the LANG environment - variable to a locale which supports UTF-8 and which is installed on - your system. - - On unix, locale -a lists the installed locales. Look for one which - mentions utf8, UTF-8 or similar. Some examples: C.UTF-8, en_US.utf-8, - fr_FR.utf8. If necessary, use your system package manager to install - one. Then select it by setting the LANG environment variable. Note, - exact spelling and capitalisation of the locale name may be important: - Here's one common way to configure this permanently for your shell: - - $ echo "export LANG=en_US.utf8" >>~/.profile - # close and re-open terminal window - - If you are using Nix (not NixOS) for GHC and Hledger, you might need to - set the LOCALE_ARCHIVE variable: - - $ echo "export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive" >>~/.profile - # close and re-open terminal window + Text decoding issues: I get errors like "Illegal byte sequence" or "In- + valid or incomplete multibyte or wide character" or "commitAndRelease- + Buffer: invalid argument (invalid character)" + hledger usually needs its input to be decodable with the system lo- + cale's text encoding. See Text encoding and Install: Text encoding. COMPATIBILITY ISSUES: hledger gives an error with my Ledger file Not all of Ledger's journal file syntax or feature set is supported. @@ -10348,4 +10485,4 @@ LICENSE SEE ALSO hledger(1), hledger-ui(1), hledger-web(1), ledger(1) -hledger-1.42.99 March 2025 HLEDGER(1) +hledger-1.43.99 June 2025 HLEDGER(1)