diff --git a/Cargo.lock b/Cargo.lock index 859cc81..c268d01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,124 +74,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "async-attributes" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "async-channel" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "once_cell", - "slab", -] - -[[package]] -name = "async-global-executor" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5262ed948da60dd8956c6c5aca4d4163593dddb7b32d73267c93dab7b2e98940" -dependencies = [ - "async-channel", - "async-executor", - "async-io", - "async-lock", - "blocking", - "futures-lite", - "num_cpus", - "once_cell", -] - -[[package]] -name = "async-io" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5e18f61464ae81cde0a23e713ae8fd299580c54d697a35820cfd0625b8b0e07" -dependencies = [ - "concurrent-queue", - "futures-lite", - "libc", - "log", - "once_cell", - "parking", - "polling", - "slab", - "socket2", - "waker-fn", - "winapi", -] - -[[package]] -name = "async-lock" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-std" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" -dependencies = [ - "async-attributes", - "async-channel", - "async-global-executor", - "async-io", - "async-lock", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - -[[package]] -name = "async-task" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" - -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "atty" version = "0.2.14" @@ -224,20 +106,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "blocking" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] - [[package]] name = "bstr" version = "0.2.17" @@ -249,24 +117,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "bumpalo" -version = "3.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" - -[[package]] -name = "cache-padded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" - -[[package]] -name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" - [[package]] name = "cfg-if" version = "1.0.0" @@ -275,9 +125,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.6" +version = "3.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f1fe12880bae935d142c8702d500c63a4e8634b6c3c57ad72bf978fc7b6249a" +checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" dependencies = [ "atty", "bitflags", @@ -292,18 +142,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.2.2" +version = "3.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c09fbb00fb6e20e92f785598ecbf0c118f269737490c57af28b1ed07f392be16" +checksum = "ead064480dfc4880a10764488415a97fdd36a4cf1bb022d372f02e8faf8386e1" dependencies = [ "clap", ] [[package]] name = "clap_complete_fig" -version = "3.2.2" +version = "3.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4fddf94bed77a3b977c7c30a67ba3e28ad8bb772fff81ae3bc4c48e6b525726" +checksum = "d56555fb3c4fd44301b45a883e05c5bf7b20f07079087e91f9ae25f3b2732f02" dependencies = [ "clap", "clap_complete", @@ -311,9 +161,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.6" +version = "3.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed6db9e867166a43a53f7199b5e4d1f522a1e5bd626654be263c999ce59df39a" +checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" dependencies = [ "heck", "proc-macro-error", @@ -324,22 +174,13 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87eba3c8c7f42ef17f6c659fc7416d0f4758cd3e58861ee63c5fa4a4dde649e4" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ "os_str_bytes", ] -[[package]] -name = "concurrent-queue" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" -dependencies = [ - "cache-padded", -] - [[package]] name = "crossbeam-utils" version = "0.8.10" @@ -350,16 +191,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "ctor" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "difflib" version = "0.4.0" @@ -400,15 +231,9 @@ checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541" [[package]] name = "either" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "event-listener" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" [[package]] name = "fastrand" @@ -473,21 +298,6 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" -[[package]] -name = "futures-lite" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.21" @@ -565,18 +375,6 @@ dependencies = [ "regex", ] -[[package]] -name = "gloo-timers" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - [[package]] name = "hashbrown" version = "0.12.1" @@ -644,24 +442,6 @@ dependencies = [ "either", ] -[[package]] -name = "js-sys" -version = "0.3.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -681,7 +461,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", - "value-bag", ] [[package]] @@ -733,52 +512,18 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "once_cell" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" -[[package]] -name = "ordered-float" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96bcbab4bfea7a59c2c0fe47211a1ac4e3e96bea6eb446d704f310bc5c732ae2" -dependencies = [ - "num-traits", -] - [[package]] name = "os_str_bytes" version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" -[[package]] -name = "parking" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" - [[package]] name = "pin-project-lite" version = "0.2.9" @@ -791,19 +536,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "polling" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" -dependencies = [ - "cfg-if", - "libc", - "log", - "wepoll-ffi", - "winapi", -] - [[package]] name = "predicates" version = "2.1.1" @@ -927,11 +659,10 @@ dependencies = [ [[package]] name = "rstest" -version = "0.13.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b939295f93cb1d12bc1a83cf9ee963199b133fb8a79832dd51b68bb9f59a04dc" +checksum = "e9c9dc66cc29792b663ffb5269be669f1613664e69ad56441fdb895c2347b930" dependencies = [ - "async-std", "futures", "futures-timer", "rstest_macros", @@ -940,9 +671,9 @@ dependencies = [ [[package]] name = "rstest_macros" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f78aba848123782ba59340928ec7d876ebe745aa0365d6af8a630f19a5c16116" +checksum = "5015e68a0685a95ade3eee617ff7101ab6a3fc689203101ca16ebc16f2b89c66" dependencies = [ "cfg-if", "proc-macro2", @@ -982,9 +713,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.10" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41d061efea015927ac527063765e73601444cdc344ba855bc7bd44578b25e1c" +checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" [[package]] name = "serde" @@ -1018,16 +749,6 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" -[[package]] -name = "socket2" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "strsim" version = "0.10.0" @@ -1124,16 +845,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" -[[package]] -name = "value-bag" -version = "1.0.0-alpha.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" -dependencies = [ - "ctor", - "version_check", -] - [[package]] name = "version_check" version = "0.9.4" @@ -1149,12 +860,6 @@ dependencies = [ "libc", ] -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "walkdir" version = "2.3.2" @@ -1172,91 +877,6 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasm-bindgen" -version = "0.2.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" - -[[package]] -name = "web-sys" -version = "0.3.58" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "wepoll-ffi" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" -dependencies = [ - "cc", -] - [[package]] name = "which" version = "4.2.5" @@ -1325,7 +945,6 @@ dependencies = [ "fastrand", "glob", "nix", - "ordered-float", "rstest", "rstest_reuse", "serde", diff --git a/Cargo.toml b/Cargo.toml index d221668..8299f94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "zoxide" readme = "README.md" repository = "https://github.com/ajeetdsouza/zoxide" -rust-version = "1.59" +rust-version = "1.62" version = "0.8.2" [badges] @@ -27,7 +27,6 @@ dirs = "4.0.0" dunce = "1.0.1" fastrand = "1.7.0" glob = "0.3.0" -ordered-float = "3.0.0" serde = { version = "1.0.116", features = ["derive"] } [target.'cfg(unix)'.dependencies] @@ -46,7 +45,7 @@ clap_complete_fig = "3.1.0" [dev-dependencies] assert_cmd = "2.0.0" -rstest = "0.13.0" +rstest = "0.15.0" rstest_reuse = "0.3.0" tempfile = "3.1.0" diff --git a/README.md b/README.md index 3901f32..8021d9e 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,8 @@ Add this to your configuration (usually `~/.config/fish/config.fish`): zoxide init fish | source ``` +Note: zoxide only supports fish v3.4.0 and above. +
diff --git a/man/man1/zoxide-init.1 b/man/man1/zoxide-init.1 index 79d9ee8..a655e8f 100644 --- a/man/man1/zoxide-init.1 +++ b/man/man1/zoxide-init.1 @@ -28,6 +28,8 @@ Add this to your configuration (usually \fB~/.config/fish/config.fish\fR): .nf \fBzoxide init fish | source\fR .fi +.sp +Note: zoxide only supports fish v3.4.0 and above. .TP .B nushell Add this to your env file (find it by running \fB$nu.env-path\fR in Nushell): diff --git a/shell.nix b/shell.nix index eb800e9..513a9da 100644 --- a/shell.nix +++ b/shell.nix @@ -1,8 +1,8 @@ let rust = import (builtins.fetchTarball - "https://github.com/oxalica/rust-overlay/archive/6ddde85465a678aa549cef26dd7ddb012aa0eda3.tar.gz"); + "https://github.com/oxalica/rust-overlay/archive/8b4c5bef319198920fd03a916dd5f6600147358b.tar.gz"); pkgs = import (builtins.fetchTarball - "https://github.com/NixOS/nixpkgs/archive/90e10f361f0a87082adb3553bfddaa63f150dd57.tar.gz") { + "https://github.com/NixOS/nixpkgs/archive/0323e1f8bac882f19905174639a89397db1930f1.tar.gz") { overlays = [ rust ]; }; in pkgs.mkShell { diff --git a/src/config.rs b/src/config.rs index 4ec7903..a58fdd4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,7 +2,7 @@ use std::env; use std::ffi::OsString; use std::path::PathBuf; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result}; use glob::Pattern; use crate::db::Rank; @@ -10,45 +10,34 @@ use crate::db::Rank; pub fn data_dir() -> Result { let path = match env::var_os("_ZO_DATA_DIR") { Some(path) => PathBuf::from(path), - None => match dirs::data_local_dir() { - Some(mut path) => { - path.push("zoxide"); - path - } - None => bail!("could not find data directory, please set _ZO_DATA_DIR manually"), - }, + None => dirs::data_local_dir() + .context("could not find data directory, please set _ZO_DATA_DIR manually")? + .join("zoxide"), }; - Ok(path) } pub fn echo() -> bool { - match env::var_os("_ZO_ECHO") { - Some(var) => var == "1", - None => false, - } + env::var_os("_ZO_ECHO").map_or(false, |var| var == "1") } pub fn exclude_dirs() -> Result> { - env::var_os("_ZO_EXCLUDE_DIRS").map_or_else( - || { + match env::var_os("_ZO_EXCLUDE_DIRS") { + Some(paths) => env::split_paths(&paths) + .map(|path| { + let pattern = path.to_str().context("invalid unicode in _ZO_EXCLUDE_DIRS")?; + Pattern::new(pattern).with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern)) + }) + .collect(), + None => { let pattern = (|| { let home = dirs::home_dir()?; - let home = home.to_str()?; - let home = Pattern::escape(home); + let home = Pattern::escape(home.to_str()?); Pattern::new(&home).ok() })(); Ok(pattern.into_iter().collect()) - }, - |paths| { - env::split_paths(&paths) - .map(|path| { - let pattern = path.to_str().context("invalid unicode in _ZO_EXCLUDE_DIRS")?; - Pattern::new(pattern).with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern)) - }) - .collect() - }, - ) + } + } } pub fn fzf_opts() -> Option { @@ -56,20 +45,14 @@ pub fn fzf_opts() -> Option { } pub fn maxage() -> Result { - match env::var_os("_ZO_MAXAGE") { - Some(maxage) => { - let maxage = maxage.to_str().context("invalid unicode in _ZO_MAXAGE")?; - let maxage = - maxage.parse::().with_context(|| format!("unable to parse _ZO_MAXAGE as integer: {}", maxage))?; - Ok(maxage as Rank) - } - None => Ok(10000.0), - } + env::var_os("_ZO_MAXAGE").map_or(Ok(10_000.0), |maxage| { + let maxage = maxage.to_str().context("invalid unicode in _ZO_MAXAGE")?; + let maxage = + maxage.parse::().with_context(|| format!("unable to parse _ZO_MAXAGE as integer: {}", maxage))?; + Ok(maxage as Rank) + }) } pub fn resolve_symlinks() -> bool { - match env::var_os("_ZO_RESOLVE_SYMLINKS") { - Some(var) => var == "1", - None => false, - } + env::var_os("_ZO_RESOLVE_SYMLINKS").map_or(false, |var| var == "1") } diff --git a/src/db/dir.rs b/src/db/dir.rs index 1661a1f..793bbc5 100644 --- a/src/db/dir.rs +++ b/src/db/dir.rs @@ -132,14 +132,7 @@ pub struct DirDisplayScore<'a> { impl Display for DirDisplayScore<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - let score = self.dir.score(self.now); - let score = if score > 9999.0 { - 9999 - } else if score > 0.0 { - score as u32 - } else { - 0 - }; + let score = self.dir.score(self.now).clamp(0.0, 9999.0) as u32; write!(f, "{:>4} {}", score, self.dir.path) } } diff --git a/src/db/mod.rs b/src/db/mod.rs index f0e99d1..7d527ab 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -94,10 +94,8 @@ impl<'file> Database<'file> { pub fn age(&mut self, max_age: Rank) { let sum_age = self.dirs.iter().map(|dir| dir.rank).sum::(); - if sum_age > max_age { let factor = 0.9 * max_age / sum_age; - for idx in (0..self.dirs.len()).rev() { let dir = &mut self.dirs[idx]; dir.rank *= factor; @@ -105,7 +103,6 @@ impl<'file> Database<'file> { self.dirs.swap_remove(idx); } } - self.modified = true; } } diff --git a/src/db/stream.rs b/src/db/stream.rs index e5d3eb9..91a2ab7 100644 --- a/src/db/stream.rs +++ b/src/db/stream.rs @@ -2,9 +2,7 @@ use std::iter::Rev; use std::ops::Range; use std::{fs, path}; -use ordered_float::OrderedFloat; - -use super::{Database, Dir, Epoch}; +use crate::db::{Database, Dir, Epoch}; use crate::util; pub struct Stream<'db, 'file> { @@ -23,7 +21,7 @@ pub struct Stream<'db, 'file> { impl<'db, 'file> Stream<'db, 'file> { pub fn new(db: &'db mut Database<'file>, now: Epoch) -> Self { // Iterate in descending order of score. - db.dirs.sort_unstable_by_key(|dir| OrderedFloat(dir.score(now))); + db.dirs.sort_unstable_by(|dir1, dir2| dir1.score(now).total_cmp(&dir2.score(now))); let idxs = (0..db.dirs.len()).rev(); // If a directory is deleted and hasn't been used for 90 days, delete it from the database. diff --git a/templates/fish.txt b/templates/fish.txt index 9cd7473..d00fcb1 100644 --- a/templates/fish.txt +++ b/templates/fish.txt @@ -136,4 +136,6 @@ end # To initialize zoxide, add this to your configuration (usually # ~/.config/fish/config.fish): # -# zoxide init fish | source +# zoxide init fish | source +# +# Note: zoxide only supports fish v3.4.0 and above.