Github url


by idank

idank /explainshell

match command-line arguments to their help text

8.3K Stars 535 Forks Last release: Not found GNU General Public License v3.0 257 Commits 0 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here: - match command-line arguments to their help text

explainshell is a tool (with a web interface) capable of parsing man pages, extracting options and explain a given command-line by matching each argument to the relevant help text in the man page.


explainshell is built from the following components:

  1. man page reader which converts a given man page from raw format to html (
  2. classifier which goes through every paragraph in the man page and classifies it as contains options or not (algo/
  3. an options extractor that scans classified paragraphs and looks for options (
  4. a storage backend that saves processed man pages to mongodb (
  5. a matcher that walks the command's AST (parsed by bashlex) and contextually matches each node to the relevant help text (

When querying explainshell, it:

  1. parses the query into an AST
  2. visits interesting nodes in the AST, such as:
    • command nodes - these nodes represent a simple command
    • shell related nodes - these nodes represent something the shell interprets such as '|', '&&'
  3. for every command node we check if we know how to explain the current program, and then go through the rest of the tokens, trying to match each one to the list of known options
  4. returns a list of matches that are rendered with Flask

TODO file

Missing man pages

Right now contains the entire archive of Ubuntu. It's not possible to directly add a missing man page to the live site (it might be in the future). Instead, submit a link hereand I'll add it.

Running explainshell locally

To setup a working environment that lets you run the web interface locally, you'll need to:

$ pip install -r requirements.txt # load classifier data, needs a mongodb $ mongorestore dump/explainshell && mongorestore -d explainshell\_tests dump/explainshell $ make tests .............................................................................. ---------------------------------------------------------------------- Ran 79 tests in 3.847s OK

Processing a man page

Use the manager to parse and save a gzipped man page in raw format:

$ PYTHONPATH=. python explainshell/ --log info manpages/1/echo.1.gz store, db = 'explainshell\_tests', host = 'mongodb://localhost' INFO:explainshell.algo.classifier:train on 994 instances INFO:explainshell.manager:handling manpage echo (from /tmp/es/manpages/1/echo.1.gz) up manpage in mapping with src 'echo' INFO:explainshell.manpage:executing '/tmp/es/tools/w3mman2html.cgi local=%2Ftmp%2Fes%2Fmanpages%2F1%2Fecho.1.gz' INFO:explainshell.algo.classifier:classified <paragraph description: do not output the trailing newlin> (0.991381) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph description: enable interpretation of backslash escape> (0.996904) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph description: disable interpretation of backslash escapes> (0.998640) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph description: display this help and exi> (0.999215) as an option paragraph
INFO:explainshell.algo.classifier:classified <paragraph description:> (0.999993) as an option paragraph mapping (alias) echo -&gt; echo (52207a1fa9b52e42fb59df36) with score 10
successfully added echo

Start up a local web server:

$ make serve python \* Running on \* Restarting with reloader

Start up a local web server with docker

# Build docker web and db containers $ docker-compose build $ docker-compose up # Copy dump over to container for than to import it. $ docker cp dump/ explainshell\_db\_1:/tmp/dump # Import classifiers $ docker exec explainshell\_db\_1 mongorestore /tmp/dump # Import a man page $ docker exec explainshell\_web\_1 bash -c "PYTHONPATH=. python explainshell/ --log info /usr/share/man/man1/grep.1.gz" ... successfully added grep.1.gz # Open browser at port 5000 $ open http://localhost:5000 # Restore test db to run tests $ docker exec explainshell\_db\_1 mongorestore -d explainshell\_tests /tmp/dump/explainshell $ docker exec explainshell\_web\_1 make tests .............................................................................. ---------------------------------------------------------------------- Ran 79 tests in 3.847s OK

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.