GLOB: A simple filepath globber

Last modification on

Motivation

In the interest of refactoring shell features into separate self-contained binaries, this tool (glob) deals with the globbing of files according to a wildcard path spec.

It also avoids an annoying quirk of shell pattern matching: If the specified pattern does not match any files, sh-compliant shells will emit the pattern instead of an empty string. This is generally unexpected behavior and makes iterating over files using wildcards error-prone.

Features

The program fits inside a single, small C file (~150 LOC).

Files are globbed using * wildcards, which match everything except /.

A backslash \ may be prepended to treat the wildcard or directory separator as a literal.

The source code is available at: https://git.sinitax.com/sinitax/glob