idank / explainshell

match command-line arguments to their help text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

any intention on making a cli interface for this?

roryfahy opened this issue · comments

commented

would be very much interested in this as well!

I made a small script that does a request to explainshell and parses its output. It doesn't parse properly in all places, but it's a good starting point:

Uses pup for the html parsing: https://github.com/ericchiang/pup

#! /usr/bin/bash
# file stored in /tmp/x
input="$@"
parsed="${input// /+}"

curl -s -X GET "https://explainshell.com/explain?cmd=${parsed}"  | pup '.help-box text{}'

Saving to /tmp/x and chmod +x /tmp/x, I can do this:

$ x curl -siX

transfer a URL
-s, --silent
       Silent or quiet mode. Don't show progress meter or error messages.  Makes Curl mute.
-i, --include
       (HTTP) Include the HTTP-header in the output. The HTTP-header includes  things  like  server-name,
       date of the document, HTTP-version and more...
-X, --request <command>
       (HTTP)  Specifies  a  custom  request  method to use when communicating with the HTTP server.  The
       specified request will be used instead of the method otherwise used (which defaults to GET).  Read
       the  HTTP  1.1 specification for details and explanations. Common additional HTTP requests include
       PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.

       (FTP) Specifies a custom FTP command to use instead of LIST when doing file lists with FTP.

       If this option is used several times, the last one will be used.

Nice!

Let's get this party started

explain_lol() {
    local input="$@"
    local parsed="${input// /+}"
    lynx "https://explainshell.com/explain?cmd=${parsed}" \
        -dump \
        -width=160 \
        -nolist | tail -n +8
}

Who's next

Here's a bash script I use for opening explainshell.com for a query in the system's default browser.

Save as wtf in some dir that's in your PATH (and install jq if you don't already have it):

#!/bin/bash
set -euo pipefail

args="$@"
query=$(printf %s "$args" | jq -sRr @uri)
url="https://explainshell.com/explain?cmd=$query"

if command -v xdg-open &> /dev/null
then
    # linux, probably
    xdg-open "$url"
elif command -v cmd.exe &> /dev/null
then
    # Windows WSL2
    cmd.exe /c start "$url"
else
    # assume macOS
    open "$url"
fi

then you can just

wtf 'curl -vSL0 http://example.com'

to open that in a browser