1

I am using rbenv on Mac OS X. I have autocomplete functionality already for the gem command:

$ gem 
build           environment     lock            query           stale
cert            fetch           mirror          rdoc            uninstall
check           generate_index  outdated        search          unpack
cleanup         help            owner           server          update
contents        install         pristine        sources         which
dependency      list            push            specification   yank

But I often use gem which in order to get the location of an installed gem in order to browse the source. Something like:

gem which sp[tab]
spork-1.0.0rc4        spork-rails-4.0.0     sprockets-2.10.1      sprockets-rails-2.0.1

Mapping directories shouldn't be that hard, but I think that having existing autocomplete functionality may complicate things. I've tried writing custom bash completion functions before but I always get really frustrated with it. This one is also going to have to check the current ruby version with something like rbenv version before picking the directory to check.

  • Is it possible to "tack on" this "sub-command" functionality with bash completion?

I recently learned about Thor which seems to make building command-line programs pretty easy by mapping arguments to classes and methods (just a tangentially related example not a solution for this), but

  • Are there any good resources or frameworks for creating custom bash completion functions?

...or, if there is no such framework, how can I set up the bash completion function as a script so that I can run it and have it output the results? ( Perhaps using something like inotifywait to run the script when it is changed, passing input like "sp" and using the console to debug the output until it works correctly? ) Just hoping there is an easier way to do it because trying to write bash completion is probably one of the most aggravating things I've worked on.

0

I'm not aware of any frameworks or tools that will assist in doing this. About the best thing you'll find is the myriad of examples that are present on your system along with various tutorials on the internet, such as this one titled: Writing your own Bash Completion Function.

The official docs should probably be all you need though.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.