Bash Autocompletion - How to pass this array to compgen without significant whitespace being collapsed?
Why bother with compgen
? Just add them to COMPREPLY manually. The following will complete the matching filenames from /some/path
, handling filenames safely.
some_completion_function() {
local files=("/some/path/$2"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]##*/}" )
}
It's not possible to have compgen
handle filenames safely.