Go to file
Simon Michael 1ca448bb45 Merge branch 'bash-completion' (#1410)
An extensive overhaul by @zhelezov of the bash programmable
completions in shell-completions/.

"This was supposed to be just a fix for #1404 but upon visiting the source
several issues became apparent and that is why the commit grew a bit more than
expected. A complete list of changes bellow:

Fix #1404
No more orphaned temporary directories. Commands, options, etc. that used to be
stored in there are included at build-time as here documents in the source.

Fix artifacts in /tmp after build
Upon fixing the above I became aware that the build itself was leaving behind a
heap of artifacts in /tmp that were not taken care of with a make clean.
Fixed by using temporary files and directories in the build directory. Makefile
and build scripts adjusted.

Produce command aliases
Regular expressions in build scripts changed to produce all command aliases
except single letter ones (see below)

Do not propose single letters completions
It is simply not useful and adds a lot of noise. It makes completion slower as
well because you need to hit yes on the prompt:
Display all 200 possibilities? (y or n)
output-options.sh now excludes those.

Query filters simplified
Keep only the prefix of the filter with the colon in query-filters.txt. This
change has two reasons:

Single letter completions are not useful (see above)
It allows for completion suggestions specific to each
Bonus reason: it's a completion engine, not a user manual.
Fix completion impacts on global environment
The completion script was making a couple of changes to the global environment
which had an impact for the rest of the shell session.

set -o pipefail: the change is hidden from the user and could lead to subtle
errors throughout the shell session
COMP_WORDBREAKS=" ": this affects subsequent completions for us and other
programs too. I exclude the colon : from its value and use
compopt -o filenames to handle escaping of special characters for us. I would
like to find a solution without messing with COMP_WORDBREAKS but it is not
straight forward.
Fix hiding of legit subcommands
Completion was hiding all possibilities if a subcommand happens to be the prefix
of another. On typing balance, one should be proposed balancesheet and
balancesheetequity as well.

Return early
Try to complete depending on the current context and return immediately if
successful. Keep completion list relevant and as short as possible.

Context aware completion

Add handlers for option parameter completion, see _hledger_compreply_optarg()
Add handlers for query filters:, see _hledger_compreply_query()
Use --file and --rules-file arguments when proposing completions for the
above, see _hledger()
Propose only top level accounts at first. Again, keep it short and focused.
Custom compgen wrapper
compgen is fairly complicated. There is no way to feed it a word list with
literals. It will mangle your input in so many ways that we cannot trust it. To
work around this several wrappers are used: _hledger_compgen() works with
_hledger_quote_by_ref() to process and escape newline separated input which is
then fed to compgen and finally in COMPREPLY through _hledger_compreply()
and _hledger_compreply_append(). It sounds messy and I guess it is, I would like
to find a more straight forward way to do it. I think it is still a way better
and safer interface with readline than trying to grep our way through.

Replace declare with local
Again, this script is sourced by the shell -- keep variable scopes as narrow as
possible. Oops, they are actually synonymous when used in a function but
local declares our intentions explicitly.

Use compopt -o nosort
Often I resort to using it to keep different groups of completions together.
Whether this is more ergonomic or not is subjective. But our input lists are
already sorted at build-time so why not. Sort manually query-filters.txt when
editing it.

Remove irrelevant comments
And add some new ones :)

I think that is all. Give it a spin, try to abuse it, in and outside of quotes,
with some funky accounts, payees, tags, whatever, and tell me where it breaks or
behaves unexpectedly."
2021-03-05 16:12:08 -08:00
.github ;stack: build with lts-17/ghc-8.10.3 by default 2021-01-29 15:13:06 -08:00
.sandstorm Add --capabilities-header to launcher.sh 2018-06-24 17:44:22 +02:00
bin bin: more robust --package syntax, comma form sometimes fails 2021-02-12 13:55:31 -08:00
checks update dev setup tests 2015-03-16 17:59:06 -07:00
doc cli: rename --infer-value to --infer-market-price 2021-02-05 15:16:39 -08:00
docker package: added helper scripts in docker/ 2019-01-31 12:44:12 -08:00
examples ;gather investing examples 2021-03-03 04:09:41 -08:00
hledger ;bal: doc: tweaks 2021-03-05 14:55:24 -08:00
hledger-install install: 1.20.4 2021-01-29 14:38:40 -08:00
hledger-lib lib: Default to PeriodChange report when using ValueChangeReport. 2021-03-05 10:09:14 -08:00
hledger-ui ui, web: make --man and --info work, similar to hledger 2021-03-03 05:57:31 -08:00
hledger-web ui, web: make --man and --info work, similar to hledger 2021-03-03 05:57:31 -08:00
shell-completion Rebuild completion after the rebase on upstream/master 2021-02-28 08:36:42 +01:00
tools tools: Include more commodities and prices in generated journals. 2021-03-05 10:12:49 -08:00
.ci ;api: another round of hledger-api purging; fix the build 2019-09-11 14:49:22 -07:00
.ctags cli, lib: move functional tests into hledger/test/ 2020-11-16 08:47:41 -08:00
.dockerignore package: added Dockerfile 2019-01-29 16:14:03 -08:00
.editorconfig fix datepicker not closing, linting 2017-12-30 13:44:40 -05:00
.ghci tools: use pretty-simple for ghci output 2020-11-03 08:19:01 -10:00
.gitignore web: --test [-- HSPECARGS] runs the test suite 2020-11-16 14:02:16 -08:00
.hlint.yaml refactor: lib: hlint cleanups 2019-02-14 05:15:49 -08:00
.mailmap doc: use consistent spelling of Mykola Orliuk 2017-03-27 05:47:15 -07:00
.version ;bump version to 1.20.99 2020-12-14 11:28:07 -08:00
azure-pipelines.yml ;api: another round of hledger-api purging; fix the build 2019-09-11 14:49:22 -07:00
bench.sh benchmarks: add some large (140, 1400 columns) tabular reports 2020-11-03 17:30:10 -10:00
cabal.project ;re-enable doctest suite, with a workaround for cabal 3 (#1139) 2020-03-06 18:30:32 -08:00
CHANGES.md ;doc: changelog updates 2020-12-29 10:21:27 -08:00
CONTRIBUTING.md ;doc: link updates 2020-12-26 17:27:27 -08:00
CREDITS.md ;doc: CREDITS cleanup 2020-03-21 18:37:49 -07:00
dev.hs collect some langage pragmas in dev.hs 2019-02-20 18:08:33 -08:00
Dockerfile ;api: another round of hledger-api purging; fix the build 2019-09-11 14:49:22 -07:00
hie.yaml ;tools: silence hls errors for Shake.hs 2020-12-07 12:27:03 -08:00
LICENSE add LICENSE 2008-10-01 07:52:07 +00:00
Makefile ;make functest: bump threads from 16 to 64 2021-01-29 12:09:02 -08:00
Makefile.helpsys make: rename sub-makefiles; start moving site script to make/shake 2019-03-05 18:43:04 -08:00
README.md ;doc: readme: drop badges header 2020-08-21 08:18:26 -07:00
ROADMAP.md ;roadmap: status 2020-08-29 14:45:50 -07:00
Shake.hs ;shake: use --markdown-headings to silence warning (& require pandoc-2.11.2+) 2021-02-17 12:11:15 -08:00
stack7.10.yaml.disabled ;simplify stack.yaml filenames 2020-03-30 15:35:53 -07:00
stack8.0.yaml add missing dep for other stack snapshots; also bump GHC 8.10 to .2 2020-11-11 12:52:44 -08:00
stack8.2.yaml add missing dep for other stack snapshots; also bump GHC 8.10 to .2 2020-11-11 12:52:44 -08:00
stack8.4.yaml add missing dep for other stack snapshots; also bump GHC 8.10 to .2 2020-11-11 12:52:44 -08:00
stack8.6.yaml add missing dep for other stack snapshots; also bump GHC 8.10 to .2 2020-11-11 12:52:44 -08:00
stack8.8.yaml ;stack: build with lts-17/ghc-8.10.3 by default 2021-01-29 15:13:06 -08:00
stack.yaml stack: bump default to lts-17.4/ghc-8.10.4 2021-03-05 14:56:33 -08:00

hledger project README

lightweight, portable, dependable accounting tools

hledger is a computer program for easily tracking money, time, or other commodities, on unix, mac and windows (and web-capable mobile devices, to some extent).

It is first a command-line tool, but there are also terminal and web interfaces, and a Haskell library for building your own programs and scripts (hledger is written in Haskell). hledger was inspired by and is largely compatible with Ledger. hledger is free software available under the GNU General Public License v3+.

hledger aims to help both computer experts and regular folks to gain clarity and control in their finances and time management, but currently it is a bit more suited to techies. I use it every day to:

  • track spending and income
  • see time reports by day/week/month/project
  • get accurate numbers for client billing and tax filing
  • track invoices

Though limited in features, hledger is lightweight, usable and reliable. For some, it is a simpler, less distracting, more future-proof alternative to Quicken or GnuCash.

For more, see the home page: https://hledger.org

Sponsorship

Your support, large or small, helps keep this project strong!
See also https://hledger.org#sponsorship.

Sponsor Simon (project leader): github liberapay paypal

Sponsor the hledger project as an organisation: OpenCollective

Sponsor the hledger project as an individual: OpenCollective

Bounties for specific tasks: all bounties bountysource bounties




license hledger CI on hackage github issues