Skip to content

Commit

Permalink
feat(init): Use which-rs to resolve starship path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people committed Nov 14, 2022
1 parent d86e1c1 commit cc2c8c4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/init/mod.rs
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit cc2c8c4

Please sign in to comment.