Skip to content

Get Started

llms.txt

Bunmagic is a script management tool that makes it easy to create and run shell scripts on Bun.

In bunmagic scripts, utilities like $, arg(), flag(), args, flags, cd, files, prompts, and styling helpers are globally available.

  1. Install Bun

    Terminal window
    curl -fsSL https://bun.sh/install | bash
  2. Install Bunmagic

    Terminal window
    bunx bunmagic install
  3. Create your first script

    Terminal window
    bunmagic create hello-world
  4. Write script logic

    console.log(ansis.green('Hello from bunmagic'))
    await $`echo "Running shell commands is easy"`
    const input = arg(0).string().optional()
    if (input) {
    console.log(`You passed: ${input}`)
    }
    if (flags.verbose) {
    console.log('Verbose mode enabled')
    }
    if (await files.isDir('./src')) {
    const sourceFiles = await files.glob('src/*.ts')
    console.log(`Found ${sourceFiles.length} TypeScript files`)
    }
    const runFile = files.resolve('./tmp/run.json')
    const previous = await files.pathExists(runFile)
    ? (JSON.parse(await files.readFile(runFile)) as { runs?: number })
    : {}
    await files.outputFile(runFile, `${JSON.stringify({
    runs: (previous.runs ?? 0) + 1,
    ranAt: new Date().toISOString(),
    args,
    }, null, 2)}\n`)
    const name = await ask("What's your name?")
    const confirmed = ack(`Nice to meet you, ${name}! Continue?`, 'y')
    if (confirmed) {
    const choice = await select('Pick your favorite:', ['Bun', 'Node', 'Deno'])
    console.log(`Great choice: ${choice}`)
    }
  5. Run your script

    Terminal window
    hello-world