diff options
author | Caleb Bassi <calebjbassi@gmail.com> | 2018-12-04 15:22:41 -0800 |
---|---|---|
committer | Caleb Bassi <calebjbassi@gmail.com> | 2018-12-04 15:22:41 -0800 |
commit | db57b4065905578e56f1cf6706f08160b2e903d6 (patch) | |
tree | 0db88b6bd33e4b581e2b02c48714bad278cae26a | |
parent | a2d80c8282de0568b6538a06ad8af2e6316d098a (diff) |
Refactor config directory into global variable
-rw-r--r-- | main.go | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -31,6 +31,7 @@ var ( percpuLoad = false widgetCount = 6 fahrenheit = false + configDir = getConfigDir() cpu *w.CPU mem *w.Mem @@ -100,15 +101,18 @@ func handleColorscheme(cs string) { } } -// getCustomColorscheme tries to read a custom json colorscheme from -// {$XDG_CONFIG_HOME,~/.config}/gotop/{name}.json -func getCustomColorscheme(name string) colorschemes.Colorscheme { - xdg := os.Getenv("XDG_CONFIG_HOME") - if xdg == "" { - xdg = os.ExpandEnv("$HOME") + "/.config" +func getConfigDir() string { + globalConfigDir := os.Getenv("XDG_CONFIG_HOME") + if globalConfigDir == "" { + globalConfigDir = os.ExpandEnv("$HOME") + "/.config" } - file := xdg + "/gotop/" + name + ".json" - dat, err := ioutil.ReadFile(file) + return globalConfigDir + "/gotop" +} + +// getCustomColorscheme tries to read a custom json colorscheme from {configDir}/{name}.json +func getCustomColorscheme(name string) colorschemes.Colorscheme { + filePath := configDir + "/" + name + ".json" + dat, err := ioutil.ReadFile(filePath) if err != nil { fmt.Fprintf(os.Stderr, "error: colorscheme not recognized\n") os.Exit(1) |