Add completions for query filters

This commit is contained in:
Jakob Schöttl 2019-01-19 00:23:42 +01:00 committed by Simon Michael
parent 5df9de3abb
commit 3f407a326d
4 changed files with 56 additions and 3 deletions

View File

@ -3,7 +3,7 @@
all: command-options hledger-completion.bash
hledger-completion.bash: hledger-completion.bash.m4 commands-list.txt generic-options.txt
hledger-completion.bash: hledger-completion.bash.m4 commands-list.txt query-filters.txt generic-options.txt
m4 hledger-completion.bash.m4 > $@
generic-options.txt:

View File

@ -76,7 +76,8 @@ _hledger_completion_function() {
# be passed!
declare -a accounts
readarray -t accounts < <(hledger accounts --flat | grep "^$wordToComplete")
readarray -t accounts < <({ cat "$_HLEDGER_COMPLETION_TEMPDIR/query-filters.txt"; hledger accounts --flat; } | grep "^$wordToComplete")
compopt -o nospace
COMPREPLY+=( "${accounts[@]}" )
# Special characters (e.g. '-', ':') are allowed in account names.
# Account names with spaces must be still be quoted (e.g. '"Expens')
@ -128,6 +129,31 @@ cf
is
TEXT
cat <<TEXT > "$_HLEDGER_COMPLETION_TEMPDIR/query-filters.txt"
not:
acct:
amt:
amt:<
amt:<=
amt:>
amt:>=
code:
cur:
desc:
date:
date2:
depth:
note:
payee:
real:
real:0
status:
status:!
status:*
tag:
inacct:
TEXT
cat <<TEXT > "$_HLEDGER_COMPLETION_TEMPDIR/generic-options.txt"
-f
-I

View File

@ -76,7 +76,8 @@ _hledger_completion_function() {
# be passed!
declare -a accounts
readarray -t accounts < <(hledger accounts --flat | grep "^$wordToComplete")
readarray -t accounts < <({ cat "$_HLEDGER_COMPLETION_TEMPDIR/query-filters.txt"; hledger accounts --flat; } | grep "^$wordToComplete")
compopt -o nospace
COMPREPLY+=( "${accounts[@]}" )
# Special characters (e.g. '-', ':') are allowed in account names.
# Account names with spaces must be still be quoted (e.g. '"Expens')
@ -98,6 +99,10 @@ cat <<TEXT > "$_HLEDGER_COMPLETION_TEMPDIR/commands.txt"
include(`commands.txt')dnl
TEXT
cat <<TEXT > "$_HLEDGER_COMPLETION_TEMPDIR/query-filters.txt"
include(`query-filters.txt')dnl
TEXT
cat <<TEXT > "$_HLEDGER_COMPLETION_TEMPDIR/generic-options.txt"
include(`generic-options.txt')dnl
TEXT

View File

@ -0,0 +1,22 @@
not:
acct:
amt:
amt:<
amt:<=
amt:>
amt:>=
code:
cur:
desc:
date:
date2:
depth:
note:
payee:
real:
real:0
status:
status:!
status:*
tag:
inacct: