Gitignore-compatible pattern matching for Crystal
require "ignore"
# Parse gitignore patterns
matcher = Ignore.parse("*.log\nbuild/\n!important.log")
matcher.ignores?("debug.log") # => true
matcher.ignores?("build/") # => true
matcher.ignores?("important.log") # => false
# Filtered directory operations
dir = Ignore::Dir.new("/project", root: ".gitignore")
dir.glob("**/*.cr") # ignores filtered out
# Manage ignore files
file = Ignore::File.new(".gitignore")
file.add("*.tmp").save
Wildcards, character classes, negation, directory-only, anchored patterns, and ** globbing.
Filtered glob, children, and entries. Automatically excludes ignored directories and their contents.
Read, modify, and save ignore files while preserving comments and blank lines.
Load nested ignore files with proper scoping. Deeper patterns take precedence.
Matcher, Dir, and File all include Enumerable for easy iteration and filtering.
Get only ignored files with ignored_glob, ignored_children, etc.