[Bash-completion-devel] How to handle command/keywords with spaces in them?

Benjamin Block bebl at mageta.org
Fri Aug 29 13:03:00 UTC 2014


HejHej,

I was writing a bash-completion for a command of a project I am working
at. Thing is, we have commands like this:

> jailhouse cell stats --name "Hello World"

This "Hello World" is parsed from sysfs and that can be done with simple
bash. But how can I program the bash-completion in a way that it would
auto-complete this:

> jailhouse cell stats --name Hello<tab>

At the moment it can't handle this and would just print the two words as
single option. The corresponding code looks like this:

> local cur quoted_cur quoted
> 
> _quote_readline_by_ref "${COMP_WORDS[COMP_CWORD]}" quoted_cur
> ....
> for n in /sys/devices/jailhouse/cells/*; do
>         _quote_readline_by_ref "${n##*/}" quoted
>         names="${names} ${quoted}"
> done
> ....
> COMPREPLY=( $( compgen -W "--name ${names}" -- ${quoted_cur} ) )

That doesn't work. I see that you guys solved it for stuff like
filenames, but how, I can't seem to figure it out.

Any help would be appreciated (I am not registered on the list).

-- 
The explanation requiring the fewest assumptions is the most likely to be
correct.
		-- William of Occam
--
                                                          best regards,
                                                            - Benjamin Block
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 648 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20140829/f80f826e/attachment.sig>


More information about the Bash-completion-devel mailing list