Question

There is a way to run commands in bash like this:

echo ls | bash

I need to unit-test bash completion, and I'm curisous if there is a way to pass a press to Tab this way to get the command completed, something like this:

# This doesn't work, but I think you get the idea
echo chromi$'\t' | bash

Is that possible? Or maybe you can suggest another way to unit-test bash completion?

Was it helpful?

Solution

Take a look at compgen, a builtin command which lets you generates completion matches the same way bash does.

$ compgen -c unam
uname

Alternatively, run bash in interactive mode with -i. Then it will perform Tab-completion.

$ bash -i <<< $'unam\t'
$ bash -i <<< $'unam\t'
$ uname 
Darwin
$ exit

OTHER TIPS

$ printf 'makeinf\t' | bash --norc -i
[user@host ~]$ makeinfo
[user@host ~]$ exit

works here. Set PS1 as well if you don't need the prompt:

$ printf 'makeinf\t' | PS1='' bash --norc -i
makeinfo
exit
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top