Skip to main content

idt/installers/
zellij.rs

1use std::path::Path;
2
3use rootcause::prelude::ResultExt;
4
5use crate::Installer;
6
7pub struct Zellij<'a> {
8    pub dev_tools_dir: &'a Path,
9    pub bin_dir: &'a Path,
10}
11
12impl Installer for Zellij<'_> {
13    fn bin_name(&self) -> &'static str {
14        "zellij"
15    }
16
17    fn install(&self) -> rootcause::Result<()> {
18        let source_dir = self.dev_tools_dir.join(self.bin_name()).join("source");
19        let cargo_target = self.dev_tools_dir.join("cargo-target");
20
21        ytil_cmd::silent_cmd("sh")
22            .args([
23                "-c",
24                &format!(
25                    r#"
26                        ([ ! -d "{0}" ] && \
27                            git clone --depth=1 https://github.com/zellij-org/zellij.git {0} || true) && \
28                        cd {0} && \
29                        git fetch origin main --depth=1 && \
30                        git checkout origin/main && \
31                        CARGO_TARGET_DIR={1} cargo build --release
32                    "#,
33                    source_dir.display(),
34                    cargo_target.display(),
35                ),
36            ])
37            .status()
38            .context("failed to spawn build command")?
39            .exit_ok()
40            .context("build failed")
41            .attach_with(|| format!("tool={}", self.bin_name()))
42            .attach_with(|| format!("source_dir={}", source_dir.display()))?;
43
44        let target = cargo_target.join("release").join(self.bin_name());
45        ytil_sys::file::ln_sf(&target, &self.bin_dir.join(self.bin_name()))?;
46        ytil_sys::file::chmod_x(&target)?;
47
48        Ok(())
49    }
50
51    fn should_verify_checksum(&self) -> bool {
52        false
53    }
54}