feat(init): Use which-rs to resolve starship path

This patch uses the which crate to resolve the starship path, replacing the
current_exe() mechanism.

Co-authored-by: Kevin Song <chips@ksong.dev>
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>
This commit is contained in:
Kevin Menard 2022-11-14 04:28:29 +01:00 committed by GitHub
parent d86e1c1d1c
commit cc2c8c4a54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -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<Self> {
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