Getting Started with mir
// Learn how to install mir and start using code snippets
What is mir?
mir is a command-line tool for sharing and installing reusable code snippets. A snippet can be anything from a single function to a complete directory structure with multiple files. Use mir to save time on repetitive code and maintain consistency across your projects.
Installation
Option 1: Using npx (Recommended)
Run mir directly without installing:
npx @tbsten/mir --helpOption 2: Global Installation
Install mir globally on your system:
npm install -g @tbsten/mir
mir --helpQuick Start
Step 1: Initialize a Project
Create a new mir project in your current directory:
npx @tbsten/mir initThis creates a .mir/ directory with sample snippets and configuration.
Step 2: View Available Snippets
List snippets in your local registry:
npx @tbsten/mir listStep 3: Install a Snippet
Install a snippet from the official registry:
npx @tbsten/mir install react-hookmir will prompt you for any required variables, then generate the files.
Step 4: Create Your Own Snippet
Create a new snippet template:
npx @tbsten/mir create my-snippetEdit the generated .mir/snippets/my-snippet.yaml and template files, then publish:
npx @tbsten/mir publish my-snippetCore Concepts
Snippets
A snippet is a reusable collection of template files with configurable variables. When you install a snippet, mir generates files with your custom values substituted in.
Registries
Registries store snippets. mir supports both local registries (~/.mir/registry/) and remote registries (e.g., the official registry at mir.tbsten.me).
Variables
Variables are placeholders in your snippet templates. When installing, mir prompts you for values and substitutes them using Handlebars syntax (e.g., {{variableName}}).
Common Commands
| Command | Description |
|---|---|
| npx @tbsten/mir init | Initialize a new mir project |
| npx @tbsten/mir list | List snippets in registry |
| npx @tbsten/mir info <name> | Show snippet details |
| npx @tbsten/mir search <query> | Search snippets |
| npx @tbsten/mir install <name> | Install a snippet |
| npx @tbsten/mir create <name> | Create a new snippet |
| npx @tbsten/mir publish <name> | Publish a snippet |
Next Steps
- → Check out the Tutorial for a detailed walkthrough
- → Learn about Template Syntax for advanced features
- → Explore the Variables guide
- → Browse available snippets to use
Need Help?
Use npx @tbsten/mir --help to view all available commands and options.
For more information, visit the GitHub repository.