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

FlagDescriptionDefault
-n, --nameHeader name for the cheat"Snippet"
-d, --descriptionOptional description below the header(empty)
-f, --fileTarget save location(auto)
-p, --printPrint to stdout instead of savingfalse

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.md inside that directory.
  • If it is a file, it appends directly to that file.