From 73fed621b9db5488cc6de5d035e6c090c43a7c50 Mon Sep 17 00:00:00 2001 From: windwp Date: Thu, 5 May 2022 09:22:57 +0700 Subject: [PATCH] feat: allow use system enviroment variables --- config.go | 4 ++++ config_test.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 560300e..5fa45b9 100644 --- a/config.go +++ b/config.go @@ -67,6 +67,10 @@ func ParseConfig(data string, settings map[string]string) (Config, error) { return val } + if val, ok := os.LookupEnv(v); ok { + return val + } + return v }) diff --git a/config_test.go b/config_test.go index af5af61..2af7e5f 100644 --- a/config_test.go +++ b/config_test.go @@ -1,6 +1,7 @@ package main import ( + "os" "reflect" "testing" ) @@ -15,6 +16,7 @@ windows: panes: - commands: - echo 2 + - echo ${HOME} type: horizontal` config, err := ParseConfig(yaml, map[string]string{ @@ -33,7 +35,7 @@ windows: Panes: []Pane{ { Type: "horizontal", - Commands: []string{"echo 2"}, + Commands: []string{"echo 2", "echo " + os.Getenv("HOME")}, }, }, },