mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-12-26 03:07:30 +00:00
Support globs in _ZO_EXCLUDE_DIRS
This commit is contained in:
parent
f4525db02f
commit
5cfcd79c39
@ -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
|
||||
|
||||
|
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"] }
|
||||
|
@ -27,10 +27,18 @@ pub fn zo_data_dir() -> Result<PathBuf> {
|
||||
Ok(data_dir)
|
||||
}
|
||||
|
||||
pub fn zo_exclude_dirs() -> Vec<PathBuf> {
|
||||
pub fn zo_exclude_dirs() -> Result<Vec<glob::Pattern>> {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,10 @@ fn add<P: AsRef<Path>>(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(());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user