From e491f34ddf6d797fb1699f1f6b0fca05a8dbce88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Sat, 12 Jan 2019 12:25:31 +0100 Subject: [PATCH] Bugfix and remove unused code Bug was: Account names with spaces were broken into single completion suggestions, not line by line. --- shell-completion/hledger-completion.bash.m4 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/shell-completion/hledger-completion.bash.m4 b/shell-completion/hledger-completion.bash.m4 index 5d90caed7..a3c288980 100644 --- a/shell-completion/hledger-completion.bash.m4 +++ b/shell-completion/hledger-completion.bash.m4 @@ -23,9 +23,6 @@ hledgerCompletionFunction() { declare subcommand for subcommand in "${COMP_WORDS[@]}"; do if grep -Fxqe "$subcommand" "$HLEDGER_COMPLETION_TEMPDIR/commands.txt"; then - #declare -a options - #readarray -t options <(grep "^$wordToComplete" "$HLEDGER_COMPLETION_TEMPDIR/options-$subcommand.txt") - #COMPREPLY+=( "${options[@]}" ) COMPREPLY+=( $(grep -h "^$wordToComplete" -- "$HLEDGER_COMPLETION_TEMPDIR/options-$subcommand.txt") ) break fi @@ -68,8 +65,13 @@ hledgerCompletionFunction() { # the 'hledger accounts' call. Note that --rules-file - if present - must also # be passed! + declare -a accounts + readarray -t accounts < <(hledger accounts --flat | grep "^$wordToComplete") + COMPREPLY+=( "${accounts[@]}" ) + # Special characters (e.g. '-', ':') are allowed in account names. + # Account names with spaces must be still be quoted (e.g. '"Expens') + # for completion. Setting COMP_WORDBREAKS='' would not help here! COMP_WORDBREAKS=' ' - COMPREPLY+=( $(hledger accounts --flat | grep "^$wordToComplete") ) fi