Show HN: A Markdown based alternative to package.json scripts and Makefiles

github.com

14 points by timz 2 days ago

`x.md` allows you to organise your cli scripts in one or several markdown files, by mix and matching different scripting languages for various commands, such as zsh/bash/sh, python or javascript.

Handy for replacing one-line-based `package.json` scripts or `Makefile`s.

One can also write documentation and explanations to various commands in same `x.md` markdown file. ZSH autocompletions are also working, suggesting you the most relevant available commands from your `x.md` files.

Most editors highlight correctly most languages in the markdown code blocks, even when you use several scripting languages.

Provided the following example (x.md file in the root of your project), one can run in a terminal:

    $ x weather-tomorrow
or

    # x generate-password



    --- An example of x.md file ---

    # hello

    Prints "Hello" to `stdout` using Zsh.

    ```zsh
    echo "Hello"
    ```

    # world

    Just prints "World" to `stdout` using JavaScript.

    ```js
    console.log("World");
    ```

    # weather-tomorrow

    Prints the weather for tomorrow to `stdout` using Zsh.

    ```zsh
    curl wttr.in/tomorrow
    ```

    # generate-password

    Prints a random password to `stdout` using Python.

    ```python
    import random
    import string

    length = 16

    characters = string.ascii_letters + string.digits + string.punctuation
    password = ''.join(random.choice(characters) for _ in range(length))
    print(password)
    ```
    --- end of x.md ---



The syntax is simple, each command is a level 1 header followed by optional documentation in markdown notation, and followed by annotated (which interpreter to use) code block.

One can type `--help` after `x my-command` to print out the help associated with that command.

It is possible to have multiple files with scripts, just put them in the `x` folder with `.md` extension.

Would be very grateful for any suggestions or other feedback.

Thank you.

porridgeraisin 2 days ago

It'll be nice if you could make it level 2 headers. Reason: if we want to make it html to display as a webpage, we won't end up with multiple H1s, and we can have a H1 for like the name of the app or something.

  • timz a day ago

    Great suggestion. On it

az09mugen 2 days ago

That's an interesting idea you had, it makes me think of a mix between a jupyter notebook and a makefile, sort of, based on md files. I like the concept, but I need to test it to see if it fits my needs. Just a question about python and zsh, do they need to be pre-installed in your OS and accessible from PATH, that's it ?

  • cobalt60 a day ago

    ansible for markdown?

zahlman a day ago

>One can type `--help` after `x my-command` to print out the help associated with that command.

I assume that there is no support for the scripts having their own command-line arguments? Or how do you disambiguate?

Anyway, this seems like an interesting demo, but it's hard to imagine the use case.

  • timz a day ago

    When --help is provided, the help text from x.md is printed. Otherwise all the command line parameters are passed to the actual script that implements the command.

timz a day ago

published 0.3 version pnpm install -g @tzador/x.md

- better --help messages with or without command - ## level 2 headers are used - the temp file is created in current folder, like that importing npm modules from current project works