From cc2c8c4a5450f2811612129abfbdc1aba12def91 Mon Sep 17 00:00:00 2001 From: Kevin Menard Date: Mon, 14 Nov 2022 04:28:29 +0100 Subject: [PATCH] feat(init): Use which-rs to resolve starship path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch uses the which crate to resolve the starship path, replacing the current_exe() mechanism. Co-authored-by: Kevin Song Co-authored-by: David Knaack Co-authored-by: Dario Vladović --- src/init/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/init/mod.rs b/src/init/mod.rs index 5cbcab21..4289727e 100644 --- a/src/init/mod.rs +++ b/src/init/mod.rs @@ -3,6 +3,8 @@ use std::ffi::OsStr; use std::path::{Path, PathBuf}; use std::{env, io}; +use which::which; + /* We use a two-phase init here: the first phase gives a simple command to the shell. This command evaluates a more complicated script using `source` and process substitution. @@ -23,9 +25,11 @@ struct StarshipPath { } impl StarshipPath { fn init() -> io::Result { - Ok(Self { - native_path: env::current_exe()?, - }) + let exe_name = option_env!("CARGO_PKG_NAME").unwrap_or("starship"); + + let native_path = which(exe_name).or_else(|_| env::current_exe())?; + + Ok(Self { native_path }) } fn str_path(&self) -> io::Result<&str> { let current_exe = self