feat(theming): integrate NvChad chadrc rewrite into Apply
This commit is contained in:
@@ -88,6 +88,44 @@ func (m Module) resolvedTheme() string {
|
||||
return "gruvbox"
|
||||
}
|
||||
|
||||
// WriteChadrc renders chadrc.lua for the given NvChad theme name and writes
|
||||
// it to ~/.config/nvim/lua/chadrc.lua. If the file does not already exist
|
||||
// and the surrounding nvim config dir does not exist, the function returns
|
||||
// nil without writing anything (the user hasn't installed neovim yet).
|
||||
//
|
||||
// Exported so the theming package can re-render chadrc on theme switches
|
||||
// without re-running the full Module pipeline.
|
||||
func WriteChadrc(nvChadThemeName string) error {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := filepath.Join(home, ".config", "nvim")
|
||||
chadrcPath := filepath.Join(cfg, "lua", "chadrc.lua")
|
||||
|
||||
// If chadrc doesn't exist, only write when the parent dir exists. A
|
||||
// fresh system where nvim was never installed should be a no-op.
|
||||
if _, err := os.Stat(chadrcPath); err != nil {
|
||||
if _, err := os.Stat(cfg); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
tmplBytes, err := assets.ReadFile("assets/chadrc.lua.tmpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmpl, err := template.New("chadrc").Parse(string(tmplBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if err := tmpl.Execute(&buf, struct{ NvChadTheme string }{NvChadTheme: nvChadThemeName}); err != nil {
|
||||
return err
|
||||
}
|
||||
return platform.WriteUserFile(chadrcPath, buf.Bytes(), 0o644)
|
||||
}
|
||||
|
||||
func (m Module) renderChadrc() ([]byte, error) {
|
||||
tmplBytes, err := assets.ReadFile("assets/chadrc.lua.tmpl")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user