Skip to content

Instantly share code, notes, and snippets.

@samueldr
Created September 21, 2019 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueldr/43f3c24b49b3b447c6611c06dec0f94a to your computer and use it in GitHub Desktop.
Save samueldr/43f3c24b49b3b447c6611c06dec0f94a to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "open3"
require "pp"
name = ARGV.shift
search = "^/bin/#{name}$"
cmd = ["nix-locate", "-1wr", search]
stdin, stdout, stderr, wait_thr = Open3.popen3(*cmd)
out = (stdout.gets(nil) or "").split("\n")
stdout.close
attrs = out
.select { |s| s[0] != "(" }
.map{ |s| s.sub(/\.out$/, "") }
.sort
STDERR.puts "#{name}: command not found"
if out.length.positive? then
STDERR.puts ""
STDERR.puts " → #{name} is provided by:"
attrs.each do |attr|
STDERR.puts " * #{attr}"
end
end
exit 127
# vim: ft=ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment