diff --git a/Cargo.lock b/Cargo.lock index ef07e09..b409fb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,12 @@ dependencies = [ "syn 2.0.11", ] +[[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" @@ -253,6 +259,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 1.0.109", +] + +[[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.79" @@ -430,6 +474,41 @@ dependencies = [ "syn 2.0.11", ] +[[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 1.0.109", +] + +[[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 1.0.109", +] + [[package]] name = "derivative" version = "2.2.0" @@ -564,6 +643,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.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +dependencies = [ + "futures-core", + "futures-sink", +] + [[package]] name = "futures-core" version = "0.3.27" @@ -661,6 +770,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" @@ -700,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]] @@ -722,6 +837,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.3" @@ -729,7 +850,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -843,6 +964,7 @@ dependencies = [ name = "ls-interactive" version = "1.6.0" dependencies = [ + "cached", "console", "crossterm", "fuzzy-matcher", @@ -1233,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", @@ -1386,6 +1508,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" @@ -1530,6 +1658,29 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tokio" +version = "1.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +dependencies = [ + "autocfg", + "pin-project-lite", + "tokio-macros", + "windows-sys 0.45.0", +] + +[[package]] +name = "tokio-macros" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.11", +] + [[package]] name = "toml" version = "0.7.3" @@ -1767,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" diff --git a/Cargo.toml b/Cargo.toml index 593d38b..eab0a92 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.47.0", features = ["Win32_Storage_FileSystem"] } diff --git a/src/main.rs b/src/main.rs index 3bc1d42..aaa3cee 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() { @@ -79,7 +76,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 { @@ -110,7 +107,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 8c7ef74..903bc97 100644 --- a/src/structs/prompt_renderer.rs +++ b/src/structs/prompt_renderer.rs @@ -4,7 +4,7 @@ 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,11 +183,16 @@ impl Theme { cursor_pos: usize, ) -> fmt::Result { if !prompt.is_empty() { + let link_text = if cfg!(windows) && prompt == get_computer_name() { + 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) )?; } 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")) +}