Autocomplete of filename in directory
Try:
_codeComplete()
{
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(ls /something/)" -- $cur) )
}
complete -F _codeComplete hi
You need to specify the -W
option in compgen
and also quote the command which produces the wordlist.
More information on how to write completion functions on this blog: Writing your own Bash Completion Function