Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roryfahy opened this issue Dec 2, 2022 · 8 comments
Open

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

roryfahy opened this issue Dec 2, 2022 · 8 comments

Comments

@roryfahy
Copy link

roryfahy commented Dec 2, 2022

No description provided.

@roryfahy roryfahy changed the title any intention on making a cli interface for ths any intention on making a cli interface for this? Dec 2, 2022
@xeruf
Copy link

xeruf commented Jan 28, 2023

would be very much interested in this as well!

@kvalv
Copy link

kvalv commented Mar 2, 2023

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
Copy link
Owner

idank commented Mar 2, 2023

Nice!

@danyalaytekin
Copy link

danyalaytekin commented Mar 14, 2023

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
Copy link

cxcorp commented May 19, 2023

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
Copy link

hinsxd commented Sep 27, 2023

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
Copy link

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
Copy link

mekb-turtle commented May 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants