exec runme ls
cmp stdout golden-list.txt
! stderr .

exec runme ls --json
cmp stdout golden-list-json.txt
! stderr .

exec runme ls --allow-unnamed=true
cmp stdout golden-list-allow-unnamed.txt
! stderr .

! exec runme ls --filename nonexistent.md
stderr 'failed to open markdown file .*/nonexistent.md: no such file or directory'
! stdout .

env SHELL=/bin/bash
exec runme run echo
stdout 'Hello, runme!'
! stderr .

env SHELL=/bin/bash
exec runme run --filename README.md --index 0
stdout 'Hello, runme!'
! stderr .

env SHELL=/bin/bash
exec runme run --filename README.md echo-1
stdout '1\n2\n3\n'
! stderr .

env SHELL=/bin/bash
exec runme run --allow-unnamed tempdir
stdout 'hi!'
! stderr .

! exec runme run --filename README.md --allow-unknown=false hello-world-2
! stdout .
stderr 'unable to find any script named "hello-world-2"'

env HOME=/tmp
exec sh -c 'runme run --allow-unnamed package-main'
stdout 'Hello from Go, runme!'
! stderr .

env PATH=/opt/homebrew/bin:$PATH
exec runme run hello-js
stdout 'Hello, runme, from javascript!'
! stderr .

env PATH=/opt/homebrew/bin:$PATH
exec runme run hello-js-cat
stdout 'console\.log\(\"Hello, runme, from javascript!\"\)'
! stderr .

env PATH=/opt/homebrew/bin:$PATH
exec runme run hello-python
stdout 'Hello from Python'
! stderr .

-- README.md --
---
runme:
  id: 01HFVTDYA775K2HREH9ZGQJ75B
  version: 2.0
---

# Examples

## Shell

This is a basic snippet with shell command:

```sh
$ echo "Hello, runme!"
```

You can omit the language, and `runme` will assume you are in shell:

```
$ echo "Hello, runme!"
```

Names will automatically be inferred from a script's contents:

```sh
# This is a pesky comment
echo Inferred
```

With `{"name":"hello"}` you can annotate it and give it a nice name:

```sh {"name":"echo"}
$ echo "Hello, runme!"
```

It can contain multiple lines too:

```sh {"interactive":"false"}
$ echo "1"
$ echo "2"
$ echo "3"
```

Also, the dollar sign is not needed:

```sh
echo "Hello, runme! Again!"
```

It can even run scripting languages:

```js {"name":"hello-js"}
console.log("Hello, runme, from javascript!")
```

And it can even run a cell with a custom interpreter:

```js {"interpreter":"cat","name":"hello-js-cat"}
console.log("Hello, runme, from javascript!")
```

It works with `cd`, `pushd`, and similar because all lines are executed as a single script:

```sh
temp_dir=$(mktemp -d -t "runme-XXXXXXX")
pushd $temp_dir
echo "hi!" > hi.txt
pwd
cat hi.txt
popd
pwd
```

## Go

It can also execute a snippet of Go code:

```go
package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello from Go, runme!")
}
```

## Python

```python {"interpreter":"python3","name":"hello-python"}
def say_hi():
  print("Hello from Python")

say_hi()
```

-- golden-list.txt --
NAME	FILE	FIRST COMMAND	DESCRIPTION	NAMED
echo	README.md	echo "Hello, runme!"	With {"name":"hello"} you can annotate it and give it a nice name.	Yes
hello-js	README.md	console.log("Hello, runme, from javascript!")	It can even run scripting languages.	Yes
hello-js-cat	README.md	console.log("Hello, runme, from javascript!")	And it can even run a cell with a custom interpreter.	Yes
hello-python	README.md	def say_hi():		Yes
-- golden-list-allow-unnamed.txt --
NAME	FILE	FIRST COMMAND	DESCRIPTION	NAMED
echo-hello	README.md	echo "Hello, runme!"	This is a basic snippet with shell command.	No
echo-hello-2	README.md	echo "Hello, runme!"	You can omit the language, and runme will assume you are in shell.	No
echo-inferred	README.md	echo Inferred	Names will automatically be inferred from a script's contents.	No
echo	README.md	echo "Hello, runme!"	With {"name":"hello"} you can annotate it and give it a nice name.	Yes
echo-1	README.md	echo "1"	It can contain multiple lines too.	No
echo-hello-3	README.md	echo "Hello, runme! Again!"	Also, the dollar sign is not needed.	No
hello-js	README.md	console.log("Hello, runme, from javascript!")	It can even run scripting languages.	Yes
hello-js-cat	README.md	console.log("Hello, runme, from javascript!")	And it can even run a cell with a custom interpreter.	Yes
tempdir	README.md	temp_dir=$(mktemp -d -t "runme-XXXXXXX")	It works with cd, pushd, and similar because all lines are executed as a single script.	No
package-main	README.md	package main	It can also execute a snippet of Go code.	No
hello-python	README.md	def say_hi():		Yes
-- golden-list-json.txt --
[
  {
    "name": "echo",
    "file": "README.md",
    "first_command": "echo \"Hello, runme!\"",
    "description": "With {\"name\":\"hello\"} you can annotate it and give it a nice name.",
    "named": true
  },
  {
    "name": "hello-js",
    "file": "README.md",
    "first_command": "console.log(\"Hello, runme, from javascript!\")",
    "description": "It can even run scripting languages.",
    "named": true
  },
  {
    "name": "hello-js-cat",
    "file": "README.md",
    "first_command": "console.log(\"Hello, runme, from javascript!\")",
    "description": "And it can even run a cell with a custom interpreter.",
    "named": true
  },
  {
    "name": "hello-python",
    "file": "README.md",
    "first_command": "def say_hi():",
    "description": "",
    "named": true
  }
]
