Store your Minecraft configs with your other dotfiles, and load it automatically.

Compare changes

Choose any two refs to compare.

Changed files
+313 -18
cli
config
core
minecraft
modrinth
+1
.gitignore
··· 1 + instance
+27
cli/cli.go
··· 1 + package cli 2 + 3 + import ( 4 + "context" 5 + "os" 6 + 7 + "github.com/charmbracelet/log" 8 + "github.com/urfave/cli/v3" 9 + ) 10 + 11 + var rootCommand = cli.Command{ 12 + Name: "dmc", // TODO? short name? 13 + Authors: []any{ 14 + "banana", "rad", 15 + }, 16 + Copyright: "(c) 2025 potassium.sh", 17 + Description: "Store your Minecraft configs with your other dotfiles, and load them automatically.", 18 + Commands: []*cli.Command{ 19 + syncCommand, 20 + }, 21 + } 22 + 23 + func Run() { 24 + if err := rootCommand.Run(context.Background(), os.Args); err != nil { 25 + log.Fatal(err) 26 + } 27 + }
+23
cli/sync.go
··· 1 + package cli 2 + 3 + import ( 4 + "context" 5 + 6 + "github.com/urfave/cli/v3" 7 + "potassium.sh/dot-mining/core" 8 + "potassium.sh/dot-mining/minecraft" 9 + ) 10 + 11 + var syncCommand = &cli.Command{ 12 + Name: "sync", 13 + Description: "Synchronise your mods and configs.", 14 + Action: func(ctx context.Context, cmd *cli.Command) error { 15 + return sync() 16 + }, 17 + } 18 + 19 + func sync() error { 20 + core.InitConfig() 21 + minecraft.WriteOptions(core.Config.Options, core.MinecraftFile("options.txt")) 22 + return nil 23 + }
+9 -5
config/config.go
··· 4 4 "os" 5 5 6 6 "github.com/BurntSushi/toml" 7 + "potassium.sh/dot-mining/minecraft" 7 8 ) 8 9 9 10 type ( 10 11 Config struct { 11 - Fabric Loader `toml:fabric` 12 - Mods map[string]string `toml:mods` 12 + Options minecraft.Options `toml:"options"` 13 + Fabric Loader `toml:"fabric"` 14 + Mods map[string]string `toml:"mods"` 15 + Directory string `toml:"directory"` 13 16 } 17 + 14 18 Loader struct { 15 - Mods map[string]string `toml:mods` 19 + Mods map[string]string `toml:"mods"` 16 20 } 17 21 ) 18 22 19 - func LoadConfig() (Config) { 23 + func LoadConfig() Config { 20 24 file, _ := os.ReadFile("config.toml") 21 - var config Config 25 + var config Config 22 26 toml.Decode(string(file), &config) 23 27 return config 24 28 }
+7
config.toml
··· 1 + directory = "instance" 2 + 3 + [options] 4 + main_hand = "left" 5 + ao = false 6 + fov = 1 7 + 1 8 [mods] 2 9 sodium = "AANobbMI" 3 10 fabric-api = "P7dR8mSH"
+24
core/core.go
··· 1 + package core 2 + 3 + import ( 4 + "os" 5 + "path/filepath" 6 + 7 + "potassium.sh/dot-mining/config" 8 + ) 9 + 10 + var ( 11 + Config config.Config 12 + ) 13 + 14 + func InitConfig() { 15 + Config = config.LoadConfig() 16 + } 17 + 18 + func MinecraftFile(path ...string) string { 19 + cwd, _ := os.Getwd() 20 + args := []string{cwd, Config.Directory} 21 + args = append(args, path...) 22 + 23 + return filepath.Join(args...) 24 + }
+20 -1
go.mod
··· 2 2 3 3 go 1.25.4 4 4 5 - require github.com/BurntSushi/toml v1.5.0 // indirect 5 + require ( 6 + github.com/BurntSushi/toml v1.5.0 // indirect 7 + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect 8 + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect 9 + github.com/charmbracelet/lipgloss v1.1.0 // indirect 10 + github.com/charmbracelet/log v0.4.2 // indirect 11 + github.com/charmbracelet/x/ansi v0.8.0 // indirect 12 + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect 13 + github.com/charmbracelet/x/term v0.2.1 // indirect 14 + github.com/go-logfmt/logfmt v0.6.0 // indirect 15 + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 16 + github.com/mattn/go-isatty v0.0.20 // indirect 17 + github.com/mattn/go-runewidth v0.0.16 // indirect 18 + github.com/muesli/termenv v0.16.0 // indirect 19 + github.com/rivo/uniseg v0.4.7 // indirect 20 + github.com/urfave/cli/v3 v3.6.1 // indirect 21 + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 22 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect 23 + golang.org/x/sys v0.30.0 // indirect 24 + )
+57
go.sum
··· 1 1 github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= 2 2 github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= 3 + github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= 4 + github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= 5 + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= 6 + github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= 7 + github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= 8 + github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= 9 + github.com/charmbracelet/log v0.4.2 h1:hYt8Qj6a8yLnvR+h7MwsJv/XvmBJXiueUcI3cIxsyig= 10 + github.com/charmbracelet/log v0.4.2/go.mod h1:qifHGX/tc7eluv2R6pWIpyHDDrrb/AG71Pf2ysQu5nw= 11 + github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2llXn7xE= 12 + github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q= 13 + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0GVL4jeHEwG5YOXDmi86oYw2yuYUGqz6a8sLwg0X8= 14 + github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= 15 + github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= 16 + github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= 17 + github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= 18 + github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= 19 + github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 20 + github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 21 + github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= 22 + github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= 23 + github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= 24 + github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 25 + github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= 26 + github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 27 + github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= 28 + github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 29 + github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= 30 + github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= 31 + github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 32 + github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 33 + github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= 34 + github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 35 + github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 36 + github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 37 + github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 38 + github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 39 + github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 40 + github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 41 + github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 42 + github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 43 + github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 44 + github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 45 + github.com/urfave/cli v1.22.17 h1:SYzXoiPfQjHBbkYxbew5prZHS1TOLT3ierW8SYLqtVQ= 46 + github.com/urfave/cli v1.22.17/go.mod h1:b0ht0aqgH/6pBYzzxURyrM4xXNgsoT/n2ZzwQiEhNVo= 47 + github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo= 48 + github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= 49 + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= 50 + github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= 51 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= 52 + golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= 53 + golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 54 + golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 55 + golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 56 + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 57 + gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 58 + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 59 + gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+3 -12
main.go
··· 1 1 package main 2 2 3 - import ( 4 - "fmt" 5 - 6 - "potassium.sh/dot-mining/config" 7 - ) 8 - 9 - 3 + import "potassium.sh/dot-mining/cli" 10 4 11 5 func main() { 12 - config := config.LoadConfig() 13 - for modName, modID := range config.Fabric.Mods { 14 - fmt.Printf("- %s: %s\n", modName, modID) 15 - } 16 - } 6 + cli.Run() 7 + }
+53
minecraft/options.go
··· 1 + package minecraft 2 + 3 + import ( 4 + "os" 5 + "path/filepath" 6 + "reflect" 7 + "strconv" 8 + 9 + "github.com/charmbracelet/log" 10 + ) 11 + 12 + type ( 13 + Options struct { 14 + MainHand string `toml:"main_hand" txt:"mainHand"` 15 + AO bool `toml:"smooth_lighting" txt:"ao"` 16 + Fov int `toml:"fov" txt:"fov"` 17 + } 18 + ) 19 + 20 + func WriteOptions(options Options, path string) { 21 + plainText := "version:9999\n" 22 + 23 + reflectOptions := reflect.TypeOf(options) 24 + 25 + for i := range reflectOptions.NumField() { 26 + field := reflectOptions.Field(i) 27 + 28 + txt := field.Tag.Get("txt") 29 + if txt == "" { 30 + txt = field.Name 31 + } 32 + value := reflect.ValueOf(options).Field(i) 33 + 34 + switch field.Type.Kind() { 35 + case reflect.String: 36 + plainText += txt + ":" + "\"" + value.String() + "\"\n" 37 + case reflect.Int: 38 + plainText += txt + ":" + strconv.Itoa(int(value.Int())) + "\n" 39 + case reflect.Bool: 40 + plainText += txt + ":" + strconv.FormatBool(value.Bool()) + "\n" 41 + } 42 + } 43 + 44 + dir := filepath.Dir(path) 45 + if err := os.MkdirAll(dir, 0755); err != nil { 46 + log.Fatal("Failed creating instance directory ", dir, ": ", err) 47 + return 48 + } 49 + 50 + if err := os.WriteFile(path, []byte(plainText), 0755); err != nil { 51 + log.Fatal("Failed writing options", "error", err) 52 + } 53 + }
+19
modrinth/api.go
··· 1 + package modrinth 2 + 3 + import ( 4 + "encoding/json" 5 + "io" 6 + "net/http" 7 + ) 8 + 9 + func fetchProject(name string, id string) *Project { 10 + var project *Project 11 + url := "https://api.modrinth.com/v2/project/" + id 12 + res, _ := http.Get(url) 13 + if (res.StatusCode == 404) { 14 + return project 15 + } 16 + body, _ := io.ReadAll(res.Body) 17 + json.Unmarshal(body, &project) 18 + return project 19 + }
+28
modrinth/mods.go
··· 1 + package modrinth 2 + 3 + import ( 4 + "strconv" 5 + 6 + "github.com/charmbracelet/log" 7 + ) 8 + 9 + func LoadMods(mods map[string]string) []Project { 10 + var modProjects []Project 11 + log.Info("Loading " + strconv.Itoa(len(mods)) + " mods") 12 + for name, id := range mods { 13 + project := fetchProject(name, id) 14 + if (project == nil) { 15 + log.Warn("Unable to find mod project, skipping...", "name", name, "id", id) 16 + continue 17 + } 18 + if (project.ProjectType != "mod") { 19 + log.Warn("Project is not a mod, skipping...", "name", name, "id", id) 20 + continue 21 + } 22 + log.Info("Loaded mod project", "name", name, "id", id) 23 + modProjects = append(modProjects, *project) 24 + } 25 + return modProjects 26 + } 27 + 28 +
+42
modrinth/types.go
··· 1 + package modrinth 2 + 3 + type ( 4 + Project struct { 5 + Slug string 6 + Id string 7 + Title string 8 + Description string 9 + ClientSide string `json:"client_side"` 10 + ServerSide string `json:"server_side"` 11 + Status string 12 + RequestedStatus string `json:"requested_status"` 13 + ProjectType string `json:"project_type"` 14 + Versions []string 15 + GameVersions []string `json:"game_versions"` 16 + Loaders []string 17 + } 18 + 19 + Version struct { 20 + ProjectId string `json:"project_id"` 21 + Name string 22 + Id string 23 + VersionNumber string `json:"version_number"` 24 + GameVersions []string `json:"game_versions"` 25 + VersionType string `json:"version_type"` 26 + Loaders []string 27 + Files []File 28 + } 29 + 30 + File struct { 31 + Hashes Hash 32 + Url string 33 + Filename string 34 + Primary bool 35 + Size int 36 + } 37 + 38 + Hash struct { 39 + Sha512 string 40 + Sha1 string 41 + } 42 + )