4

I have a simple bash completion script that essentially invokes my (non-bash) program and set its output to COMREPLY, i.e.

COMPREPLY=( $(my-program -- "${COMP_WORDS[@]}") )

Some of the options accept comma separated value, is there a way to handle suggestion only for the last item? Let's say the user types -v opt1,opt2,o<TAB><TAB>, let's say my program finds out the the valid options at this point are opt3 or opt4. If I just return those 2 and press TAB the output changes to just o (entire prefix gone). It works if I return opt1,opt2,opt3 and opt1,opt2,opt4, but that doesn't look nice.

Possible solution is to do something like Bash completion for comma-separated values, that is, invoke my-program to generate [opt3, opt4], and pass that as word list to compgen with opt1,opt2, as prefix. But that requires duplicating some logic in the bash script as in my-program . Is there a better way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.