Compose
The compose subcommand converts a raw shell command into a reusable CheatMD snippet. It automatically extracts variables and writes a complete metadata block.
Usage
Pass a command as an argument:
cheatmd compose "curl -X POST <url> -H 'Auth: $token'" Or pipe a command through stdin:
echo "ssh -p $port $user@$host" | cheatmd compose -n "SSH Connect" Variable Extraction
compose detects both $ ($url) and angle bracket (<url>) variable syntax. It deduplicates the names and generates a <!-- cheat --> block:
# Snippet
<!-- cheat
var url
var token
-->
` + "```" + `sh
curl -X POST <url> -H 'Auth: $token'
` + "```" + ` Flags
| Flag | Description | Default |
|---|---|---|
-n, --name | Header name for the cheat | "Snippet" |
-d, --description | Optional description below the header | (empty) |
-f, --file | Target save location | (auto) |
-p, --print | Print to stdout instead of saving | false |
Save Location
If --file is not provided, compose uses the first path in your cheatmd.yaml path setting:
- If it is a directory, it appends to
snippets.mdinside that directory. - If it is a file, it appends directly to that file.