From 94b9ecb965d15e2ea6d5a81ed6e274936b46c262 Mon Sep 17 00:00:00 2001 From: Richard Stoffels Date: Sun, 1 Mar 2026 17:32:30 +0100 Subject: [PATCH] feat: install slash command for global installs --- src/skill/claude_code.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/skill/claude_code.rs b/src/skill/claude_code.rs index 888bb48..702367e 100644 --- a/src/skill/claude_code.rs +++ b/src/skill/claude_code.rs @@ -86,18 +86,31 @@ fn remove_block(existing: &str) -> String { } } -fn install_slash_command() -> Result<(), CodehudError> { - let dir = PathBuf::from(".claude/commands"); - fs::create_dir_all(&dir)?; - let path = dir.join("codehud.md"); +fn slash_command_path(global: bool) -> Result { + if global { + Ok(dirs::home_dir() + .ok_or(CodehudError::HomeDir)? + .join(".claude/commands/codehud.md")) + } else { + Ok(PathBuf::from(".claude/commands/codehud.md")) + } +} + +fn install_slash_command(global: bool) -> Result<(), CodehudError> { + let path = slash_command_path(global)?; + if let Some(parent) = path.parent() { + fs::create_dir_all(parent)?; + } fs::write(&path, SLASH_COMMAND)?; info!(path = %path.display(), "Installed slash command"); println!("Installed slash command to {}", path.display()); Ok(()) } -fn uninstall_slash_command() { - let path = PathBuf::from(".claude/commands/codehud.md"); +fn uninstall_slash_command(global: bool) { + let Ok(path) = slash_command_path(global) else { + return; + }; if path.exists() { if let Ok(()) = fs::remove_file(&path) { println!("Removed {}", path.display()); @@ -118,10 +131,7 @@ impl PlatformAdapter for ClaudeCodeAdapter { info!(path = %path.display(), "Installed codehud skill"); println!("Installed codehud skill to {}", path.display()); - // Install slash command for project-local installs - if !global { - install_slash_command()?; - } + install_slash_command(global)?; Ok(()) } @@ -141,9 +151,7 @@ impl PlatformAdapter for ClaudeCodeAdapter { println!("Removed codehud block from {}", path.display()); } - if !global { - uninstall_slash_command(); - } + uninstall_slash_command(global); Ok(()) }