From f19eb04e8dd9e18b74060eca42e8a0d447496d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Sat, 12 Jan 2019 20:05:35 +0100 Subject: [PATCH] Update completion script artifact --- shell-completion/hledger-completion.bash | 76 +++++------------------- 1 file changed, 14 insertions(+), 62 deletions(-) diff --git a/shell-completion/hledger-completion.bash b/shell-completion/hledger-completion.bash index df3d73976..1cea1f5a4 100644 --- a/shell-completion/hledger-completion.bash +++ b/shell-completion/hledger-completion.bash @@ -5,12 +5,20 @@ # No set -e because this file is sourced and is not supposed to quit the current shell. set -o pipefail -# TODO grep "^$wordToComplete" is (functional) not safe to use if the word +# Note: grep "^$wordToComplete" is (functional) not safe to use if the word # contains regex special chars. But it might be no problem because of # COMP_WORDBREAKS. -# Working with bash arrays is nasty compared to editing a text file. Consider -# for example grepping an array or mapping a substitution on it. +# Note: compgen and compopt is pretty complicated. Piping to +# grep "^$wordToComplete" +# seems like a hack - I'd rather use +# compgen ... -- "$wordToComplete" +# But what options to use? I don't want to use -W because it may exceed the +# maximum command line length. -C "cat file" is not working either. It would be +# best if compgen could read from stdin but it does not. + +# Note: Working with bash arrays is nasty compared to editing a text file. +# Consider for example grepping an array or mapping a substitution on it. # Therefore, we create temp files in RAM for completion suggestions (see below). readonly _HLEDGER_COMPLETION_TEMPDIR=$(mktemp -d) @@ -49,7 +57,9 @@ _hledger_completion_function() { # This does not work because assignment to 'files' in the "pipe # subshell" has no effect! #compgen -df | grep "^$filenameSoFar" | readarray -t files - readarray -t files < <(compgen -df | grep "^$filenameSoFar") + + compopt -o filenames -o dirnames + readarray -t files < <(compgen -f -- "$filenameSoFar") COMPREPLY=( "${files[@]}" ) else @@ -116,7 +126,6 @@ bs bse cf is -a TEXT cat < "$_HLEDGER_COMPLETION_TEMPDIR/generic-options.txt" @@ -1881,60 +1890,3 @@ cat < "$_HLEDGER_COMPLETION_TEMPDIR/options-is.txt" --version TEXT -cat < "$_HLEDGER_COMPLETION_TEMPDIR/options-a.txt" --f --I --b --e --D --W --M --Q --Y --p --U --C --P --C --R --N --E --B --V --h ---declared ---used ---tree ---flat ---drop ---file ---rules-file ---separator ---alias ---anon ---pivot ---ignore-assertions ---begin ---end ---daily ---weekly ---monthly ---quarterly ---yearly ---period ---date2 ---unmarked ---pending ---cleared ---real ---depth ---empty ---cost ---value ---auto ---forecast ---help ---debug ---version -TEXT -