-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
45 lines (35 loc) · 948 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"dlasky/away-bar/internal"
"dlasky/away-bar/modules"
"fmt"
"log"
"path"
"github.com/gotk3/gotk3/gtk"
"github.com/hashicorp/hcl/v2/hclsimple"
)
func getConfig() (*Config, error) {
//TODO: allow an explicit pathing here as well via flags
user := internal.GetEnv("USER", "")
home := internal.GetEnv("XDG_HOME", "/home/"+user)
cfg := internal.GetEnv("XDG_CONFIG", ".config")
conf := path.Join(home, cfg, "/awaybar/config.hcl")
fmt.Printf("conf path: %v", conf)
var config Config
err := hclsimple.DecodeFile(conf, nil, &config)
if err != nil {
log.Fatalf("Failed to load configuration: %s", err)
}
log.Printf("Configuration is %#v", config)
return &config, err
}
func setupFromConfig(bar *gtk.Box, config *Config) error {
if config.Module.Clock != nil {
w, err := modules.InitClockWithConfig(*config.Module.Clock)
if err != nil {
fmt.Println(err)
}
bar.Add(w.ToWidget())
}
return nil
}