0

I'm trying to write a bash completion function that works for strings containing spaces and punctuation, even quotes may be in there.

I extract these strings with sed from files and thus have them as a several lines of text where each one contains a target string for completion. However, all the ways I tried to pass this to compgen -W, I always get completion for the individual words only.

tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

0

There is a variable COMP_WORDBREAKS that defines which characters are treated as words' separators. Tuning this variable you can try to achieve what you want.

From bash(1):

COMP_WORDBREAKS — The set of characters that the Readline library treats as word separators when performing word completion. If COMP_WORDBREAKS is unset, it loses its special properties, even if it is subsequently reset.

Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
  • It's best to avoid changing `COMP_WORDBREAKS` (note the typo in your answer) since doing so can break other completions. In all of `/etc/bash_completion` and `/etc/bash_completion.d/*` on my system, only `/etc/bash_completion.d/git` changes it and that's just to *ensure* that it contains a colon (which it does by default). – Dennis Williamson Jun 17 '12 at 10:56
  • 1
    @Dennis: yes, that's right, but (1) this variable exists, and (2) to change this variable is the only way to solve the task. But I agree with you: one must remember that when one changes this variable it is quiet possible to get some side effects. – Igor Chubin Jun 17 '12 at 11:01
  • I'm not sure that changing COMP_WORDBREAKS is the only way. Somehow it works for filename completion. Unfortunately, I don't understand _how_. I've looked at _filedir (in /etc/bash_completion), but I don't get it. – Michael Schuerig Jun 17 '12 at 11:06