Compare commits
2 commits
c5c643197f
...
b2e1cb30cd
Author | SHA1 | Date | |
---|---|---|---|
b2e1cb30cd | |||
ab68d7b954 |
3 changed files with 96 additions and 1 deletions
|
@ -193,5 +193,11 @@
|
|||
"user-dirs.dirs",
|
||||
"user-dirs.locale",
|
||||
"zk"
|
||||
]
|
||||
],
|
||||
"neovim": {
|
||||
"manage": true,
|
||||
"gitRepoURL": "https://codeflow.dananglin.me.uk/linux-home/nvim.d.git",
|
||||
"gitRef": "746f07efdb203a46a7a02ada987cd97b68fa92d6",
|
||||
"gitRepoPath": "nvim"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
81
magefiles/neovim.go
Normal file
81
magefiles/neovim.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
//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
|
||||
}
|
Loading…
Reference in a new issue