diff --git a/CHANGELOG.md b/CHANGELOG.md index 3262602..b9a7944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - `zoxide init` now defines `__zoxide_z*` functions that can be aliased as needed. +- `$_ZO_EXCLUDE_DIRS` now supports globs. ### Changed diff --git a/Cargo.lock b/Cargo.lock index 207d36d..26116b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,11 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "heck" version = "0.3.1" @@ -419,6 +424,7 @@ dependencies = [ "dirs 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "dunce 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.114 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -445,6 +451,7 @@ dependencies = [ "checksum dunce 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b2641c4a7c0c4101df53ea572bffdc561c146f6c2eb09e4df02bc4811e3feeb4" "checksum float-ord 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" diff --git a/Cargo.toml b/Cargo.toml index 126808d..1d5d68a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ clap = "2.33.0" dirs = "3.0.0" dunce = "1.0.0" float-ord = "0.2.0" +glob = "0.3.0" serde = { version = "1.0.106", features = ["derive"] } structopt = "0.3.12" uuid = { version = "0.8.1", features = ["v4"] } diff --git a/src/config.rs b/src/config.rs index 902e96a..8c14e19 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,10 +27,18 @@ pub fn zo_data_dir() -> Result { Ok(data_dir) } -pub fn zo_exclude_dirs() -> Vec { +pub fn zo_exclude_dirs() -> Result> { match env::var_os("_ZO_EXCLUDE_DIRS") { - Some(dirs_osstr) => env::split_paths(&dirs_osstr).collect(), - None => Vec::new(), + Some(dirs_osstr) => env::split_paths(&dirs_osstr) + .map(|path| { + let pattern = path + .to_str() + .context("invalid utf-8 sequence in _ZO_EXCLUDE_DIRS")?; + glob::Pattern::new(&pattern) + .with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern)) + }) + .collect(), + None => Ok(Vec::new()), } } diff --git a/src/subcommand/add.rs b/src/subcommand/add.rs index 3c3010d..5ed3864 100644 --- a/src/subcommand/add.rs +++ b/src/subcommand/add.rs @@ -37,7 +37,10 @@ fn add>(path: P) -> Result<()> { util::resolve_path(&path)? }; - if config::zo_exclude_dirs().contains(&path) { + if config::zo_exclude_dirs()? + .iter() + .any(|pattern| pattern.matches_path(&path)) + { return Ok(()); }