Add spaces to the end of some Bash autocomplete options, but not to others? Add spaces to the end of some Bash autocomplete options, but not to others? bash bash

Add spaces to the end of some Bash autocomplete options, but not to others?


The feature in in scp's bash completion mentioned by C4H5As that retains the added space is not the ampersand, that is just sed syntax for "replace with match".

You have to change the IFS so compgen does not split the input on spaces but on newlines or tabs:

local IFS=$'\t\n'COMPREPLY=( $(compgen -W "$options" -- $cur) )


You can do it by removing spaces with the corresponding option, then add them back manually for the options where you want them, all using the simple -W ("wordlist") completion:

complete -o nospace -W 'Dproperty= "option1 " "option2 "' javaProgram

Autocompletion will now insert a space after option1 and option2, but none after Dproperty=.


It would be helpful to see the code you have so far.

However, look at the completion code for scp in /etc/bash_completion.d/ssh if you have that. It puts spaces after local filenames but not after hostnames.