Skip to content

Instantly share code, notes, and snippets.

@samueldr
Last active November 3, 2018 01:46
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/6b0bc554f14545ec6e00ad95c3d34058 to your computer and use it in GitHub Desktop.
Save samueldr/6b0bc554f14545ec6e00ad95c3d34058 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
command_not_found_handle ()
{
if ( type -t command-not-found > /dev/null ); then
command-not-found "$@";
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment