hledger/bin
Simon Michael 2db87333d7 bin: switch scripts to "stack ghc" and "env -S" (#1453)
Using stack's script command meant that the scripts needed to be
compatible, and regularly tested, with a hledger release in stackage,
rather than the latest hledger source. This created hassles for
maintainers, contributors and sometimes for users.

To simplify things overall, we now require script users to check out
the hledger source tree and run the scripts (or, bin/compile.sh) from
there once so they compile themselves. Some notes on alternative
setups are included (in one of the scripts, and referenced by the
others). This ensures that users and our CI tests are building scripts
the same way.

Current stack does not allow a stack options line to be used with the
"stack ghc" command, unfortunately, so instead we are using env's -S
flag, which hopefully has sufficiently wide support by now, and
putting all arguments in the shebang line.

This method will probably require complete explicit --package options,
unlike "stack script", so more testing and tweaking is expected.
Probably we're going to end up with some long shebang lines.

This isn't pretty but seems like a possible way to keep things
manageable.
2021-01-11 21:04:07 -08:00
..
_hledger-chart.hs code: Strip extraneous trailing whitespace from Haskell sources 2019-07-15 16:40:49 +01:00
.gitignore prices: new addon (#486) 2017-01-25 11:50:54 -08:00
aliases.sh move add-ons and scripts to bin/ 2017-01-08 07:28:23 -08:00
compile.sh ci: also test compilation of bin/ add-on scripts 2020-12-30 08:59:03 -08:00
csv.mk doc: move last addon docs out of hledger manual; add hledger-iadd 2017-01-24 15:39:38 -08:00
hledger-balance-as-budget.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
hledger-check-fancyassertions.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
hledger-check-tagfiles.cabal.hs bin: rename hledger-check* per "How to check for errors" 2020-11-27 12:29:54 -08:00
hledger-check-tagfiles.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
hledger-combine-balances.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
hledger-print-location.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
hledger-smooth.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
hledger-swap-dates.hs bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00
README.md ;bin: readme update 2020-12-31 12:24:44 -08:00
scripts.test bin: switch scripts to "stack ghc" and "env -S" (#1453) 2021-01-11 21:04:07 -08:00

Miscellaneous hledger add-ons, bash scripts, example make rules, etc. Things in this directory can be unfinished or out of date.

hledger scripts

The hledger-*.hs scripts here are example/experimental hledger add-on commands. See https://hledger.org/scripting.html for more about this.

They are mostly implemented as stack scripts; if you have stack in your $PATH, they should just work, automatically installing their dependencies if needed. (You can also run them with cabal, or runghc, or compile them with ghc, if you take care of the dependencies yourself.)

Scripts overview, simplest first:

  • hledger-check-tagfiles.hs - check that all tag values containing / exist as file paths
  • hledger-check-tagfiles.cabal.hs - the above as a cabal script
  • hledger-swap-dates.hs - print transactions with their date and date2 fields swapped
  • hledger-print-location.hs - add file path/line number tags to the print command
  • hledger-balance-as-budget.hs - use one balance report as budget goals for another one
  • hledger-combine-balances.hs - show balance reports for two different periods side by side
  • hledger-smooth.hs - incomplete attempt at automatically splitting infrequent/irregular transactions
  • hledger-check-fancyassertions.hs - check more complex account balance assertions

How to:

Install all scripts as add-on commands

$ git clone https://github.com/simonmichael/hledger
# add hledger/bin/ to your $PATH
$ hledger  # scripts now appear in commands list
$ hledger-print-location.hs --help  # run script directly
$ hledger print-location -- --help  # or run it via hledger, -- is needed before script options

Install a single script without getting hledger source

$ cd ~/bin  # somewhere in your $PATH
$ curl -sO https://raw.githubusercontent.com/simonmichael/hledger/master/bin/hledger-check.hs
$ chmod +x hledger-check.hs
$ hledger-check.hs --help
$ hledger check -- --help

Create a new script

The example scripts follow a template that implements hledgers standard command line options and help, so its a good idea to use one as your starting point. The hledger- naming is not required, but it causes scripts to show up in the hledger commands list. On unix, your new script should be marked executable. This should do it:

# While in the hledger source directory:
$ cp bin/hledger-swap-dates.hs bin/hledger-foo.hs
# Customise hledger-foo.hs, at least the command name and help in cmdmode
$ bin/hledger-foo.hs --help
foo [OPTIONS]
  My new foo command.
  ...
$ hledger foo -- --help
foo [OPTIONS]
  My new foo command.
  ...

Run ghcid on a script

# Ensure any extra packages the script imports from are installed in the current package db
# (running the script auto-installs them, but only in your user package db):
$ stack install string-qq
$ stack exec -- ghcid bin/hledger-foo.hs 
...
Ok, one module loaded.
All good (1 module, at 10:50:48)

Run ghci on a script

# Install any extra packages in the current package db, as above:
$ stack install string-qq
$ stack ghci bin/hledger-foo.hs 
...
Ok, one module loaded.
Loaded GHCi configuration from /private/var/folders/r7/f9j9c2zd1k97v47cr84j_qvc0000gn/T/haskell-stack-ghci/d0bde1be/ghci-script
ghci>