diff --git a/main.go b/main.go index 79eef60..aeea385 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ import ( "github.com/cjbassi/gotop/colorschemes" "github.com/cjbassi/gotop/src/logging" + "github.com/cjbassi/gotop/src/utils" w "github.com/cjbassi/gotop/src/widgets" ) @@ -29,8 +30,8 @@ const ( ) var ( - configDir = getConfigDir(appName) - logDir = getLogDir(appName) + configDir = utils.GetConfigDir(appName) + logDir = utils.GetLogDir(appName) logPath = filepath.Join(logDir, "errors.log") stderrLogger = log.New(os.Stderr, "", 0) @@ -59,26 +60,6 @@ var ( bar *w.StatusBar ) -func getConfigDir(name string) string { - var basedir string - if env := os.Getenv("XDG_CONFIG_HOME"); env != "" { - basedir = env - } else { - basedir = filepath.Join(os.Getenv("HOME"), ".config") - } - return filepath.Join(basedir, name) -} - -func getLogDir(name string) string { - var basedir string - if env := os.Getenv("XDG_STATE_HOME"); env != "" { - basedir = env - } else { - basedir = filepath.Join(os.Getenv("HOME"), ".local", "state") - } - return filepath.Join(basedir, name) -} - func parseArgs() error { usage := ` Usage: gotop [options] diff --git a/src/utils/utils.go b/src/utils/bytes.go similarity index 92% rename from src/utils/utils.go rename to src/utils/bytes.go index 7a8b5bd..b06cf8c 100644 --- a/src/utils/utils.go +++ b/src/utils/bytes.go @@ -45,10 +45,3 @@ func ConvertBytes(b uint64) (float64, string) { return BytesToTB(b), "TB" } } - -func MaxInt(a, b int) int { - if a > b { - return a - } - return b -} diff --git a/src/utils/math.go b/src/utils/math.go new file mode 100644 index 0000000..b710ee6 --- /dev/null +++ b/src/utils/math.go @@ -0,0 +1,8 @@ +package utils + +func MaxInt(a, b int) int { + if a > b { + return a + } + return b +} diff --git a/src/utils/xdg.go b/src/utils/xdg.go new file mode 100644 index 0000000..8489042 --- /dev/null +++ b/src/utils/xdg.go @@ -0,0 +1,26 @@ +package utils + +import ( + "os" + "path/filepath" +) + +func GetConfigDir(name string) string { + var basedir string + if env := os.Getenv("XDG_CONFIG_HOME"); env != "" { + basedir = env + } else { + basedir = filepath.Join(os.Getenv("HOME"), ".config") + } + return filepath.Join(basedir, name) +} + +func GetLogDir(name string) string { + var basedir string + if env := os.Getenv("XDG_STATE_HOME"); env != "" { + basedir = env + } else { + basedir = filepath.Join(os.Getenv("HOME"), ".local", "state") + } + return filepath.Join(basedir, name) +}