mbrubeck/compleat

Problem creating a completion file for "vv"

joelthelion opened this issue · 2 comments

Hi,

I have created a simple completion file for vv, a medical image viewer:

image = !ls -1 | grep -E '\.(mhd|dcm|png|jpg|vox)$' ;
vector = !ls -1 | grep -E '(\.vf|.*vf.*\.mhd)$' ;

vv <image> [ <image> | --vf <vector> | --overlay <image> ] ...

The first word () is completed alright, however if I type the following:

vv 4d_lungs_iso2.mhd --vf

in a directory containing the following files:

4d_from_60_to_50_iso2.mhd  4d_lungs_iso2.mhd  stats        vf_demon_4d_60_to_50.mhd  vf_ffd_4d_60_to_all.mhd
4d_from_60_to_50_iso2.raw  4d_lungs_iso2.raw  ventilation  vf_demon_4d_60_to_50.raw  vf_ffd_4d_60_to_all.raw

I get the following completions:

4d_from_60_to_50_iso2.mhd   --overlay                   vf_demon_4d_60_to_50.mhd
4d_lungs_iso2.mhd           --vf                        vf_ffd_4d_60_to_all.mhd

when I would expect:

vf_demon_4d_60_to_50.mhd  vf_ffd_4d_60_to_all.mhd

Am I missing something? Or is this a bug?

Thanks for the bug report!

This happens because compleat thinks that your "--vf" could be either an <image> or the --vf option. (For performance reasons it runs the image shell command only if it's completing the last word on the command line; otherwise it just matches anything.)

I could fix this by (optionally?) allowing completers to run a shell command to generate matches mid-command-line. Another solution that would be faster (but maybe more complicated for users) is a "prioritized choice" operator. Then you could write something like this:

vv [--vf <image> || --overlay <image> || <image>] ...

and then the <image> pattern would be tried only if --vf and --overlay did not already match the current word.

Finally, I've been thinking about giving special treatment to any argument starting with dashes, so they would be distinguished somehow from other things like filename arguments.

I'll try out one or more of these ideas sometime, and I'll let you know what I come up with...

Thanks for your answer! And thanks again for the great software, you're really filling a void here.