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
, 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 https://unix.stackexchange.com/questions/124539/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?
Asked by Limon
(181 rep)
Aug 12, 2019, 08:48 PM