From 58955e056fa29d52d60013aa3781f38a79801dd5 Mon Sep 17 00:00:00 2001 From: 409 Date: Tue, 21 May 2024 22:57:33 +0200 Subject: [PATCH] feat: includes executables in ~/.cargo/bin/ if present --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/executables.rs | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b83a251..3db05e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,15 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -154,6 +163,7 @@ version = "0.1.0" dependencies = [ "clap", "fuzzy-matcher", + "home", "sdl2", ] diff --git a/Cargo.toml b/Cargo.toml index 84badff..88c6e21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ strip = true [dependencies] clap = { version = "4.5.4", features = ["derive"] } fuzzy-matcher = "0.3.7" +home = "0.5.9" sdl2 = { version = "0.36.0", features = ["ttf"] } diff --git a/src/executables.rs b/src/executables.rs index d97c50b..b090224 100644 --- a/src/executables.rs +++ b/src/executables.rs @@ -5,11 +5,21 @@ pub fn get_executables() -> Result, Box> { get_files(Path::new("/usr/local"), &mut executables)?; get_files(Path::new("/bin"), &mut executables)?; + match home::cargo_home() { + Ok(cargo_home) => { + get_files(&cargo_home.join("bin"), &mut executables)?; + } + Err(_) => (), + } Ok(executables) } pub fn get_files(path: &Path, files: &mut Vec) -> Result<(), Box> { + if !path.exists() { + return Ok(()); + } + let dirs = fs::read_dir(path)?; for e in dirs {