Subscribe to
Posts
Comments

The gem command is the command line user interface to the RubyGems system for managing Ruby packages.

This command has a few sub-commands itself and a long list of options that differ per sub-command. Remembering and typing them can be tedious, but thankfully, if you are using the bash command shell, it can help with this task. It only has to be told how.

I’ve packaged the how in this file. Copy it to /etc/bash_completion.d and hope that your bash installation picks it up the next time you start a shell.

On Debian/Linux system that’s just how it works. If this does not work on your particular version of Linux or Unix, you’ll have to look up how completions are handled on your system.

10 Responses to “Bash Completion for the gem Command”

  1. on 21 Mar 2007 at 01:31Chepel

    Thank you for the very handy function!
    This is exactly what I was looking for…

    But I’m afraid you’ve missed one line in that file:

    have gem &&
    _gem()
    {
    #…

    With best regards,
    Chepel

  2. on 21 Mar 2007 at 02:14michael

    Chepel, thanks for pointing this out. I’ve changed the completion file accordingly.

  3. on 07 Jun 2008 at 15:17George

    I hope you guys don’t mind; I’ve added gem name completion, updated for v1.1.1, and put up on github. Full credits left intact of course.

    http://github.com/george-ogata/ruby-bash-completion

    Thanks for your efforts!

  4. on 08 Jun 2008 at 11:38Dr Nic

    I don’t seem to have a ‘have’ command

    -bash: have: command not found

    Where can I get it?

  5. on 08 Jun 2008 at 12:15michael

    Nic: the function have ought to be defined in /etc/bash_completion. I don’t know what you need to install on your system to get that file, on Debian/Linux it is part of the bash_completion package.

    Anyway, have is defined like this

    have()
    {
      unset -v have
      PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
      have="yes"
    }
    

  6. on 09 Jun 2008 at 07:51Dr Nic

    Awesome, working a treat now.

  7. on 08 Oct 2008 at 01:22werutzb

    Hi!

    I want to extend my SQL experience.
    I red so many SQL books and want to
    read more about SQL for my work as db2 database manager.

    What can you recommend?

    Thanks,
    Werutz

  8. on 12 Oct 2008 at 18:05michael

    Werutz, somehow your question doesn’t fit in very well in this place. Also, if you’ve read many SQL books already, it is hard for me to suggest any more without knowing what you already know.

    Anyway, here are a few

    • Garcia-Molina et al: Database Systems: The Complete Book
    • Halpin/Morgan: Information Modeling and Relational Databases
    • Faroult: Refactoring SQL Applications
  9. on 08 Apr 2010 at 23:30Micah Elliott

    I was seeing errors like:

    No such file or directory – ~/.gem/latest_source_cache (Errno::ENOENT)
    cat: ~/.gem/all_names.completion: No such file or directory

    Just did a “touch ~/.gem/all_names.completion” to create the dummy file and now everything working nicely (commands and all their args!); not sure why. Thank you for the highly valuable completion!!

  10. on 08 Apr 2010 at 23:54Micah Elliott

    I’m noticing now that this completion is included in Ubuntu Lucid Lynx, as part of rubygems1.8 (and surely 1.9). Cool. Unfortunately, it only works if you invoke as `gem1.8`, not just: `gem `

Leave a Reply

Fork me on GitHub