https://github.com/mulle-sde/mulle-match
💕 Match filenames against a set of .gitignore like patternfiles
https://github.com/mulle-sde/mulle-match
bash command-line-tool find gitignore-patterns matching-engine mulle-sde sources
Last synced: 4 months ago
JSON representation
💕 Match filenames against a set of .gitignore like patternfiles
- Host: GitHub
- URL: https://github.com/mulle-sde/mulle-match
- Owner: mulle-sde
- License: bsd-3-clause
- Created: 2018-03-05T13:45:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-04-27T21:36:39.000Z (about 1 year ago)
- Last Synced: 2025-04-27T22:26:35.000Z (about 1 year ago)
- Topics: bash, command-line-tool, find, gitignore-patterns, matching-engine, mulle-sde, sources
- Language: Shell
- Homepage:
- Size: 922 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 💕 Match filenames against a set of .gitignore like patternfiles
... for Android, BSDs, Linux, macOS, SunOS, Windows (MinGW, WSL)
mulle-match is the backbone of the mulle-sde reflection mechanism. It matches
filenames against a set of .gitignore like patternfiles to categorize and type
files according to their filenames and location. Its like a marriage of
**find** and **.gitignore**.
Here's an example of mulle-match in action to categorize files:
``` bash
$ mulle-match list -f "%t,%c : %f\n"
header,private-generated-headers : src/reflect/_mulle-testallocator-include-private.h
header,public-generated-headers : src/reflect/_mulle-testallocator-include.h
header,public-generic-headers : src/generic/include.h
header,public-headers : src/mulle-testallocator-struct.h
header,public-headers : src/pointerarray.h
header,public-headers : src/pointerset.h
source,sources : src/mulle-testallocator.c
sourcetree,all : .mulle/etc/sourcetree/config
```
| Release Version | Release Notes
|-------------------------------------------------------|--------------
|  | [RELEASENOTES](RELEASENOTES.md) |
| Executable | Description
|------------------------|----------------------------------------------------------
| `mulle-match` | Match filename according to .gitignore like patternfiles
| `mulle-match-to-cmake` | Use **mulle-match** to create cmake files
| `mulle-match-to-c` | Create include files for public headers
## Commands
### init
Initialize the current directory with some patternfiles to match C/ObjC files
for demo purposes or as a starting point:
```
mulle-match init
```
Would produce in a folder `my-project` a structure like this:
```
my-project
└── .mulle
└── etc
└── match
└── match.d
├── 50-source--private-headers
├── 60-source--public-headers
└── 70-source--sources
```
### patternfile
A *patternfile* is made up of one or more *patterns*. It is quite like a
`.gitignore` file, with the same semantics for negation.
Example:
```
# match .c .h and .cpp files
*.c
*.h
*.cpp
# ignore backup files though
!*~.*
```
A *patternfile* resides in either the `ignore.d` folder or the
`match.d` folder. Its filename is composed of three
segments: `priority-type--category`.
The first digits-only segment is there to prioritize patternfiles.
Lower numbers are matched before higher numbers (`ls` sorting).
The second segment gives the *type* of the file. And the last segment
is the *category* of the file. A *type* is required, a *category* is optional.

If a *patternfile* of the `ignore.d` folder matches, the matching has failed.
On the other hand, if a *patternfile* of the `match.d` folder matches, the
matching has succeeded. *patternfiles* are matched in sort order of their
filename.
> The [Wiki](https://github.com/mulle-sde/mulle-match/wiki) explains this in more detail.
Add a *patternfile* to select PNG files. We give it a type "hello":
```
echo "*.svg" > pattern.txt
mulle-match patternfile add hello pattern.txt
```
This will result in this change in the `match.d` folder.
```
├── .mulle
│  └── etc
│  └── match
│  └── match.d
│  ├── 50-hello--all
│  ├── 50-source--private-headers
│  ├── 60-source--public-headers
│  └── 70-source--sources
```
You could optionally specify a *category* for the patternfile:
```
mulle-match patternfile add --category special hello pattern.txt
```
It may be useful, especially in conjunction with `mulle-match find`,
that large and changing folders like `.git` and `build` are ignored.
Install the following *patternfile* into the `ignore.d` folder with `-i`:
```
echo ".git/" > pattern.txt
echo "build/" >> pattern.txt
mulle-match patternfile install -i folders pattern.txt
```
> But see [Environment](#Environment) for an even better and more efficient way of ignoring files
> and subdirectories.
Remove a *patternfile*:
```
mulle-match patternfile remove hello
```
List all *patternfiles*:
```
mulle-match patternfile list
```
and see their contents with
```
mulle-match patternfile cat
```
### filename
To test your installed *patternfile* you can use `mulle-match filename`. It
will output the patternfile name if one matches.
```
mulle-match filename pix/foo.svg
```
To test a specific patternfile use the `--pattern-file` option. This will work
for both ignored.d and match.d patternfiles:
```
mulle-match filename --pattern-file '20-ignored--none' pix/foo.svg
```
You can test individual *patterns* using the `--pattern` option:
```
mulle-match filename --pattern '*.svg' pix/foo.svg
```
### list
This command lists the filenames that match *patternfiles*.
You can decide which *patternfile* should be used by supplying an optional
filter.
This example lists all the files, that pass through *patternfiles* of type
"hello":
```
mulle-match list --match-filter "hello"
```
The speed of the `list` command is highly dependent on a reduction of the
search space with the environment variables `MULLE_MATCH_FILENAMES`,
`MULLE_MATCH_IGNORE_PATH`, `MULLE_MATCH_PATH`.
#### .gitignore modes
With the `list` option `--gitignore` the `.gitignore` file will be used to
prune the search space.
## Environment
Variable | Description
--------------------------|---------------------------------------------
`MULLE_MATCH_FILENAMES` | Filename wildcards separated by ':'. Only files matching these wildcards will be considered for. e.g. *.c:*.m:*.cmake. These values are evaluated with `find`'s `-name`. The default value is `*`
`MULLE_MATCH_IGNORE_PATH` | Locations to ignore separated by ':'. These values are evaluated with `find`'s `-path` and then pruned. The default value is `addiction:build:dependency:stash:include:lib:libexec:.git`
`MULLE_MATCH_PATH` | Locations to search for separated by ':'. These values are passed to `find` as search starts. The default value is `.mulle/etc/sourcetree/config:src`
## Install
See [mulle-sde-developer](//github.com/mulle-sde/mulle-sde-developer) how to
install mulle-sde, which will also install mulle-match with required
dependencies.
The command to install only the latest mulle-match into
`/usr/local` (with **sudo**) is:
``` bash
curl -L 'https://github.com/mulle-sde/mulle-match/archive/latest.tar.gz' \
| tar xfz - && cd 'mulle-match-latest' && sudo ./bin/installer /usr/local
```
## Author
[Nat!](https://mulle-kybernetik.com/weblog) for Mulle kybernetiK