Force exact match for `gem list`

gem list rails used to match everything that started with "rails" (and the documentation still claims that it works that way) , but at some point it started matching everything that includes rails anywhere. This may seem ridiculous, because there are (at the moment I am writing this, but I'm sure it rises by almost an hour) 2.764 elements that correspond to the "rails":

 gem list rails --remote | wc -l 2764 

Can Rubygems only make exact matches by default? I do not see any command line switches that force exact matching . Perhaps setting in ~/.gemrc ?

Obviously, I can do this by passing the output to other utilities, but it’s such a pain every time you just want (for example) to check the latest version of the gem, and it is much slower, and makes you stop and think about the details, which (IMO) detract from any problem you are working on.

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

Is there a good way to do this by default?

+6
source share
3 answers

You basically type in the regular expression on the command line, so

 gem list -r ^rails$ 

Performs accurate searches without piping. I use rubygems 2.0.6 and 2.4.5, and it worked in both versions.

I could not find anything to add .gemrc. You can easily install a shell script shell for the most common case.

+6
source

If you want to find gems starting with "rails", you can use the search bar starting with "^":

 gem list ^rails+ --remote 

I tried list with version 1.8.24 rubygems where the behavior is described in the documentation, but for rubygems 2.2.1 you have to use this one.

+2
source

They seem to have added an option in version 2.7.3 or so. I do not have it in 2.5.1.

http://guides.rubygems.org/command-reference/#gem-list

 -e, -​-exact - Name of gem(s) to query on matches the provided STRING 

If you are on Windows, you need to use quotes for REGEX, otherwise it will not work.

 gem list "^pg$" --remote --all 
0
source

All Articles