kevmoo / completion.dart

A packaged to add shell command completion to your application
https://pub.dev/packages/completion
BSD 3-Clause "New" or "Revised" License
60 stars 11 forks source link

Need a way to access the generated script from Dart code #1

Closed georgelesica-wf closed 6 years ago

georgelesica-wf commented 8 years ago

We're using completion.dart for a dev tool (dart_dev). We'd like to be able to provide a facility for doing something like below to register the completions in a .bashrc or similar, but it doesn't appear to be possible.

source "$(pub global run dart_dev bash-completion)"

My intention was to just put the generated completion script in lib/ and then write the path to stdout (which would make the above work). However, the Platform.script attribute is a URL when the app is run as a global, something like http://localhost:60270/dart_dev.dart, so we have no way of getting to lib/.

Another option would be to generate the script on the fly and use eval instead of source in the snippet above, but then we'd need to either install completions.dart globally and run it, which seems overly roundabout, or move most of the code in the completions.dart bin script into lib/ so the completions could be generated via Dart.

I will put up a PR that does the latter later today, but obviously if there is just a convenient way to get the path to a package's lib/, that would be the easiest way to get to where we want to be.

kevmoo commented 6 years ago

Is this still important, @georgelesica-wf ?

PRs welcome!

georgelesica-wf commented 6 years ago

Wow, I'd forgotten about this. I'll close it for now. It'd still be nice to have, but it's not pressing.