Skip to content

Commit 5679189

Browse files
committed
feat: add auto-completion uninstall command
1 parent 6b33654 commit 5679189

File tree

1 file changed

+55
-0
lines changed
  • crates/rustmotion-cli/src

1 file changed

+55
-0
lines changed

crates/rustmotion-cli/src/lib.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ enum SkillsAction {
159159
enum CompletionsAction {
160160
/// Install completions to the current shell config
161161
Install,
162+
/// Remove installed completions
163+
Uninstall,
162164
/// Print completions to stdout
163165
Generate {
164166
/// Shell to generate completions for
@@ -232,6 +234,7 @@ pub fn run() -> Result<()> {
232234
Ok(())
233235
}
234236
CompletionsAction::Install => install_completions(),
237+
CompletionsAction::Uninstall => uninstall_completions(),
235238
}
236239
}
237240
}
@@ -304,3 +307,55 @@ fn install_completions() -> Result<()> {
304307

305308
Ok(())
306309
}
310+
311+
fn uninstall_completions() -> Result<()> {
312+
let shell = detect_shell().ok_or_else(|| {
313+
RustmotionError::Generic("Could not detect shell.".into())
314+
})?;
315+
316+
let home = dirs::home_dir().ok_or_else(|| RustmotionError::Generic("Could not find home directory".into()))?;
317+
318+
match shell {
319+
clap_complete::Shell::Zsh => {
320+
let path = home.join(".zfunc/_rustmotion");
321+
if path.exists() {
322+
std::fs::remove_file(&path)?;
323+
eprintln!("Removed {}", path.display());
324+
}
325+
326+
// Remove fpath lines from .zshrc
327+
let zshrc = home.join(".zshrc");
328+
if zshrc.exists() {
329+
let content = std::fs::read_to_string(&zshrc)?;
330+
let filtered: Vec<&str> = content.lines().filter(|line| {
331+
let trimmed = line.trim();
332+
trimmed != "# rustmotion completions"
333+
&& !(trimmed.contains(".zfunc") && trimmed.starts_with("fpath="))
334+
&& !(trimmed.contains("compinit") && trimmed.starts_with("autoload"))
335+
}).collect();
336+
std::fs::write(&zshrc, filtered.join("\n") + "\n")?;
337+
eprintln!("Cleaned ~/.zshrc");
338+
}
339+
}
340+
clap_complete::Shell::Bash => {
341+
let path = home.join(".local/share/bash-completion/completions/rustmotion");
342+
if path.exists() {
343+
std::fs::remove_file(&path)?;
344+
eprintln!("Removed {}", path.display());
345+
}
346+
}
347+
clap_complete::Shell::Fish => {
348+
let path = home.join(".config/fish/completions/rustmotion.fish");
349+
if path.exists() {
350+
std::fs::remove_file(&path)?;
351+
eprintln!("Removed {}", path.display());
352+
}
353+
}
354+
_ => {
355+
return Err(RustmotionError::Generic(format!("Unsupported shell: {:?}", shell)).into());
356+
}
357+
}
358+
359+
eprintln!("Completions uninstalled. Restart your shell.");
360+
Ok(())
361+
}

0 commit comments

Comments
 (0)