Skip to content

Instantly share code, notes, and snippets.

@samueldr samueldr/command-not-found Secret
Created Sep 21, 2019

What would you like to do?
#!/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")
attrs = out
.select { |s| s[0] != "(" }
.map{ |s| s.sub(/\.out$/, "") }
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}"
exit 127
# vim: ft=ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.