Created
January 12, 2009 15:07
-
-
Save Narnach/46008 to your computer and use it in GitHub Desktop.
Show the manpage of a random executable in your $PATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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