go-match
is a simple command-line utility that filters a list of paths based on include and exclude globstar patterns.
The program takes a list of paths as input and outputs a JSON array of paths that match the include patterns and don't match the exclude patterns.
go install github.com/idelchi/go-match/@latest
curl -sSL https://raw.githubusercontent.com/idelchi/go-match/refs/heads/main/install.sh | sh -s -- -d ~/.local/bin
go-match [flags] [paths...]
Flag | Environment Variable | Description | Default |
---|---|---|---|
--include |
GO_MATCH_INCLUDE |
Include patterns (can be used multiple times) | - |
--exclude |
GO_MATCH_EXCLUDE |
Exclude patterns (can be used multiple times) | - |
-h, --help |
- | Help for go-match | - |
-v, --version |
- | Version for go-match | - |
# Filter Go files excluding a specific directory
go-match --include "**/*.go" --exclude "path/to/another/*" \
path/to/dir1 \
path/to/dir2 \
path/to/file.go \
path/to/another/file.go
# Output:
["path/to/file.go"]
- Use globstar patterns (
**
) to match multiple directory levels - Use single asterisk (
*
) to match within a single directory level - Patterns are case-sensitive
- Multiple include/exclude patterns can be specified
For detailed help:
go-match --help