idank / explainshell

match command-line arguments to their help text
GNU General Public License v3.0
13.17k stars 787 forks source link

any intention on making a cli interface for this? #307

Open roryfahy opened 1 year ago

xeruf commented 1 year ago

would be very much interested in this as well!

kvalv commented 1 year ago

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.
idank commented 1 year ago

Nice!

danyalaytekin commented 1 year ago

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

cxcorp commented 1 year ago

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

hinsxd commented 1 year ago

Made a simple wrapper for this :)

https://github.com/hinsxd/xshell

Usage:

$ npm i -g @hinsxd/xshell
$ xshell 'your_command_here'

or

$ xshell # you will be prompted
? Enter command to explain
  your_command_here
rpdelaney commented 4 months ago

Here's how I've been doing it.

#!/usr/bin/env bash
#
# explain a shell command using explainshell.com
#

if ! command -v w3m >/dev/null 2>&1; then echo "Missing dependency: w3m" 1>&2; exit 1; fi

grep -v -e explainshell -e • -e □ -e "source manpages" < <(w3m -dump "http://explainshell.com/explain?cmd=$(tr ' ' '+' <<< "$@")")

# EOF
mekb-turtle commented 4 months ago

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

explain_lol() {
    local input
    for input in "$@"; do
        local parsed="$(printf "%s" "$input" | jq -srR @uri)"
        lynx "https://explainshell.com/explain?cmd=${parsed}" \
            -dump \
            -width=160 \
            -nolist | tail -n +8
    done
}

works with multiple at a time, and properly escapes the command using jq