ignoreme

Ignore file parser and matcher

ignoreme

A .gitignore compatible pattern parser for Crystal.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      ignoreme:
        github: trans/ignoreme
    
  2. Run shards install

Usage

require "ignoreme"

# Parse gitignore content
matcher = Ignoreme.parse(<<-GITIGNORE
  build/
  *.o
  *.log
  !important.log
GITIGNORE
)

matcher.ignores?("build/")       # => true (directory)
matcher.ignores?("main.o")       # => true
matcher.ignores?("debug.log")    # => true
matcher.ignores?("important.log") # => false (negated)

# Quick one-liner
Ignoreme.ignores?("foo.log", "*.log")  # => true

Directory Matching

Use a trailing slash to check directories:

matcher = Ignoreme.parse("build/")
matcher.ignores?("build/")  # => true (directory)
matcher.ignores?("build")   # => false (file)

Building Patterns Incrementally

matcher = Ignoreme::Matcher.new
matcher.add("*.o")
matcher.add("*.log")
matcher.add("!important.log")
matcher.ignores?("test.o")  # => true

Loading from a Directory Tree

Load all .gitignore files from a project, with patterns scoped to their directories:

matcher = Ignoreme.root("/path/to/project")
matcher.ignores?("src/debug.log")

This loads .gitignore files from the root and all subdirectories. Patterns from deeper directories take precedence, so a !debug.log in src/.gitignore will override *.log in the root .gitignore.

You can also load other ignore file formats:

# Load .dockerignore files
matcher = Ignoreme.root("/path/to/project", ".dockerignore")

# Load .npmignore files
matcher = Ignoreme.root("/path/to/project", ".npmignore")

Loading Individual Files

matcher = Ignoreme::Matcher.new
matcher.add_file(".gitignore")
matcher.add_file("src/.gitignore", base: "src/")

Supported Patterns

Pattern Description
*.txt Wildcard, matches any .txt file
? Single character wildcard
[abc] Character class
[a-z] Character range
[!abc] Negated character class
build/ Directory only (trailing slash)
/root Anchored to root (leading slash)
foo/bar Anchored (contains slash)
!pattern Negation (un-ignore)
**/foo Match in all directories
foo/** Match everything inside
a/**/b Zero or more directories between
\# \! Escaped special characters

License

MIT

Repository

ignoreme

Owner
Statistic
  • 2
  • 0
  • 0
  • 1
  • 0
  • about 3 hours ago
  • January 22, 2026
License

MIT License

Links
Synced at

Fri, 23 Jan 2026 00:32:28 GMT

Languages