Skip to content

Instantly share code, notes, and snippets.

@aelsabbahy
Last active October 17, 2017 15:24
Show Gist options
  • Save aelsabbahy/a8a322df29135b303c786ee4516a93e5 to your computer and use it in GitHub Desktop.
Save aelsabbahy/a8a322df29135b303c786ee4516a93e5 to your computer and use it in GitHub Desktop.
Simple script to explain what a command does using https://explainshell.com/
#!/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
@aelsabbahy
Copy link
Author

aelsabbahy commented Oct 17, 2017

CLI wrapper to http://explainshell.com/

Example:

explain ls -ltr

Output:

explainshell.com - ls -ltr

------------------------
list directory contents
------------------------
-l     use a long listing format
------------------------
-t     sort by modification time, newest first
------------------------
-r, --reverse
       reverse order while sorting
------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment