How to Configure Multiple QMD Collections with Different Glob Patterns
Use the qmd collection add command with the --mask flag to define multiple collections with independent glob patterns, stored in ~/.config/qmd/index.yml and managed by the src/collections.ts module.
The QMD CLI tool from tobi/qmd enables you to index and search across multiple file collections using different glob patterns. When you configure multiple QMD collections with different glob patterns, you can maintain separate indexes for Markdown notes, JSON configuration files, shell scripts, or any other file types within the same QMD installation.
Understanding the Collection Configuration File
QMD stores collection definitions in a YAML file located at ~/.config/qmd/index.yml. This Collection Config (CollectionConfig) contains entries with three essential fields:
- path: Absolute filesystem directory to index
- pattern: Glob pattern selecting which files to index (defaults to
**/*.md) - context (optional): Human-readable description
The configuration is managed by src/collections.ts, which provides key functions including addCollection(name, path, pattern), listCollections(), removeCollection(name), and renameCollection(old, new).
Adding Collections with Custom Glob Patterns
To configure multiple QMD collections with different glob patterns, use the CLI command defined in src/qmd.ts. The collectionAdd function (around line 3170) parses arguments and invokes addCollection (around line 645) to persist the configuration.
Create distinct collections for different file types:
# Markdown notes (default pattern)
qmd collection add ~/notes --name notes
# All JSON files in a project
qmd collection add ~/my-project --name project-json --mask "**/*.json"
# Only README files in a docs folder
qmd collection add ~/docs --name docs-readme --mask "README.*"
Each command creates an entry in ~/.config/qmd/index.yml:
collections:
notes:
path: /home/you/notes
pattern: "**/*.md"
project-json:
path: /home/you/my-project
pattern: "**/*.json"
docs-readme:
path: /home/you/docs
pattern: "README.*"
Managing Existing Collections
Verify your configured patterns using the listCollections() function:
qmd collection list
This reads the YAML configuration and displays each collection's glob pattern:
notes (qmd://notes/) Pattern: **/*.md
project-json (qmd://project-json/) Pattern: **/*.json
docs-readme (qmd://docs-readme/) Pattern: README.*
To modify a collection, remove and re-add it with a new pattern:
qmd collection remove project-json
qmd collection add ~/my-project --name project-json --mask "**/*.yaml"
How Glob Patterns Work During Indexing
When you run qmd update or add a collection, QMD calls indexFiles which uses fast-glob (lines 1416-1419 in src/qmd.ts) with the collection-specific pattern. Only matching files are read, hashed, and inserted into the SQLite database.
This means each collection maintains an independent view of the filesystem based on its glob pattern. The search and list commands consult these patterns to restrict results to files belonging to that specific collection.
Advanced Configuration Options
Manual YAML Editing
You can edit ~/.config/qmd/index.yml directly to add collections:
my-scripts:
path: /home/you/scripts
pattern: "**/*.sh"
After saving, run qmd update to index the new files. The loadConfig() function (around line 94) reads this file on every QMD execution.
Custom Configuration Directory
To maintain multiple independent QMD setups (e.g., work vs. personal), use the QMD_CONFIG_DIR environment variable. The getConfigDir() function (lines 64-70) checks this variable before defaulting to ~/.config/qmd.
export QMD_CONFIG_DIR=$HOME/.config/qmd-work
qmd collection add ~/work --name work --mask "**/*.md"
qmd update
This creates a separate index.yml in the custom directory, completely isolated from your default QMD configuration.
Summary
- QMD stores collection definitions in
~/.config/qmd/index.ymlwithpath,pattern, and optionalcontextfields - Use
qmd collection add <path> --name <name> --mask "<glob>"to configure multiple QMD collections with different glob patterns - The
src/collections.tsmodule handles persistence viaaddCollection(), whilesrc/qmd.tsimplements the CLI interface - Each collection's glob pattern is passed to fast-glob during indexing, ensuring only matching files enter the SQLite database
- Override the default config location using the
QMD_CONFIG_DIRenvironment variable for isolated environments
Frequently Asked Questions
How do I change the glob pattern for an existing collection?
Remove the collection using qmd collection remove <name> and re-add it with the new --mask value. The renameCollection() and addCollection() functions in src/collections.ts do not support in-place pattern modification, so a remove-and-re-add cycle is required.
Can I use negative glob patterns to exclude certain files?
Yes, standard glob negation patterns work because QMD passes the pattern directly to fast-glob. For example, use --mask "**/*.md" "!**/node_modules/**" to index all Markdown files while excluding node_modules directories. Ensure you quote the pattern to prevent shell expansion.
Where does QMD store the actual indexed content?
Indexed content resides in a SQLite database located in the same directory as your index.yml configuration (typically ~/.config/qmd/). The database stores file hashes and content, while the YAML file stores the collection metadata including glob patterns. Use the QMD_CONFIG_DIR environment variable to relocate both files.
What happens if two collections have overlapping file paths?
QMD treats each collection independently. If two glob patterns match the same file, that file will be indexed twice—once under each collection's namespace. The indexFiles function in src/qmd.ts does not deduplicate across collections, allowing you to maintain separate views of overlapping datasets.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →