Last active
October 17, 2017 15:24
-
-
Save aelsabbahy/a8a322df29135b303c786ee4516a93e5 to your computer and use it in GitHub Desktop.
Simple script to explain what a command does using https://explainshell.com/
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 | |
require 'open-uri' | |
require 'nokogiri' | |
require 'erb' | |
if ARGV.size < 1 | |
puts "Usage: explain <COMMAND> [OPTIONS]" | |
exit 1 | |
end | |
command = ERB::Util.url_encode(ARGV.join(' ')) | |
url = URI.parse("https://www.explainshell.com/explain?cmd=#{command}") | |
result = Nokogiri::HTML(open(url)) | |
puts result.xpath('//title').first.content | |
puts | |
result.xpath('//pre').each do |node| | |
puts '-'*24 | |
puts node.content | |
end | |
puts '-'*24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CLI wrapper to http://explainshell.com/
Example:
Output: