checkpoint: began to write the neovim target
This commit is contained in:
parent
5f8ac4b035
commit
ab68d7b954
2 changed files with 76 additions and 0 deletions
|
@ -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()
|
||||
|
||||
|
|
68
magefiles/neovim.go
Normal file
68
magefiles/neovim.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue