Skip to content

Instantly share code, notes, and snippets.

@labocho
Last active November 28, 2017 02:55
Show Gist options
  • Select an option

  • Save labocho/9adce7c0102034ba1db7d2b53f6af622 to your computer and use it in GitHub Desktop.

Select an option

Save labocho/9adce7c0102034ba1db7d2b53f6af622 to your computer and use it in GitHub Desktop.
grep for all gems in Gemfile.lock
#!/usr/bin/env ruby
# Usage: bundle-grep -E "^foo"
require "bundler"
lockfile = Bundler::LockfileParser.new(File.read("Gemfile.lock"))
gem_paths = lockfile.specs.map{|lazy_spec| lazy_spec.__materialize__.full_gem_path }
command = ["find", *gem_paths, "-type", "f"].shelljoin + " | " +
["xargs", "grep", *ARGV].shelljoin
exec(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment