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

feat: cli, instance home and actual writing

Changed files
+131 -24
cli
config
core
minecraft
+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 + }
+2
config.toml
··· 1 + directory = "instance" 2 + 1 3 [options] 2 4 main_hand = "left" 3 5 ao = false
+7 -6
config/config.go
··· 9 9 10 10 type ( 11 11 Config struct { 12 - Options minecraft.Options `toml:options` 13 - Fabric Loader `toml:fabric` 14 - 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"` 15 16 } 16 17 17 18 Loader struct { 18 - Mods map[string]string `toml:mods` 19 + Mods map[string]string `toml:"mods"` 19 20 } 20 21 ) 21 22 22 - func LoadConfig() (Config) { 23 + func LoadConfig() Config { 23 24 file, _ := os.ReadFile("config.toml") 24 - var config Config 25 + var config Config 25 26 toml.Decode(string(file), &config) 26 27 return config 27 28 }
+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 + }
+1
go.mod
··· 17 17 github.com/mattn/go-runewidth v0.0.16 // indirect 18 18 github.com/muesli/termenv v0.16.0 // indirect 19 19 github.com/rivo/uniseg v0.4.7 // indirect 20 + github.com/urfave/cli/v3 v3.6.1 // indirect 20 21 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect 21 22 golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect 22 23 golang.org/x/sys v0.30.0 // indirect
+23
go.sum
··· 14 14 github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= 15 15 github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= 16 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= 17 21 github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= 18 22 github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= 19 23 github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= ··· 24 28 github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 25 29 github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= 26 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= 27 32 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 28 33 github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= 29 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= 30 49 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= 31 50 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= 32 51 golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= ··· 34 53 golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 35 54 golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 36 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 -9
main.go
··· 1 1 package main 2 2 3 - import ( 4 - "potassium.sh/dot-mining/config" 5 - "potassium.sh/dot-mining/minecraft" 6 - ) 7 - 8 - 3 + import "potassium.sh/dot-mining/cli" 9 4 10 5 func main() { 11 - config := config.LoadConfig() 12 - minecraft.WriteOptions(config.Options, "") 13 - } 6 + cli.Run() 7 + }
+20 -9
minecraft/options.go
··· 1 1 package minecraft 2 2 3 3 import ( 4 - "fmt" 4 + "os" 5 + "path/filepath" 5 6 "reflect" 6 7 "strconv" 7 - ) 8 8 9 + "github.com/charmbracelet/log" 10 + ) 9 11 10 12 type ( 11 13 Options struct { 12 14 MainHand string `toml:"main_hand" txt:"mainHand"` 13 - AO bool `toml:"smooth_lighting" txt:"ao"` 14 - Fov int `toml:"fov" txt:"fov"` 15 + AO bool `toml:"smooth_lighting" txt:"ao"` 16 + Fov int `toml:"fov" txt:"fov"` 15 17 } 16 18 ) 17 19 ··· 20 22 21 23 reflectOptions := reflect.TypeOf(options) 22 24 23 - for i := 0; i < reflectOptions.NumField(); i++ { 25 + for i := range reflectOptions.NumField() { 24 26 field := reflectOptions.Field(i) 25 27 26 28 txt := field.Tag.Get("txt") 27 - if (txt == "") { 29 + if txt == "" { 28 30 txt = field.Name 29 31 } 30 32 value := reflect.ValueOf(options).Field(i) 31 - 32 - switch field.Type.Kind(){ 33 + 34 + switch field.Type.Kind() { 33 35 case reflect.String: 34 36 plainText += txt + ":" + "\"" + value.String() + "\"\n" 35 37 case reflect.Int: ··· 38 40 plainText += txt + ":" + strconv.FormatBool(value.Bool()) + "\n" 39 41 } 40 42 } 41 - fmt.Print(plainText) 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 + } 42 53 }