Skip to content

Instantly share code, notes, and snippets.

@Narnach
Created January 12, 2009 15:07
Show Gist options
  • Save Narnach/46008 to your computer and use it in GitHub Desktop.
Save Narnach/46008 to your computer and use it in GitHub Desktop.
Show the manpage of a random executable in your $PATH
#!/usr/bin/env ruby
# Command of the day
# Picks a random executable from your path until it finds one with a manpage.
# Use this to learn about some of the really obscure yet really useful scripts that are already on your system.
files = ENV["PATH"].split(":").uniq.compact.map { |path|
Dir.glob(File.join(path,'*')).select {|file| File.file?(file) && File.executable?(file)}
}.flatten.compact.uniq
cotd = File.basename(files[rand(files.size)])
until system "man #{cotd} > /dev/null 2>&1"
cotd = File.basename(files[rand(files.size)])
end
puts "Command of the day is: #{cotd}"
exec "man #{cotd}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment