Skip to content

feat(builtins): add glob command (non-standard, programmatic glob matching) #574

@chaliy

Description

@chaliy

Summary

A non-standard builtin exposing glob matching as a command. While bash does glob expansion natively, there is no way to test if a string matches a glob pattern programmatically (without [[ ]] hacks).

Proposed Syntax

glob [OPTIONS] pattern [string...]
# or
input | glob [OPTIONS] pattern

Proposed Flags

Flag Description
(default) Print matching strings
-v Invert — print non-matching
-q Quiet — exit 0 if any match, 1 if none
-c Count matches
--files Match against VFS files (like find but with glob)

Use Cases

# Filter a list by pattern
echo -e "foo.rs\nbar.py\nbaz.rs" | glob "*.rs"
# foo.rs
# baz.rs

# Test if string matches pattern
if glob -q "v[0-9]*" "$tag"; then
    echo "Valid version tag"
fi

# Find files by glob
glob --files "src/**/*.rs"

# Exclude pattern
ls | glob -v "*.tmp"

llm_hint()

Some("glob: Glob matching. `echo files | glob '*.rs'` filters by pattern. `glob -q pat str` tests match. `glob --files 'src/**/*.rs'` finds files.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions