Skip to content

Commit

Permalink
Merge pull request #51 from Araxeus/fix-windows-pc-link
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus authored Mar 30, 2023
2 parents 27b1a96 + c53c128 commit 0802d19
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 22 deletions.
172 changes: 157 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -79,7 +76,7 @@ fn get_choices(entry: &Entry) -> Vec<Entry> {
#[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 {
Expand Down Expand Up @@ -110,7 +107,7 @@ fn get_choices(entry: &Entry) -> Vec<Entry> {
// .. 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,
});
Expand Down
9 changes: 7 additions & 2 deletions src/structs/prompt_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
)?;
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ fn bitmask_to_vec(bitmask: u32) -> Vec<char> {
}
vec
}

#[cached::proc_macro::once]
pub fn get_computer_name() -> String {
env::var("COMPUTERNAME").unwrap_or_else(|_| String::from("My Computer"))
}

0 comments on commit 0802d19

Please sign in to comment.