DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Run README.md in your terminal
Sebastian Tiedtke
Sebastian Tiedtke

Posted on

Run README.md in your terminal

Documentation has always been a crucial part of onboarding onto a non-trivial system. For this reason, developers of packaged software started including README files as part of their distribution documentation dating back to the mid-1970s.

Today, the readme is still around but has morphed into a markdown-based README.md file that lives in your repo’s version control. It has become part of modern development culture, and you will find them everywhere.

retro.png

Swordfish90’s Apple2 retro terminal viewing rdme’s README.md

Lowering entry barriers for developers

At Stateful, we want to lower development onboarding barriers and make prerequisites, setup, and workflows as approachable as possible. Source code hosting platforms such as GitHub have already elevated the README.md as a repo’s primary entry point in their UX, but they still diverge from code and documentation and we want to see more.

Run README commands straight from my terminal?

Primarily born out of the annoyance of never-ending README copy & paste, our teammate Adam Babik decided to utilize a Markdown Abstract Syntax Tree parser to generate a naive digest of README snippets and make them easily runnable. This is a prototype (take the happy path!), but we are pleased with the initial results. Illustrated here using Husky - a popular solution to manage git hooks:

πŸ’‘ We skipped $ rdme run npm-install for brevity

Running through husky’s example with ease

Running through husky’s example with ease

Let's run through it

The parsing is still far from perfect, but with best-effort pattern-matching of the AST into a data structure of command snippet pairs, we are often able to capture commands and their implied description. The outputted list tries to maintain the order initially defined in the README.md. Feel free to copy & paste the following step-by-step breakdown. You really shouldn’t have to, though, now that you have rdme 😎.

Simply list all commands

$ rdme list
Enter fullscreen mode Exit fullscreen mode

List all commands in your README

Prepare package.json’s scripts for git-pre-commit hook

$ rdme run npm-pkg
Enter fullscreen mode Exit fullscreen mode

Prepare package.json’s scripts for git-pre-commit hook

Now install example pre-commit husky hook

$ rdme run npx-husky
Enter fullscreen mode Exit fullscreen mode

 raw `rdme run npx-husky` endraw  which will install an example husky hook

Trigger the pre-commit hook

$ rdme run git-commit
Enter fullscreen mode Exit fullscreen mode

 raw `rdme run git-commit` endraw

Using a simple rdme run <name> you can run command blocks (check out the tab completion too) without much fuzz (as illustrated above making a sample commit to trigger the git-pre-commit hook). For a simple CLI tool, we have been pleasantly surprised at how natural the experience feels for interacting with tasks (if you like the terminal). You can find some additional examples inside of rdme’s repo.

Maybe in the future we will employ automation to execute the README’s commands continuously and detect outdated docs, but for now let's catch those issues by running them regularly with rdme!

Go ahead and take rdme for a spin

If you are on MacOS and using homebrew, it’s as easy as installing rdme from our tap:

$ brew install stateful/tap/rdme
Enter fullscreen mode Exit fullscreen mode

You can use scoop to install a version of rdme on Windows. However, please note that currently only shell environments (PowerShell is not supported yet) are supported.

$ scoop bucket add stateful https://github.com/stateful/scoop-bucket.git && scoop install stateful/rdme
Enter fullscreen mode Exit fullscreen mode

For all other platforms, please check out the install section in rdme’s README.md.

Much more rdme could do

Using rdme internally has led to a lengthy list of possible improvements, but we’ve intentionally decided to keep it simple and release rdme's codebase as alpha.

Here’s a list of possible improvements:

  • more robust parsing, configurability and/or ML/AI
  • annotating markdown to achieve deterministic snippets
  • introducing interactivity and β€œcolor” into CLI experience
  • embedding run controls&output in README markdown viewer
  • automated ENV resolution, injection of user runtime config
  • C/I testability, as in β€œalways know when you are breaking docs”
  • deterministic order of commands, without building Makefile inside of READMEs
  • what else?

Check out rdme’s GitHub issues to get a better sense of what projects are on the agenda.

Let us know how it goes

If rdme struck the same cord with you or, if you have strong feelings in one way or another, we would love to hear about it. Using the tool you will likely uncover edge cases. Please don't be shy to tell us about them on Discord or just drop a line in the comments below.

Top comments (6)

Collapse
tobiobeck profile image
Tobi Obeck

Cool idea! I could see how this is useful for installation commands or the like that aren't npm scripts (which are listed in package.json anyway).
Would be handy if there was an additional VS Code extension that shows the commands with a run button similar to the npm scripts panel in the explorer side bar.

Collapse
knighttechwork profile image
Randy Knight

This is awesome! πŸŽ‰Thanks 😎

Collapse
thealpha706 profile image
TheAlpha706

πŸ”₯πŸ”₯

Collapse
bobbyiliev profile image
Bobby Iliev

Very cool!

Collapse
andrewbaisden profile image
Andrew Baisden

Wow, awesome this is so useful!

Collapse
pierre profile image
Pierre-Henry Soria ✨

Amazing article! Thanks for sharing this Sebastian! πŸŽ‰

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.