From 3315cca3793e38bb0abc58377861c5019d102e44 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 17 Mar 2023 21:28:22 +0200 Subject: [PATCH 1/4] [Windows] fix `My Computer` link in dirview depends on https://github.com/microsoft/terminal/pull/14993 --- src/structs/prompt_renderer.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/structs/prompt_renderer.rs b/src/structs/prompt_renderer.rs index 8c7ef74..41f2b07 100644 --- a/src/structs/prompt_renderer.rs +++ b/src/structs/prompt_renderer.rs @@ -183,11 +183,16 @@ impl Theme { cursor_pos: usize, ) -> fmt::Result { if !prompt.is_empty() { + let link_text = if cfg!(windows) && prompt == env!("COMPUTERNAME") { + link_with_label("shell:MyComputerFolder", prompt) + } else { + link(prompt) + }; write!( f, "{} {} ", &self.prompt_prefix, - self.prompt_style.apply_to(link(prompt)) + self.prompt_style.apply_to(link_text) )?; } From 3c0d1eb949e5a16bf635d233eeabaa4f20d28032 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Wed, 29 Mar 2023 20:50:49 +0300 Subject: [PATCH 2/4] replace `env!` with `std::env::var` The macro doesn't fetch at runtime for some reason, so we use this method instead --- src/structs/prompt_renderer.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/structs/prompt_renderer.rs b/src/structs/prompt_renderer.rs index 41f2b07..ef3be37 100644 --- a/src/structs/prompt_renderer.rs +++ b/src/structs/prompt_renderer.rs @@ -1,5 +1,5 @@ //! Customizes the rendering of the elements. -use std::{fmt, io}; +use std::{env, fmt, io}; use console::{style, Style, StyledObject, Term}; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; @@ -183,7 +183,9 @@ impl Theme { cursor_pos: usize, ) -> fmt::Result { if !prompt.is_empty() { - let link_text = if cfg!(windows) && prompt == env!("COMPUTERNAME") { + let link_text = if cfg!(windows) + && prompt == env::var("COMPUTERNAME").unwrap_or("My Computer".to_string()) + { link_with_label("shell:MyComputerFolder", prompt) } else { link(prompt) From 8c6b648db4fdea4af8527dc277459be9c35a4346 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Wed, 29 Mar 2023 22:35:59 +0300 Subject: [PATCH 3/4] create cached `fn get_computer_name()` --- Cargo.lock | 153 ++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/main.rs | 7 +- src/structs/prompt_renderer.rs | 8 +- src/utils.rs | 5 ++ 5 files changed, 163 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38151b4..9882e26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,6 +141,12 @@ dependencies = [ "syn", ] +[[package]] +name = "async_once" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ce4f10ea3abcd6617873bae9f91d1c5332b4a778bd9ce34d0cd517474c1de82" + [[package]] name = "atomic-waker" version = "1.1.0" @@ -215,6 +221,44 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cached" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5877db5d1af7fae60d06b5db9430b68056a69b3582a0be8e3691e87654aeb6" +dependencies = [ + "async-trait", + "async_once", + "cached_proc_macro", + "cached_proc_macro_types", + "futures", + "hashbrown 0.13.2", + "instant", + "lazy_static", + "once_cell", + "thiserror", + "tokio", +] + +[[package]] +name = "cached_proc_macro" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10ca87c81aaa3a949dbbe2b5e6c2c45dbc94ba4897e45ea31ff9ec5087be3dc" +dependencies = [ + "cached_proc_macro_types", + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "cached_proc_macro_types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" + [[package]] name = "cc" version = "1.0.78" @@ -394,6 +438,41 @@ dependencies = [ "syn", ] +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "derivative" version = "2.2.0" @@ -528,6 +607,36 @@ dependencies = [ "instant", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +dependencies = [ + "futures-core", + "futures-sink", +] + [[package]] name = "futures-core" version = "0.3.25" @@ -625,6 +734,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" + [[package]] name = "heck" version = "0.3.3" @@ -686,6 +801,12 @@ dependencies = [ "cxx-build", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "indexmap" version = "1.9.2" @@ -693,7 +814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -806,6 +927,7 @@ dependencies = [ name = "ls-interactive" version = "1.6.0" dependencies = [ + "cached", "console", "crossterm", "fuzzy-matcher", @@ -1356,6 +1478,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strum" version = "0.22.0" @@ -1489,6 +1617,29 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tokio" +version = "1.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +dependencies = [ + "autocfg", + "pin-project-lite", + "tokio-macros", + "windows-sys 0.45.0", +] + +[[package]] +name = "tokio-macros" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "toml" version = "0.7.2" diff --git a/Cargo.toml b/Cargo.toml index 0c186a3..09d8d26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ fuzzy-matcher = "0.3.7" crossterm = "0.26.1" unicode-segmentation = "1.10.1" tiny_update_notifier = "2.2.0" +cached = "0.42.0" [target.'cfg(windows)'.dependencies] windows = { version = "0.44.0", features = ["Win32_Storage_FileSystem"] } diff --git a/src/main.rs b/src/main.rs index 8430248..8a29891 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,6 @@ use std::{fs, path::Path}; use structs::{Entry, Filetype, Icons}; use utils::{display_choices, err, get_first_arg, pretty_path, resolve_lnk, KeyModifiers}; -#[cfg(windows)] -use utils::get_logical_drives; - use tiny_update_notifier::check_github; fn main() { @@ -75,7 +72,7 @@ fn get_choices(entry: &Entry) -> Vec { #[cfg(windows)] // Open Drives View on Windows if entry.filetype == Filetype::DriveView { - match get_logical_drives() { + match utils::get_logical_drives() { Ok(drives) => { for drive in drives { result_vector.push(Entry { @@ -106,7 +103,7 @@ fn get_choices(entry: &Entry) -> Vec { // .. Open Drives View on Windows result_vector.push(Entry { name: String::from(".."), - path: env!("COMPUTERNAME").to_string(), + path: utils::get_computer_name(), icon: &Icons::PC, filetype: Filetype::DriveView, }); diff --git a/src/structs/prompt_renderer.rs b/src/structs/prompt_renderer.rs index ef3be37..903bc97 100644 --- a/src/structs/prompt_renderer.rs +++ b/src/structs/prompt_renderer.rs @@ -1,10 +1,10 @@ //! Customizes the rendering of the elements. -use std::{env, fmt, io}; +use std::{fmt, io}; use console::{style, Style, StyledObject, Term}; use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; -use crate::utils::{link, link_with_label, pretty_path}; +use crate::utils::{get_computer_name, link, link_with_label, pretty_path}; use super::Entry; @@ -183,9 +183,7 @@ impl Theme { cursor_pos: usize, ) -> fmt::Result { if !prompt.is_empty() { - let link_text = if cfg!(windows) - && prompt == env::var("COMPUTERNAME").unwrap_or("My Computer".to_string()) - { + let link_text = if cfg!(windows) && prompt == get_computer_name() { link_with_label("shell:MyComputerFolder", prompt) } else { link(prompt) diff --git a/src/utils.rs b/src/utils.rs index df4b33d..02c908a 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -100,3 +100,8 @@ fn bitmask_to_vec(bitmask: u32) -> Vec { } vec } + +#[cached::proc_macro::once] +pub fn get_computer_name() -> String { + env::var("COMPUTERNAME").unwrap_or_else(|_| String::from("My Computer")) +} From 2b9106279fe07ecdcf0ad5e6fe2c95f57a47c22a Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Thu, 30 Mar 2023 18:41:18 +0300 Subject: [PATCH 4/4] Update Cargo.lock --- Cargo.lock | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6ae8ac..b409fb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -288,7 +288,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -495,7 +495,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 1.0.109", ] [[package]] @@ -506,7 +506,7 @@ checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ "darling_core", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -651,9 +651,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "futures" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" dependencies = [ "futures-channel", "futures-core", @@ -665,9 +665,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" dependencies = [ "futures-core", "futures-sink", @@ -815,16 +815,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.54" +version = "0.1.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" +checksum = "716f12fbcfac6ffab0a5e9ec51d0a0ff70503742bb2dc7b99396394c9dc323f0" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows 0.46.0", + "windows 0.47.0", ] [[package]] @@ -1355,9 +1355,9 @@ checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" [[package]] name = "rustix" -version = "0.37.4" +version = "0.37.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c348b5dc624ecee40108aa2922fed8bad89d7fcc2b9f8cb18f632898ac4a37f9" +checksum = "0e78cc525325c06b4a7ff02db283472f3c042b7ff0c391f96c6d5ac6f4f91b75" dependencies = [ "bitflags", "errno", @@ -1660,9 +1660,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.26.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "pin-project-lite", @@ -1672,13 +1672,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.11", ] [[package]] @@ -1918,15 +1918,6 @@ dependencies = [ "windows_x86_64_msvc 0.39.0", ] -[[package]] -name = "windows" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows" version = "0.47.0"