Vladimir Zhelezov
b97c2043b8
Add install and uninstall build targets
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
1b6f968a6a
Move commands and options parsing into the Makefile
...
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.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
0498b8ff7c
Add stub file to m4 build target prerequisites
...
And as it becomes unwieldy, put all the dependencies in a variable
2021-02-28 08:33:18 +01:00
Caleb Maclennan
4a32ebf8b5
Eliminate dependency on ‘paste’ and ‘parallel’
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
bb8118c771
Isolate shell code in a stub file included by m4
...
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.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
bc66b23520
Fix build race condition
...
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.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
13bf6fdcd8
Amend installation comment
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
bee666704b
Add a comment with example installation instructions
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
99af527f16
Remove _function from function names
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
fdac46d68a
Fix _hledger_extension_completion when called by path...
...
Could break if called with ./funky-path/with-dashes/hledger-ui
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
fb3577d3e0
return 0
...
Shame on me...
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
910e86b4b2
Fix a7dc62d: set $subcommandOptions unconditionally
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
d82e13bb51
Add an automatic check for required option argument
...
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().
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
3eccfb85e0
Remove compopt -o nospace from --{close,open}-acct handler
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
0f8c01f033
Delay setting compopt -o filenames
...
...until just before query completion. It is not desired for
commands and options completion and is better used selectively
only when really needed.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
34dbe3b3a8
Use compopt -o nospace only for a query prefix
...
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 (:).
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
797301c3dc
White space
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
78ce651531
White space, fix alignment
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
1bbf04d310
Edit comments
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
05d483494b
Remove redundant call of _get_comp_words_by_ref()
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
750450915d
Break overly long lines for better readability
...
Hopefully differences are aligned and easily discernible this way
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
83cfd104f9
Remove _hledger_quote(), unused.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
3cabee2470
Remove unnecessary quoting, a matter of consistency...
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
eea7f0d506
Add an early return from option argument completion
...
Do not even enter the case statement if preceding words don't look
like an option
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
b6a4a887b9
White space
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
046421e712
Simplify sub-command loop logic
...
If the cursor is on the sub-command, just offer sub-command
completions and be done with it. It was way over complicated.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
f5d2a6bcc3
Move sub-command options reply out of the for-loop
...
It was just before the `break` statement anyways
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
e2b2c2fb2e
_hledger_compreply_query: minor refactor
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
0361c81da2
Add a couple of sub-commands to the no-query list
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
3a20e91b69
Further refinement of option extraction regex
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
5a88a1437c
Improve option extraction
...
Do not consider lines starting with anything other than white space
followed by a dash.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
a5ccae8f31
Fix regular expression in output-options.sh
...
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.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
40a7549013
Adjust comment obsoleted by previous commit: 4d2a4b0
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
8feb9053ec
Append = to long options requiring an argument
...
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.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
09132ace80
f656ff8 made another early return possible, so do it
...
Also it made a couple of statements redundant, cleaned up.
2021-02-28 08:33:18 +01:00
Vladimir Zhelezov
e6d54f79d7
Postpone options display until after entering a dash
...
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.
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
ddf55a86a4
Rename $wordlist to $complist in _hledger_compgen()
...
Keep to established conventions
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
e2cac96449
Typo in comments
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
d943fa613e
Make sure = is present in COMP_WORDBREAKS
...
Currently option processing logic is based on the assumption that `=` is
a word-breaking character, so make sure it is present in COMP_WORDBREAKS
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
8c14dfb3eb
A non-recursive version of _hledger_compreply_optarg()
...
Feels more streamlined and readable
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
985f041d81
Make hard-coded completion word lists easy to find
...
A quick search for `wordlist=` should be enough to find hard-coded
completions if we need to change them
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
57c79d0050
Simplify condition
...
Knowing the cursor position is enough to decide whether to complete
subcommand or not, and subcommand is already known.
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
c139bb24a7
Minor refactor of main function
...
No functional changes except special treatment of `help` subcommand
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
b195826c0f
Revert "Refactor _hledger_compreply_optarg()"
...
This reverts commit 2fd01d8ef51b897a63a2590556dbb3af7c13ffc9.
Well, I was so wrong...
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
d30913c6a8
Refactor _hledger_compreply_optarg()
...
It used to do a lot more work parsing the command line that is
no longer necessary. Clean up redundant code.
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
9d94f84781
Clarify comment in extension completion function
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
c729708343
Refactor _hledger_extension_completion_function()
...
Reduce number of instructions, remove variables used only once
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
c2da8ac2d4
Fix extension completion
...
When inserting $extensionName in $COMP_WORDS manually, $COMP_CWORD lags
behind by one. Needs a manual adjustment too.
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
4101fdf3bb
Fix duplicate call of _hledger_compreply_optarg()
...
It was called in both conditional branches so it's moved out before
the conditional.
2021-02-28 08:33:17 +01:00
Vladimir Zhelezov
9dc65e4ee5
Helper _hledger_debug() now accepts any number of arguments
2021-02-28 08:33:17 +01:00