From 638d67c0e4b3ff5be76dcc2af0690201a12fb281 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 28 Jun 2018 19:37:19 +0300 Subject: [PATCH] read system-wide configuration at '/etc/lfrc' --- client.go | 6 ++++-- os.go | 9 ++++++--- os_windows.go | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 7d399245..50bdf6fa 100644 --- a/client.go +++ b/client.go @@ -32,8 +32,10 @@ func run() { app := newApp() - if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) { - app.readFile(gConfigPath) + for _, path := range gConfigPaths { + if _, err := os.Stat(path); !os.IsNotExist(err) { + app.readFile(path) + } } app.loop() diff --git a/os.go b/os.go index 056c4ed1..273d6aaf 100644 --- a/os.go +++ b/os.go @@ -25,8 +25,8 @@ var ( ) var ( - gUser *user.User - gConfigPath string + gUser *user.User + gConfigPaths []string ) func init() { @@ -41,7 +41,10 @@ func init() { config = filepath.Join(gUser.HomeDir, ".config") } - gConfigPath = filepath.Join(config, "lf", "lfrc") + gConfigPaths = []string{ + filepath.Join("/etc", "lfrc"), + filepath.Join(config, "lf", "lfrc"), + } gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username)) } diff --git a/os_windows.go b/os_windows.go index 7382775b..b54975f7 100644 --- a/os_windows.go +++ b/os_windows.go @@ -16,8 +16,8 @@ var ( ) var ( - gUser *user.User - gConfigPath string + gUser *user.User + gConfigPaths []string ) func init() { @@ -30,7 +30,7 @@ func init() { // remove domain prefix gUser.Username = strings.Split(gUser.Username, `\`)[1] - gConfigPath = filepath.Join(gUser.HomeDir, "AppData", "Local", "lf", "lfrc") + gConfigPaths = []string{filepath.Join(gUser.HomeDir, "AppData", "Local", "lf", "lfrc")} } func pauseCommand() *exec.Cmd {