diff options
| author | Fuwn <[email protected]> | 2024-09-17 16:52:35 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-09-17 16:52:35 -0700 |
| commit | 2db46a96a8499d0102d386f23e972891c4443426 (patch) | |
| tree | a42eb9097d62ac2231dd6454b81cde46c522b843 | |
| parent | 51d86c7be9756674252b39412ca3b9cb1227b406 (diff) | |
| download | rui-2db46a96a8499d0102d386f23e972891c4443426.tar.xz rui-2db46a96a8499d0102d386f23e972891c4443426.zip | |
feat(rui): editor and flake file configuration
| -rw-r--r-- | rui.go | 48 |
1 files changed, 38 insertions, 10 deletions
@@ -11,7 +11,9 @@ import ( ) type Configuration struct { - Notify bool `json:"notify"` + Notify bool `json:"notify"` + Editor string `json:"editor"` + Flake string `json:"flake"` } var configuration Configuration @@ -110,8 +112,14 @@ func main() { user = os.Getenv("USER") } + flake := configuration.Flake + + if flake == "" { + flake = os.Getenv("FLAKE") + } + err = Command("home-manager", append([]string{"switch", - "--flake", fmt.Sprintf("%s#%s", os.Getenv("FLAKE"), user)}, + "--flake", fmt.Sprintf("%s#%s", flake, user)}, extraArgs...)...) } @@ -134,7 +142,12 @@ func main() { }, }, Action: func(c *cli.Context) error { - target := os.Getenv("FLAKE") + flake := configuration.Flake + + if flake == "" { + flake = os.Getenv("FLAKE") + } + extraArgs := []string{} if c.Bool("impure") { @@ -142,11 +155,11 @@ func main() { } if user := c.String("user"); user != "" { - target = fmt.Sprintf("%s#%s", target, user) + flake = fmt.Sprintf("%s#%s", flake, user) } return Command("home-manager", append([]string{"news", "--flake", - target}, extraArgs...)...) + flake}, extraArgs...)...) }, }, }, @@ -191,8 +204,14 @@ func main() { } } + flake := configuration.Flake + + if flake == "" { + flake = os.Getenv("FLAKE") + } + err = Command(escalator, "nixos-rebuild", "switch", "--flake", - fmt.Sprintf("%s#%s", os.Getenv("FLAKE"), hostname)) + fmt.Sprintf("%s#%s", flake, hostname)) } if err != nil { @@ -207,13 +226,22 @@ func main() { { Name: "edit", Action: func(c *cli.Context) error { - editor, err := os.LookupEnv("FLAKE_EDITOR") + var found bool + + editor := configuration.Editor + flake := configuration.Flake + + if flake == "" { + flake = os.Getenv("FLAKE") + } - if err { - return Command(editor, os.Getenv("FLAKE")) + if editor == "" { + if editor, found = os.LookupEnv("FLAKE_EDITOR"); !found { + editor = os.Getenv("EDITOR") + } } - return Command(os.Getenv("EDITOR"), os.Getenv("FLAKE")) + return Command(editor, flake) }, }, }, |