aboutsummaryrefslogtreecommitdiff
path: root/rui.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-09-17 16:32:41 -0700
committerFuwn <[email protected]>2024-09-17 16:32:41 -0700
commit2d47b7db708357393d0ea618ce423b4be73857f8 (patch)
tree6194f56995872537630bd510a6248582e2bed033 /rui.go
parentcfe895fee4a62595afb52c748a6e3a8a66c0e334 (diff)
downloadrui-2d47b7db708357393d0ea618ce423b4be73857f8.tar.xz
rui-2d47b7db708357393d0ea618ce423b4be73857f8.zip
feat(rui): top-level configuration initialisation
Diffstat (limited to 'rui.go')
-rw-r--r--rui.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/rui.go b/rui.go
index 3b0e9cd..6495408 100644
--- a/rui.go
+++ b/rui.go
@@ -10,6 +10,30 @@ import (
"github.com/urfave/cli/v2"
)
+type Configuration struct {
+ Notify bool `json:"notify"`
+}
+
+var configuration Configuration
+
+func init() {
+ configurationPath := os.Getenv("RUI_CONFIG")
+
+ if configurationPath == "" {
+ configurationPath = os.Getenv("XDG_CONFIG_HOME") + "/rui/config.json"
+ }
+
+ content, err := os.ReadFile(configurationPath)
+
+ if err != nil {
+ return
+ }
+
+ if err := json.Unmarshal(content, &configuration); err != nil {
+ return
+ }
+}
+
func main() {
(&cli.App{
Name: "rui",
@@ -206,23 +230,7 @@ func Command(name string, args ...string) error {
return cmd.Run()
}
-type Configuration struct {
- Notify bool `json:"notify"`
-}
-
func Notify(message string) error {
- content, err := os.ReadFile(os.Getenv("XDG_CONFIG_HOME"))
-
- if err != nil {
- return err
- }
-
- var configuration Configuration
-
- if err := json.Unmarshal(content, &configuration); err != nil {
- return err
- }
-
notifySend, err := exec.LookPath("notify-send")
if err != nil {