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