From afe29a81095249ad4445283b8b1d3c24cad4ce47 Mon Sep 17 00:00:00 2001 From: syui Date: Mon, 2 Mar 2026 19:03:52 +0900 Subject: [PATCH] fix path --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index e8127a2..4ec0656 100644 --- a/src/main.rs +++ b/src/main.rs @@ -94,7 +94,8 @@ fn run_setup() -> Result<()> { .expect("Cannot find config directory") .join("ai.syui.log") .join("config.json"); - let aigpt_bin = std::env::current_exe().unwrap_or_else(|_| "aigpt".into()); + let aigpt_bin = which_command("aigpt") + .unwrap_or_else(|| "aigpt".into()); // 1. ~/ai/ std::fs::create_dir_all(&ai_dir)?; @@ -156,12 +157,17 @@ fn run_setup() -> Result<()> { Ok(()) } -fn is_command_available(cmd: &str) -> bool { +fn which_command(cmd: &str) -> Option { Command::new("which") .arg(cmd) .output() - .map(|o| o.status.success()) - .unwrap_or(false) + .ok() + .filter(|o| o.status.success()) + .map(|o| std::path::PathBuf::from(String::from_utf8_lossy(&o.stdout).trim())) +} + +fn is_command_available(cmd: &str) -> bool { + which_command(cmd).is_some() } fn print_status() {