Bash Completion for the gem Command

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 thoughts on “Bash Completion for the gem Command

  1. 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 &&

    With best regards,

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

    -bash: have: command not found

    Where can I get it?

  3. 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

      unset -v have
      PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&

  4. 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?


  5. 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
  6. 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!!

  7. 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

Your email address will not be published. Required fields are marked *