//go:build mage package main import ( "fmt" "os" "slices" "github.com/magefile/mage/sh" ) // Neovim downloads and manages neovim configuration from a remote git repository. func Neovim() error { config, err := newConfig() if err != nil { return fmt.Errorf( "unable to load the configuration: %w", err, ) } if !config.Neovim.Manage { return nil } //homeConfigDirectory, err := os.UserConfigDir() //if err != nil { // return fmt.Errorf( // "unable to get the user's home configuration directory: %w", // err, // ) //} var ( // neovimManagedDir = filepath.Join(rootManagedDir, "nvim") // versionLabelFile = filepath.Join(neovimManagedDir, ".managed.version") // neovimConfigDir = filepath.Join(homeConfigDirectory, "nvim") ) tempLocalRepo, err := cloneNvimConfigRepo(config.Neovim.GitRepoURL, config.Neovim.GitRef) if err != nil { return fmt.Errorf("unable to clone the git repository: %w", err) } fmt.Println("Git repository cloned to:", tempLocalRepo) // defer os.Remove(tempLocalRepo) // TODO: copy the files from temp folder to managed folder // TODO: add commit/tag ref to .managed.version // TODO: symlink all inside managed neovim folder return nil } func cloneNvimConfigRepo(repoURL, repoRef string) (string, error) { cloneDir, err := os.MkdirTemp("/tmp", "neovim-config-") if err != nil { return "", fmt.Errorf("unable to create the temporary directory: %w", err) } git := sh.RunCmd("git", "-C", cloneDir) commands := [][]string{ {"init"}, {"remote", "add", "origin", repoURL}, {"fetch", "origin", repoRef}, {"checkout", "FETCH_HEAD"}, } for _, command := range slices.All(commands) { if err := git(command...); err != nil { return "", err } } return cloneDir, nil }