//go:build mage package main import ( "fmt" "os" "path/filepath" "codeflow.dananglin.me.uk/linux-home/manager/magefiles/internal/config" "codeflow.dananglin.me.uk/linux-home/manager/magefiles/internal/utilities" ) // BashProfile manages the user's Bash Profile using their configuration and the Bash Profile template. func BashProfile() error { const ( bashProfileTemplateFile string = "bash/profile.gotmpl" managedBashProfile string = "managed/bash_profile" defaultFilename string = ".bash_profile" ) homeDirectory, err := os.UserHomeDir() if err != nil { return fmt.Errorf("unable to get the user's home configuration directory: %w", err) } cfg, err := config.NewConfig() if err != nil { return fmt.Errorf("unable to load the configuration: %w", err) } if !cfg.BashProfile.Manage { return nil } if err := utilities.RenderTemplate(cfg, bashProfileTemplateFile, managedBashProfile); err != nil { return fmt.Errorf("unable to generate the Bash Profile: %w", err) } filename := cfg.BashProfile.Filename if filename == "" { filename = defaultFilename } symlinkPath := filepath.Join(homeDirectory, filename) if err := utilities.EnsureSymlink(managedBashProfile, symlinkPath); err != nil { return err } return nil }