idt/installers/
nvim.rs

1use std::path::Path;
2
3use ytil_cmd::silent_cmd;
4
5use crate::Installer;
6
7pub struct Nvim<'a> {
8    pub dev_tools_dir: &'a Path,
9    pub bin_dir: &'a Path,
10}
11
12impl Installer for Nvim<'_> {
13    fn bin_name(&self) -> &'static str {
14        "nvim"
15    }
16
17    fn install(&self) -> color_eyre::Result<()> {
18        // Compiling from sources because I can checkout specific refs in case of broken nightly builds.
19        // Moreover...it's pretty badass 😎
20        let nvim_source_dir = self.dev_tools_dir.join(self.bin_name()).join("source");
21        let nvim_release_dir = self.dev_tools_dir.join(self.bin_name()).join("release");
22
23        silent_cmd("sh")
24            .args([
25                "-c",
26                &format!(
27                    r#"
28                        ([ ! -d "{0}" ] && \
29                            git clone https://github.com/neovim/neovim {0} || true) && \
30                        cd {0} && \
31                        git checkout master && \
32                        git pull origin master && \
33                        make distclean && \
34                        make CMAKE_BUILD_TYPE=Release CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX={1}" && \
35                        make install
36                    "#,
37                    nvim_source_dir.display(),
38                    nvim_release_dir.display(),
39                ),
40            ])
41            .status()?
42            .exit_ok()?;
43
44        let target = nvim_release_dir.join("bin").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 check_args(&self) -> Option<&[&str]> {
52        Some(&["-V1", "-v"])
53    }
54}