Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force exact match for `gem list`

Tags:

rubygems

gem list rails used to match everything that began with "rails" (and the documentation still claims it works that way) but at some point it started matching everything that includes rails anywhere in the name. This can get ridiculous, as there are (at the moment I write this, but I'm sure it goes up practically by the hour) 2,764 items that match "rails":

gem list rails --remote | wc -l
2764

Can Rubygems be made to only return exact matches by default? I don't see any commandline switches that force an exact match. Perhaps a setting in ~/.gemrc?

Obviously I can do this by piping the output to other utilities, but that's kind of a pain to do every time you just want to (e.g.) check the latest version of a gem, and it's a lot slower, and forces you to stop and think about a detail that (IMO) is a distraction from whatever problem you're working on.

gem list rails --remote | grep '^rails '

Is there a good way to make this the default?

like image 273
iconoclast Avatar asked Jan 06 '14 18:01

iconoclast


People also ask

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

What is Gemname?

GEMNAME - name of the gem to print information about.

How do I run a gem command?

Press Ctrl+Space to show the available gem executables. In this field, type the command line arguments of the script. Specify the working directory used by the running task. For example, this option is in effect when the running script loads other scripts by relative paths.

What is Gemfile?

Gemfile - A format for describing gem dependencies for Ruby programs. A Gemfile describes the gem dependencies required to execute associated Ruby code. Place the Gemfile in the root of the directory containing the associated code.


1 Answers

You are basically entering a regex on the command line, so

gem list -r ^rails$

does an exact search without piping. I'm using rubygems 2.0.6 and 2.4.5 and it worked on both versions.

I couldn't find anything to put in .gemrc, though. You could easily set up a wrapper shell script for your most common case.

like image 197
alvin Avatar answered Sep 17 '22 22:09

alvin