It is just a pipe of sed regex filters and all can be viewed/edited
in one place. Add a couple of debug targets to see easily the
effects of regex changes.
This way we can easily edit m4 in m4-mode and the shell script stub
in sh-mode and prevent subtle errors coming from accidental quoting
issues or macros (mis)interpreted by m4.
Make `command-options` a prerequisite of `hledger-completion.bash`.
Currently the build succeeds only because the former takes less time
to finish than all the prerequisites of the latter. If you run a
`make clean && make -j 4`, the build would fail as they are built
in parallel.
Get rid of manually listing unhandled long options:
Instead of listing options requiring an argument one by one in the
case statement in _hledger_compreply_optarg(), the option completion
lists are searched and if the option does require an argument an
empty COMPREPLY is send. Short options are uncounted for and still
need a manual entry.
This necessitated setting $subcommandOptions beforehand, so it is
moved back where it was -- in the sub-command loop in main().
Similarly to long options treatment, suspend space only when
completing what looks like a query or account prefix i.e. something
ending with a colon (:).
Match only lines starting with white space because there are a lot
of option like strings in the discussion section that follows that
are not necessarily what we are after.
Make it obvious that the option expects an argument by appending
the equal sign on completion. Suspend space in this case. The
regular expression in `output-options.sh` is adjusted to take into
account this on processing option strings.
I was looking at how other programs that have an overwhelming
number of sub-commands and options deal with completion, namely
how git does it, and I liked the clean workflow not spitting every
available option until asked for. Hledger's main workflow is:
> hledger COMMAND QUERY
so I have tried to reproduce this with this change. Options are of
course still there, but not shown until you ask for them by entering
a dash on the command line. Also, the `acct:` filter proposes only top
level accounts until there is some input from the user because accounts
tend to be numerous as well.