aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/comp
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-11 19:56:10 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-11 19:56:10 +0800
commite42567b25093907cfd939edc92ace94a5d59b398 (patch)
treef2514fdd18277b5620b0fd6512cfc95569cfce15 /mingling_core/src/comp
parent99d5a62aa3655f8676021a9bf70af3d12c9457bc (diff)
Add `builds` feature and install completion scripts
Diffstat (limited to 'mingling_core/src/comp')
-rw-r--r--mingling_core/src/comp/installation.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/mingling_core/src/comp/installation.rs b/mingling_core/src/comp/installation.rs
new file mode 100644
index 0000000..d3d31d6
--- /dev/null
+++ b/mingling_core/src/comp/installation.rs
@@ -0,0 +1,72 @@
+use crate::{build::build_comp_script_to_file, ShellFlag};
+
+pub fn install_comp_script(
+ flag: ShellFlag,
+ bin_name: impl AsRef<str>,
+) -> Result<(), std::io::Error> {
+ match flag {
+ // ~/.local/share/bash-completion/completions/
+ ShellFlag::Bash => {
+ let Some(data_dir) = dirs::data_dir() else {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::Unsupported,
+ "Data directory not found!",
+ ));
+ };
+
+ let bin_name = bin_name.as_ref();
+
+ let comp_script_path = data_dir
+ .join("bash-completion")
+ .join("completions")
+ .join(format!("{}.sh", bin_name));
+
+ build_comp_script_to_file(&ShellFlag::Bash, bin_name, comp_script_path)?;
+ Ok(())
+ }
+
+ // ~/.zsh/completions/
+ ShellFlag::Zsh => {
+ let Some(home_dir) = dirs::home_dir() else {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::Unsupported,
+ "Home directory not found!",
+ ));
+ };
+
+ let bin_name = bin_name.as_ref();
+
+ let comp_script_path = home_dir
+ .join(".zsh")
+ .join("completions")
+ .join(format!("{}.zsh", bin_name));
+
+ build_comp_script_to_file(&ShellFlag::Zsh, bin_name, comp_script_path)?;
+ Ok(())
+ }
+
+ // ~/.config/fish/completions/
+ ShellFlag::Fish => {
+ let Some(config_dir) = dirs::config_dir() else {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::Unsupported,
+ "Config directory not found!",
+ ));
+ };
+
+ let bin_name = bin_name.as_ref();
+
+ let comp_script_path = config_dir
+ .join("fish")
+ .join("completions")
+ .join(format!("{}.fish", bin_name));
+
+ build_comp_script_to_file(&ShellFlag::Fish, bin_name, comp_script_path)?;
+ Ok(())
+ }
+ _ => Err(std::io::Error::new(
+ std::io::ErrorKind::Unsupported,
+ "unsupported shell flag",
+ )),
+ }
+}