intelli_shell/utils/
installation.rs1use std::{env, path::Path};
2
3#[derive(Debug, PartialEq, Eq)]
4pub enum InstallationMethod {
5 Installer,
7 Cargo,
9 Nix,
11 Source,
13 Unknown(Option<String>),
15}
16
17pub fn detect_installation_method(data_dir: impl AsRef<Path>) -> InstallationMethod {
19 let current_exe = match env::current_exe() {
20 Ok(path) => path,
21 Err(_) => return InstallationMethod::Unknown(None),
22 };
23
24 let installer_bin_path = data_dir.as_ref().join("bin");
27 if current_exe.starts_with(installer_bin_path) {
28 return InstallationMethod::Installer;
29 }
30
31 let path_str = current_exe.to_string_lossy();
33 if path_str.starts_with("/nix/store/") {
34 InstallationMethod::Nix
36 } else if path_str.contains(".cargo/bin") {
37 InstallationMethod::Cargo
39 } else if path_str.contains("target/debug") || path_str.contains("target/release") {
40 InstallationMethod::Source
42 } else {
43 InstallationMethod::Unknown(Some(path_str.to_string()))
44 }
45}