8000 GitHub - zongou/cr_old: markdown codeblock runner
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

zongou/cr_old

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CR (Codeblock Runner)

Run markdown codeblocks by its heading.
It searches(case ignored) for a cr.md file, then .cr.md, then README.md in the current or parent directories.
You can refer the markdown file to use with option -f or --file.
For more information, run with option --help.

For example:

./cr test sh -- foo bar

Features:

  • scoped env

Prefixed env

  • MD_EXE
  • MD_FILE

Custom env

key value
scope_root foo
scope global

The basic idea is make markdown work like makemenuconfig

Test with README.md

  1. find the target markdown file in current dir in the name of README.md case ignored, if not found, search upper dir, or direct a file with -f or --file option
  2. run Tag as subcommand, following arguments as positional arguments.

To-Does

  • depends
  • target toolchain

Test non-configured languages

Show not be displayed

Configure

Run go mod tidy

go mod tidy

Build

Build this program

go build -ldflags="-w -s"

Install

Install this program

go run . build
PROG=$(basename "${MD_EXE}")
if command -v sudo >/dev/null; then
    sudo install "${PROG}" "/usr/local/bin/${PROG}"
elif test "${PREFIX+1}"; then
    install "${PROG}" "${PREFIX}/bin/${PROG}"
fi

Uninstall

Uninstall this program

PROG=$(basename "${MD_EXE}")
if command -v sudo >/dev/null; then
    sudo rm $(command -v "${PROG}")
elif test "${PREFIX+1}"; then
    rm $(command -v "${PROG}")
fi

Benchmark

Benchmark this program

go run . build
hyperfine "${MD_EXE} test env" "$@"

Test

Test this program

key value
scope_test bar
scope test
go run . build
${MD_EXE} test env
${MD_EXE} test env sub
${MD_EXE} test args
${MD_EXE} test multiple
echo Hello | ${MD_EXE} test stdin
echo "cr file size: $(du -ahd0 ${MD_EXE} | ${MD_EXE} test awk)"

env

Test scoped env

key value
scope_env 123
scope env
for env in \
    MD_EXE \
    MD_FILE \
    scope_root \
    scope_test \
    scope_env \
    scope; do

    eval echo "env ${env}=\${${env}}"
done

sub

Test scoped env (heading +1)

key value
scope sub
echo "sub scope=${scope}"

sh

Test shellscript

echo "shellscript with arguments: $*"

js

Test javascript

console.log(`nodejs with arguments: ${process.argv}`);

py

Test python

import sys

print("python with arguments: %s" %(sys.argv))

awk

Print first column in awk

{print $1}

args

Test program with arguments

${MD_EXE} test sh -- a b c
${MD_EXE} test js -- a b c
${MD_EXE} test py -- a b c

multiple

Test multiple codeblocks

echo codeblock 1 in multiple
echo codeblock 2 in multiple

stdin

Read stdin in shell

echo "stdin: $(cat)"

Reset

Reset to the initial commit

git reset --hard $(git rev-list --max-parents=0 HEAD)
git pull

Inspired by mask and xc.

About

markdown codeblock runner

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0