explainshell icon indicating copy to clipboard operation
explainshell copied to clipboard

any intention on making a cli interface for this?

Open roryfahy opened this issue 2 years ago • 8 comments

roryfahy avatar Dec 02 '22 17:12 roryfahy

would be very much interested in this as well!

xeruf avatar Jan 28 '23 18:01 xeruf

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.

kvalv avatar Mar 02 '23 14:03 kvalv

Nice!

idank avatar Mar 02 '23 14:03 idank

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

danyalaytekin avatar Mar 14 '23 22:03 danyalaytekin

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

cxcorp avatar May 19 '23 16:05 cxcorp

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

hinsxd avatar Sep 27 '23 08:09 hinsxd

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

rpdelaney avatar May 09 '24 15:05 rpdelaney

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

mekb-turtle avatar May 19 '24 05:05 mekb-turtle