68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
//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
|
|
}
|