A cross-platform script to scan .md files for runnable commands and execute them. Available for both Bash (Linux/macOS) and PowerShell (Windows/Linux/macOS). Supports extracting commands, generating test scripts, and direct execution of commands with optional debugging.
- ✅ Extract and list commands prefixed with
$from.mdfiles - ✅ Generate test scripts from extracted commands (
doctest.shordoctest.ps1) - ✅ Execute specific commands by their ID
- ✅ Debug logging for troubleshooting, easily toggled on/off
- ✅ Security features: dry-run mode, interactive confirmation, dangerous command detection
- ✅ Cross-platform: Works on Linux, macOS, and Windows
- ✅ Command validation to prevent accidental destructive operations
For Linux/macOS (Bash):
- Bash: Most Linux and macOS systems include Bash. Verify with:
bash --version
For Windows/Cross-platform (PowerShell):
- PowerShell 7+: Install from PowerShell GitHub
pwsh --version
-
Clone the repository:
git clone https://github.com/munafsheikh/runnable.git cd runnable -
For Bash users (Linux/macOS), make the script executable:
chmod +x runnable.sh
-
For PowerShell users (Windows/Linux/macOS), set execution policy if needed:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
-
(Optional) Add the folder to your PATH for global usage:
Bash (Linux/macOS):
export PATH=$PATH:$(pwd)
PowerShell (Windows):
$env:PATH += ";$(Get-Location)"
Bash (Linux/macOS):
./runnable.sh <file|folder> [id] [-r]PowerShell (Windows/Linux/macOS):
.\runnable.ps1 <file|folder> [id] [-Run]Bash:
./runnable.sh ./example.md
./runnable.sh ./testsPowerShell:
.\runnable.ps1 .\example.md
.\runnable.ps1 .\testsBash:
./runnable.sh ./example.md 00PowerShell:
.\runnable.ps1 .\example.md 00Bash:
./runnable.sh ./example.md 00 -rPowerShell:
.\runnable.ps1 .\example.md 00 -RunBash:
./runnable.sh ./example.md 2PowerShell:
.\runnable.ps1 .\example.md 2Both scripts support the following environment variables:
| Variable | Description | Default |
|---|---|---|
DEBUG |
Enable debug logging | false |
DRY_RUN |
Preview commands without executing | false |
INTERACTIVE |
Ask for confirmation before each command | false |
Bash:
DEBUG=true ./runnable.sh ./example.mdPowerShell:
$env:DEBUG = "true"; .\runnable.ps1 .\example.mdBash:
DRY_RUN=true ./runnable.sh ./example.md 2PowerShell:
$env:DRY_RUN = "true"; .\runnable.ps1 .\example.md 2Bash:
INTERACTIVE=true ./runnable.sh ./example.md 2PowerShell:
$env:INTERACTIVE = "true"; .\runnable.ps1 .\example.md 2🔴 Only run Runnable on trusted markdown files from trusted sources!
This tool executes commands directly from markdown files. Running it on untrusted files could:
- Delete files or directories
- Modify system settings
- Execute malicious code
- Compromise system security
Runnable includes several safety features:
-
Dangerous Command Detection: Automatically detects potentially dangerous patterns:
rm -rf/Remove-Item -Recurse -Forcemkfs/Format-Volumedd if=commands- Pipe to shell (
curl | bash, etc.) - Fork bombs and other destructive operations
-
Dry Run Mode: Preview commands before execution
DRY_RUN=true ./runnable.sh ./example.md 2
-
Interactive Mode: Confirm each command before running
INTERACTIVE=true ./runnable.sh ./example.md 2
-
Security Warnings: Displays warnings before executing commands
✅ DO:
- Review markdown files before running Runnable on them
- Use
DRY_RUN=truefirst to preview commands - Enable
INTERACTIVE=truefor untrusted sources - Keep Runnable updated for latest security patches
❌ DON'T:
- Run Runnable on markdown files from unknown sources
- Execute commands without reviewing them first
- Disable security warnings or confirmations
- Run with elevated privileges (sudo/admin) unless necessary
If you discover a security vulnerability, please report it responsibly:
- Open a private security advisory on GitHub
- Email the maintainers directly
- Do not publicly disclose until a fix is available
Create a file example.md with the following content:
# Example File
## Commands
1. Show current directory
```shell
$ pwd-
List files
$ ls -la
-
Print a message
$ echo "Hello, Runnable!"
### Run Tests
1. List commands:
```bash
./runnable.sh ./example.md
Expected Output:
pwd
ls -la
echo "Hello, Runnable!"
-
Generate
doctest.sh:./runnable.sh ./example.md 00
Expected Output:
Generating... [doctest.sh] -
Execute the test script:
./runnable.sh ./example.md 00 -r
Expected Output:
========================= pwd ------------------------ /path/to/current/directory ========================= ls -la ------------------------ <list of files> ========================= echo "Hello, Runnable!" ------------------------ Hello, Runnable! -
Run a specific command by ID:
./runnable.sh ./example.md 2
Expected Output:
<list of files>
Enable debug logs by setting DEBUG=true:
DEBUG=true ./runnable.sh ./example.mdThis will provide detailed logs at every step of execution.
MIT License