JustBash.Interpreter.Expansion.Glob (JustBash v0.4.0)

View Source

Glob expansion and pattern matching utilities.

Handles:

  • Filename expansion: *, ?, [...]
  • IFS word splitting
  • Converting glob patterns to regex

Summary

Functions

Expand a glob pattern against the filesystem. Returns a list of matching filenames, or the original pattern if no matches.

Convert a glob pattern to a regex pattern string.

Check if a string contains glob metacharacters.

Split a string on IFS characters.

Functions

expand(bash, pattern)

@spec expand(JustBash.t(), String.t()) :: [String.t()]

Expand a glob pattern against the filesystem. Returns a list of matching filenames, or the original pattern if no matches.

Handles wildcards in any path segment, not just the filename. For example: /tmp//file.txt or /a//b/*.log

Trailing slashes are preserved: /tmp/*/ expands to /tmp/foo/, /tmp/bar/

glob_pattern_to_regex(pattern)

@spec glob_pattern_to_regex(String.t()) :: String.t()

Convert a glob pattern to a regex pattern string.

has_glob_chars?(str)

@spec has_glob_chars?(String.t()) :: boolean()

Check if a string contains glob metacharacters.

split_on_ifs(str, ifs)

@spec split_on_ifs(String.t(), String.t()) :: [String.t()]

Split a string on IFS characters.