Real-World Example: Dotfiles Manager¶
A complete example showing how to manage and deploy dotfiles using Mooncake.
Features Demonstrated¶
- Multi-file organization
- Template rendering for dynamic configs
- File tree iteration
- Conditional deployment by OS
- Variable management
- Backup functionality
- Tag-based workflows
Quick Start¶
cd examples/real-world/dotfiles-manager
# Deploy all dotfiles
mooncake run --config setup.yml
# Deploy only shell configs
mooncake run --config setup.yml --tags shell
# Preview what would be deployed
mooncake run --config setup.yml --dry-run
Directory Structure¶
dotfiles-manager/
├── setup.yml # Main entry point
├── vars.yml # User configuration
├── dotfiles/ # Your actual dotfiles
│ ├── shell/
│ │ ├── .bashrc
│ │ └── .zshrc
│ ├── vim/
│ │ └── .vimrc
│ └── git/
│ └── .gitconfig
└── templates/ # Dynamic config templates
├── .tmux.conf.j2
└── .config/
└── nvim/
└── init.lua.j2
What It Does¶
- Backs up existing dotfiles
- Creates necessary directories
- Deploys static dotfiles
- Renders dynamic configs from templates
- Sets appropriate permissions
- OS-specific configuration
Configuration¶
Edit vars.yml to customize:
user_email: [email protected]
user_name: Your Name
editor: nvim
shell: zsh
color_scheme: gruvbox
Usage¶
Full Deployment¶
Selective Deployment¶
# Only shell configs
mooncake run --config setup.yml --tags shell
# Only vim/neovim
mooncake run --config setup.yml --tags vim
# Only git config
mooncake run --config setup.yml --tags git
Backup Only¶
Extending¶
Adding New Dotfiles¶
- Add file to
dotfiles/directory - Add deployment step in
setup.yml:
Adding Templates¶
- Create template in
templates/ - Add rendering step:
Real-World Tips¶
- Version control - Keep this in git
- Test first - Use
--dry-runbefore applying - Incremental - Add configs gradually
- Backup - The example includes backup steps
- Document - Add comments for custom settings
See Also¶
This example combines concepts from: - 06-loops - File iteration - 05-templates - Config rendering - 08-tags - Selective deployment - 10-multi-file-configs - Organization