views:

143

answers:

1

I sweated over the question above. The answer I'm going to supply took me a while to piece together, but it still seems hopelessly primitive and hacky compared to what one could do were completion to be redesigned to be less staticky. I'm almost afraid to ask if there's some good reason that completion logic seems to be completely divorced from the program it's completing for.

+8  A: 

I wrote a command line library (can be seen in scala trunk) which lets you flip a switch to have a "--bash" option. If you run

./program --bash

It calculates the completion file, writes it out to a tempfile, and echoes

. /path/to/temp/file

to the console. The result is that you can use backticks like so:

`./program --bash`

and you will have completion for "program" in the current shell since it will source the tempfile.

For a concrete example: check out scala trunk and run test/partest.

extempore
You can get rid of temprary file by using here strings:source /dev/stdin <<<"$(./program --bash)"
Jürgen Hötzel
Yeah, I had encountered that, but in the formulation I saw it didn't work on OSX. Yours does! Thank you much.
extempore