#shell #glob #nu-shell #signal

nu-glob

Fork of glob. Support for matching file paths against Unix shell style patterns.

60 releases (breaking)

0.103.0 Mar 19, 2025
0.101.0 Dec 22, 2024
0.100.0 Nov 13, 2024
0.96.1 Jul 29, 2024
0.60.0 Mar 22, 2022

#277 in Filesystem

Download history 3270/week @ 2024-12-17 1786/week @ 2024-12-24 2136/week @ 2024-12-31 2756/week @ 2025-01-07 2316/week @ 2025-01-14 2321/week @ 2025-01-21 2451/week @ 2025-01-28 3689/week @ 2025-02-04 2849/week @ 2025-02-11 3529/week @ 2025-02-18 2907/week @ 2025-02-25 4061/week @ 2025-03-04 4302/week @ 2025-03-11 4785/week @ 2025-03-18 3862/week @ 2025-03-25 4320/week @ 2025-04-01

19,091 downloads per month
Used in 100 crates (6 directly)

MIT/Apache and maybe CC-PDDC

1MB
27K SLoC

Support for matching file paths against Unix shell style patterns.

The glob and glob_with functions allow querying the filesystem for all files that match a particular pattern (similar to the libc glob function). The methods on the Pattern type provide functionality for checking if individual paths match a particular pattern (similar to the libc fnmatch function).

For consistency across platforms, and for Windows support, this module is implemented entirely in Rust rather than deferring to the libc glob/fnmatch functions.

Examples

To print all jpg files in /media/ and all of its subdirectories.

use nu_glob::glob;

for entry in glob("/media/**/*.jpg", None).expect("Failed to read glob pattern") {
    match entry {
        Ok(path) => println!("{:?}", path.display()),
        Err(e) => println!("{:?}", e),
    }
}

To print all files containing the letter "a", case insensitive, in a local directory relative to the current working directory. This ignores errors instead of printing them.

use nu_glob::glob_with;
use nu_glob::MatchOptions;
use nu_protocol::Signals;

let options = MatchOptions {
    case_sensitive: false,
    require_literal_separator: false,
    require_literal_leading_dot: false,
    recursive_match_hidden_dir: true,
};
for entry in glob_with("local/*a*", options, Signals::empty()).unwrap() {
    if let Ok(path) = entry {
        println!("{:?}", path.display())
    }
}

nu-glob

Support for matching file paths against Unix shell style patterns.

Usage

To use nu-glob, add this to your Cargo.toml:

[dependencies]
nu-glob = "0.60.0"

Examples

Print all jpg files in /media/ and all of its subdirectories.

use nu_nu_glob::glob;

for entry in glob("/media/**/*.jpg").expect("Failed to read glob pattern") {
    match entry {
        Ok(path) => println!("{:?}", path.display()),
        Err(e) => println!("{:?}", e),
    }
}

Dependencies

~15–49MB
~705K SLoC