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