Bugfix: use proper built-in file completion with support for subfolders
This commit is contained in:
parent
65ec51c3d9
commit
43b3fb3cae
@ -9,6 +9,14 @@ set -o pipefail
|
|||||||
# contains regex special chars. But it might be no problem because of
|
# contains regex special chars. But it might be no problem because of
|
||||||
# COMP_WORDBREAKS.
|
# COMP_WORDBREAKS.
|
||||||
|
|
||||||
|
# TODO 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 can read from stdin but it does not.
|
||||||
|
|
||||||
# Working with bash arrays is nasty compared to editing a text file. Consider
|
# Working with bash arrays is nasty compared to editing a text file. Consider
|
||||||
# for example grepping an array or mapping a substitution on it.
|
# for example grepping an array or mapping a substitution on it.
|
||||||
# Therefore, we create temp files in RAM for completion suggestions (see below).
|
# Therefore, we create temp files in RAM for completion suggestions (see below).
|
||||||
@ -49,7 +57,9 @@ _hledger_completion_function() {
|
|||||||
# This does not work because assignment to 'files' in the "pipe
|
# This does not work because assignment to 'files' in the "pipe
|
||||||
# subshell" has no effect!
|
# subshell" has no effect!
|
||||||
#compgen -df | grep "^$filenameSoFar" | readarray -t files
|
#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[@]}" )
|
COMPREPLY=( "${files[@]}" )
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user