ignore

Gitignore-compatible pattern matching for Crystal

Install

dependencies:
  ignore:
    github: trans/ignore

Quick Example

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

Features

Full Pattern Support

Wildcards, character classes, negation, directory-only, anchored patterns, and ** globbing.

Directory Filtering

Filtered glob, children, and entries. Automatically excludes ignored directories and their contents.

File Management

Read, modify, and save ignore files while preserving comments and blank lines.

Hierarchical Loading

Load nested ignore files with proper scoping. Deeper patterns take precedence.

Enumerable

Matcher, Dir, and File all include Enumerable for easy iteration and filtering.

Inverse Filtering

Get only ignored files with ignored_glob, ignored_children, etc.