#glob #nu-shell #uninterruptible #nu-glob

nu-glob

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

61 releases (breaking)

new 0.104.0 Apr 29, 2025
0.103.0 Mar 19, 2025
0.102.0 Feb 5, 2025
0.101.0 Dec 22, 2024
0.60.0 Mar 22, 2022

#385 in Filesystem

Download history 2847/week @ 2025-01-08 1944/week @ 2025-01-15 2317/week @ 2025-01-22 2542/week @ 2025-01-29 3698/week @ 2025-02-05 2963/week @ 2025-02-12 3429/week @ 2025-02-19 3021/week @ 2025-02-26 4924/week @ 2025-03-05 3494/week @ 2025-03-12 4737/week @ 2025-03-19 3801/week @ 2025-03-26 5306/week @ 2025-04-02 4617/week @ 2025-04-09 3850/week @ 2025-04-16 4118/week @ 2025-04-23

18,354 downloads per month
Used in 104 crates (7 directly)

MIT/Apache

60KB
1K 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, Uninterruptible};

for entry in glob("/media/**/*.jpg", Uninterruptible).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, MatchOptions, Uninterruptible};

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, Uninterruptible).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),
    }
}

No runtime deps