From 262f4ac873140f55d4484b6b3d9261040bde319b Mon Sep 17 00:00:00 2001 From: Pavel Vorobyov Date: Tue, 24 Sep 2019 16:06:20 +0300 Subject: [PATCH] environ configuration --- cli/cli.go | 7 +++++++ config/config.go | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/cli/cli.go b/cli/cli.go index 440a3c2..51f5bba 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -94,6 +94,7 @@ func New(cfg *config.XCConfig, backend store.Backend) (*Cli, error) { cli.stopped = false cli.aliases = make(map[string]*alias) cli.setupCmdHandlers() + setEnvironment(cfg.LocalEnvironment) cfg.Readline.AutoComplete = cli.completer cli.rl, err = readline.NewEx(cfg.Readline) @@ -267,6 +268,12 @@ func (c *Cli) CmdLoop() { } } +func setEnvironment(environ map[string]string) { + for key, value := range environ { + os.Setenv(key, value) + } +} + func (c *Cli) confirm(msg string) bool { reader := bufio.NewReader(os.Stdin) for { diff --git a/config/config.go b/config/config.go index 14dd3e8..f40ca5e 100644 --- a/config/config.go +++ b/config/config.go @@ -87,6 +87,7 @@ type XCConfig struct { SuInterpreter string Interpreter string PasswordManagerPath string + LocalEnvironment map[string]string } const ( @@ -155,6 +156,7 @@ func read(filename string, secondPass bool) (*XCConfig, error) { cfg := new(XCConfig) cfg.Readline = defaultReadlineConfig cfg.BackendCfg = &BackendConfig{Type: BTIni, Options: make(map[string]string)} + cfg.LocalEnvironment = make(map[string]string) hf, err := props.GetString("main.history_file") if err != nil { @@ -316,5 +318,13 @@ func read(filename string, secondPass bool) (*XCConfig, error) { cfg.PasswordManagerPath, _ = props.GetString("passmgr.path") + envkeys, err := props.Subkeys("environ") + if err == nil { + for _, key := range envkeys { + value, _ := props.GetString(fmt.Sprintf("environ.%s", key)) + cfg.LocalEnvironment[key] = expandPath(value) + } + } + return cfg, nil }