Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • So the gist of autocompletion is that COMPREPLY is an array of possible completions, and the comp* buil-ins are mostlly easy ways to generate these completions? How are spaced handled? Your answer doesn't seem to support spaces in verbs (curve ball, I know). Your file completion woudl also list all the files, I had to change it to compgen -G "${COMP_WORDS[COMP_CWORD]}*.txt" to have the expected completions, but this still doesn't work if there are files with spaces in the filename. Commented Jun 12, 2020 at 12:11
  • @xenoid Sorry, that's more advanced than my bash knowledge (I use zsh). As far as I can tell, to deal with spaces in file names, use local IFS=$'\n' in your completion function. To deal with newlines or wildcard characters in file names, use zsh. Commented Jun 12, 2020 at 12:23
  • @xenoid Ah, looking at examples from bash_completion: use its _filedir function. Commented Jun 12, 2020 at 12:24
  • OK works great. Thx Commented Jun 12, 2020 at 12:44