Parse bash comments as if they were YAML frontmatter, almost https://twitter.com/HorseAJ86/status/1258247206835941376
Go to file
AJ ONeal 76cfb79542 first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
.gitignore first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
.prettierrc first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
LICENSE first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
README.md first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
example.sh first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
package-lock.json first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
package.json first (and hopefully final) commit 2020-05-06 21:58:55 -06:00
shmatter.js first (and hopefully final) commit 2020-05-06 21:58:55 -06:00

README.md

Shmatter

Parse bash comments as if they were frontmatter.

It's not really YAML, but it's intended to look like it!

Example

Consider this bash file:

#!/bin/bash

# title: Foo Bar
# tagline: Messes stuff up
# homepage: https://example.com/foobar
# description: |
#   Foo Bar is a community-festered, government-driven destruction (GDD) system.
# examples: |
#
#   Really mess something up
#
#   ```bash
#   foobar my-file.txt
#   ````
#
#   Mess up an entire volume, forcefully and recursively
#
#   ```bash
#   foobar -rf /
#   ```

rm -i "${0}" "${1}"

Now consider parsing it with shmatter:

var shmatter = require("shmatter");
var bash = fs.readFileSync("./myscript.sh", "utf8");
var meta = shmatter(bash);

console.log(meta);

This is what you'd get:

{
  title: 'Foo Bar',
  tagline: 'Messes stuff up',
  description: '<p>Foo Bar is a community-festered, government-driven destruction (GDD) system.</p>\n',
  examples: '<p>Really mess something up</p>\n' +
    '<pre><code class="language-bash">foobar my-file.txt</code></pre>\n' +
    '<p>Mess up an entire volume, forcefully and recursively</p>\n' +
    '<pre><code class="language-bash">foobar -rf /</code></pre>\n',
  homepage: 'https://example.com/foobar'
}

Why?

Pfff... go ask yourself!

I know it was a dumb idea. I've moved on. I'm healing... but why are you here?