diff --git a/magefiles/config.go b/magefiles/config.go index f974bf2..c3c2eea 100644 --- a/magefiles/config.go +++ b/magefiles/config.go @@ -15,6 +15,7 @@ type config struct { BashProfile configBashProfile `json:"bashProfile"` Directories configDirectories `json:"directories"` Git configGit `json:"git"` + Neovim configNeovim `json:"neovim"` } type configDirectories struct { @@ -54,6 +55,13 @@ type configBashProfileCommand struct { Description string `json:"description"` } +type configNeovim struct { + Manage bool `json:"manage"` + GitRepoURL string `json:"gitRepoURL"` + GitRef string `json:"gitRef"` + GitRepoPath string `json:"gitRepoPath"` +} + func newConfig() (config, error) { cfg := defaultConfig() diff --git a/magefiles/neovim.go b/magefiles/neovim.go new file mode 100644 index 0000000..45442a0 --- /dev/null +++ b/magefiles/neovim.go @@ -0,0 +1,68 @@ +//go:build mage + +package main + +import ( + "fmt" + "os" + "path/filepath" +) + +// 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., config.Neovim.) + + defer func() { + if err := os.Remove(tempLocalRepo); err != nil { + return fmt.Errorf( + "received an error while trying to remove %s: %w", + err, + ) + } + }() + + // 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) { + tempDir, err := os.MkdirTemp("/tmp", "neovim-config-") + if err != nil { + return "", fmt.Errorf("unable to create the temporary directory: %w", err) + } + + // TODO: clone the repo to the tempDir and return tempDir + + return tempDir, nil +}