From 1cd979ae18bc641452789de2252f18c7f4d62f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Fri, 11 Jan 2019 23:41:45 +0100 Subject: [PATCH] Bugfix: Must use array here because of word splitting --- shell-completion/hledger-completion.bash.m4 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shell-completion/hledger-completion.bash.m4 b/shell-completion/hledger-completion.bash.m4 index 940cbc0bf..a6623eff8 100644 --- a/shell-completion/hledger-completion.bash.m4 +++ b/shell-completion/hledger-completion.bash.m4 @@ -1,4 +1,4 @@ -#!/bin/bash + # Completion script for hledger. # Created using a Makefile and real hledger. @@ -52,7 +52,12 @@ hledgerCompletionFunction() { if [[ -n $completeFiles ]]; then #COMP_WORDBREAKS='= ' - COMPREPLY+=( $(compgen -df | grep "^$filenameSoFar") ) + declare -a files + # 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") + COMPREPLY=( "${files[@]}" ) else COMPREPLY+=( $(grep -h "^$wordToComplete" -- "$HLEDGER_COMPLETION_TEMPDIR/commands.txt" "$HLEDGER_COMPLETION_TEMPDIR/generic-options.txt") )