diff --git a/README.md b/README.md index 9549c89..69f9a7f 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,12 @@ SlurmCommander does not require any special privileges to be installed, see inst ### Site administrators Instructions are same as for the regular users, with one minor perk. -Place the [config file](./cmd/scom/scom.conf) in `/etc/scom/scom.conf` to be used as global configuration source for all scom instances on that machine. +Place the [config file](./cmd/scom/scom.conf) in one of the following locations to be used as global configuration source for all scom instances on that machine. + +1. /etc/scom/scom.conf +2. Any location, providing users with the environment variable `SCOM_CONF` containing path to config. file +3. Users $XDG_CONFIG_HOME/scom/scom.conf + __NOTE__: Users can still override global configuration options by changing config stanzas in their local `$HOME/scom/scom.conf` diff --git a/internal/config/config.go b/internal/config/config.go index 1307fbc..d2d9af2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -44,6 +44,22 @@ func (cc *ConfigContainer) GetConfig() error { cfgPaths = []string{defaults.SiteConfFile, home + "/" + defaults.AppName + "/" + defaults.ConfFileName} } + // SCOM_CONF content, if exists + if scomConf, exists := os.LookupEnv(defaults.EnvConfVarName); exists && scomConf != "" { + // SCOM_CONF set + cfgPaths = append(cfgPaths, scomConf) + } + + // $XDG_CONFIG_HOME/scom/scom.conf + if xdgConfHome, exists := os.LookupEnv("XDG_CONFIG_HOME"); exists && xdgConfHome != "" { + // XDG_CONFIG_HOME set + cfgPaths = append(cfgPaths, xdgConfHome+"/"+defaults.AppName+"/"+defaults.ConfFileName) + } else { + // XDG_CONFIG_HOME unset or empty + // If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. + cfgPaths = append(cfgPaths, home+"/.config/"+defaults.AppName+"/"+defaults.ConfFileName) + } + for _, v := range cfgPaths { log.Printf("Trying conf file: %s\n", v) f, err := os.ReadFile(v) diff --git a/internal/defaults/defaults.go b/internal/defaults/defaults.go index 7762970..4fc6230 100644 --- a/internal/defaults/defaults.go +++ b/internal/defaults/defaults.go @@ -5,9 +5,10 @@ const ( AppName = "scom" - ConfFileName = "scom.conf" - SiteConfDir = "/etc/" + AppName + "/" - SiteConfFile = SiteConfDir + ConfFileName + EnvConfVarName = "SCOM_CONF" + ConfFileName = "scom.conf" + SiteConfDir = "/etc/" + AppName + "/" + SiteConfFile = SiteConfDir + ConfFileName TemplatesDir = SiteConfDir + "templates" TemplatesSuffix = ".sbatch" diff --git a/internal/model/view.go b/internal/model/view.go index 61d42ce..73722ca 100644 --- a/internal/model/view.go +++ b/internal/model/view.go @@ -4,10 +4,10 @@ import ( "fmt" "strings" - "github.com/charmbracelet/lipgloss" "github.com/CLIP-HPC/SlurmCommander/internal/keybindings" "github.com/CLIP-HPC/SlurmCommander/internal/styles" "github.com/CLIP-HPC/SlurmCommander/internal/version" + "github.com/charmbracelet/lipgloss" ) // genTabs() generates top tabs @@ -50,7 +50,8 @@ Petar Jager CLIP-HPC @VBC Contributors: -Seren,Ümit @VBC +Seren Ümit +Kilian Cavalotti ` return s