Bash completion support for rubygems.
I have useed these versions of rubygems a lot during development of this script and in my general ruby use:
Other versions shold work fine regardless unless the
gem suddenly changed. It's probably worth
trying on any version that's even remotely "recent-ish".
Put rubygems-completion.bash in one of the following locations:
or otherwise make sure it is sourced into your shell.
You can apply completion to your own function
or alias with
_gemcomp. I recommend using this
if possible, instead of calling
for future compatability.
_gem handles completion for the
gem command itself. For example:
alias rg="command /some/obscure/path/to/gem" _gemcomp _gem rg
If you want to alias a specific gem command, hook
directly to the command's completion function
instead of going through
_gem. The command functions
are named by the command name itself prefixed with
_gem_foo for the
gem foo command).
alias gi="command gem install --verbose" _gemcomp _gem_install gi
Initially, I dynamically pulled some of the completion
lists out of gem itself, but that turned out to be VERY
slow in practice. An extra second or two on each execution
.bashrc is just too much delay.
It might be practical to have several versions of the options, and select them by a simple version user-setting, but... that's not really any different than just choosing the correct version of the file to load in the first place.
I'm open to suggestions, though, if anybody has an idea on how to do this efficiently.
I'm currently experimenting with a compromise on the above dynamic-vs-speed issue: precompiling the what I parse out of the gem command into to bash arrays. It would require triggering a "recompile" task when rubygems is updated, but I suspect that's not too big of an issue.
I will never change the default of this script away form the the "inoffensive and fast" default that it has right now, but an optional dynamic-update feature could be useful.
At a minimum, I need to find the various
gems so the top-level command list can be completed correctly,
even when gem itself has been extended.
Distributed under the GNU General Public License, version 2.0.