From b6130551c440bd78f0caa1690925e0235d0cf6b1 Mon Sep 17 00:00:00 2001 From: mauriciopolvora Date: Fri, 14 Nov 2025 13:13:31 +0000 Subject: [PATCH 1/2] Update CLI installation path and improve related messages --- src-tauri/src/commands/cli.rs | 65 ++++++++----------- .../components/tabs/general-settings.tsx | 2 +- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src-tauri/src/commands/cli.rs b/src-tauri/src/commands/cli.rs index 75a0d69c..424dfedf 100644 --- a/src-tauri/src/commands/cli.rs +++ b/src-tauri/src/commands/cli.rs @@ -2,12 +2,17 @@ use std::fs; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; #[cfg(unix)] -use std::path::Path; use tauri::command; // Platform-specific CLI paths #[cfg(unix)] -const CLI_SCRIPT_PATH: &str = "/usr/local/bin/athas"; +fn get_cli_script_path() -> Result { + let home = std::env::var("HOME").map_err(|_| "Failed to get home directory".to_string())?; + Ok(std::path::PathBuf::from(home) + .join(".local") + .join("bin") + .join("athas")) +} #[cfg(windows)] fn get_cli_script_path() -> Result { @@ -21,21 +26,18 @@ fn get_cli_script_path() -> Result { #[command] pub fn check_cli_installed() -> Result { - #[cfg(unix)] - { - Ok(Path::new(CLI_SCRIPT_PATH).exists()) - } - - #[cfg(windows)] - { - let cli_path = get_cli_script_path()?; - Ok(cli_path.exists()) - } + let cli_path = get_cli_script_path()?; + Ok(cli_path.exists()) } #[cfg(unix)] #[command] pub fn install_cli_command() -> Result { + let cli_path = get_cli_script_path()?; + let bin_dir = cli_path + .parent() + .ok_or_else(|| "Failed to get parent directory".to_string())?; + // Create the CLI launcher script content let script_content = r#"#!/bin/bash # Athas CLI launcher @@ -51,37 +53,27 @@ else fi "#; - // Check if /usr/local/bin exists, create if not - let bin_dir = Path::new("/usr/local/bin"); + // Create the bin directory if it doesn't exist if !bin_dir.exists() { - fs::create_dir_all(bin_dir).map_err(|e| { - format!( - "Failed to create /usr/local/bin directory: {}. You may need to run this with \ - administrator privileges.", - e - ) - })?; + fs::create_dir_all(bin_dir).map_err(|e| format!("Failed to create directory: {}", e))?; } // Write the script - fs::write(CLI_SCRIPT_PATH, script_content).map_err(|e| { - format!( - "Failed to write CLI script: {}. You may need to run this with administrator privileges.", - e - ) - })?; + fs::write(&cli_path, script_content) + .map_err(|e| format!("Failed to write CLI script: {}", e))?; // Make the script executable - let mut perms = fs::metadata(CLI_SCRIPT_PATH) + let mut perms = fs::metadata(&cli_path) .map_err(|e| format!("Failed to get file permissions: {}", e))? .permissions(); perms.set_mode(0o755); - fs::set_permissions(CLI_SCRIPT_PATH, perms) + fs::set_permissions(&cli_path, perms) .map_err(|e| format!("Failed to set executable permissions: {}", e))?; Ok(format!( - "CLI command installed successfully at {}. You can now type 'athas' in your terminal!", - CLI_SCRIPT_PATH + "CLI command installed successfully at {}.\n\nNote: Make sure {} is in your PATH. Add this to your ~/.zshrc or ~/.bashrc:\nexport PATH=\"$HOME/.local/bin:$PATH\"", + cli_path.display(), + bin_dir.display() )) } @@ -135,16 +127,13 @@ if exist "%LOCALAPPDATA%\Programs\Athas\Athas.exe" ( #[cfg(unix)] #[command] pub fn uninstall_cli_command() -> Result { - if !Path::new(CLI_SCRIPT_PATH).exists() { + let cli_path = get_cli_script_path()?; + + if !cli_path.exists() { return Err("CLI command is not installed".to_string()); } - fs::remove_file(CLI_SCRIPT_PATH).map_err(|e| { - format!( - "Failed to remove CLI script: {}. You may need to run this with administrator privileges.", - e - ) - })?; + fs::remove_file(&cli_path).map_err(|e| format!("Failed to remove CLI script: {}", e))?; Ok("CLI command uninstalled successfully".to_string()) } diff --git a/src/features/settings/components/tabs/general-settings.tsx b/src/features/settings/components/tabs/general-settings.tsx index eace74e8..66bd0768 100644 --- a/src/features/settings/components/tabs/general-settings.tsx +++ b/src/features/settings/components/tabs/general-settings.tsx @@ -178,7 +178,7 @@ export const GeneralSettings = () => { cliChecking ? "Checking..." : cliInstalled - ? "CLI command is installed at /usr/local/bin/athas" + ? "CLI command is installed at $HOME/.local/bin/athas" : "Install 'athas' command to launch app from terminal" } > From 1013369df6638e082b7b1091a72e818fe8159a77 Mon Sep 17 00:00:00 2001 From: mauriciopolvora Date: Sat, 15 Nov 2025 01:15:14 +0000 Subject: [PATCH 2/2] Fixed formatting --- src-tauri/src/commands/cli.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/commands/cli.rs b/src-tauri/src/commands/cli.rs index 424dfedf..c321ee8d 100644 --- a/src-tauri/src/commands/cli.rs +++ b/src-tauri/src/commands/cli.rs @@ -71,7 +71,8 @@ fi .map_err(|e| format!("Failed to set executable permissions: {}", e))?; Ok(format!( - "CLI command installed successfully at {}.\n\nNote: Make sure {} is in your PATH. Add this to your ~/.zshrc or ~/.bashrc:\nexport PATH=\"$HOME/.local/bin:$PATH\"", + "CLI command installed successfully at {}.\n\nNote: Make sure {} is in your PATH. Add this \ + to your ~/.zshrc or ~/.bashrc:\nexport PATH=\"$HOME/.local/bin:$PATH\"", cli_path.display(), bin_dir.display() ))