Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Refactor config directory into global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Dec 4, 2018
1 parent a2d80c8 commit db57b40
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
percpuLoad = false
widgetCount = 6
fahrenheit = false
configDir = getConfigDir()

cpu *w.CPU
mem *w.Mem
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit db57b40

Please sign in to comment.