diff --git a/config.go b/config.go index c733639..560300e 100644 --- a/config.go +++ b/config.go @@ -27,12 +27,13 @@ type Window struct { } type Config struct { - Session string `yaml:"session"` - Root string `yaml:"root"` - BeforeStart []string `yaml:"before_start"` - Stop []string `yaml:"stop"` - Windows []Window `yaml:"windows"` - RebalanceWindowsThreshold int `yaml:"rebalance_panes_after"` + Session string `yaml:"session"` + Env map[string]string `yaml:"env"` + Root string `yaml:"root"` + BeforeStart []string `yaml:"before_start"` + Stop []string `yaml:"stop"` + Windows []Window `yaml:"windows"` + RebalanceWindowsThreshold int `yaml:"rebalance_panes_after"` } func EditConfig(path string) error { diff --git a/smug.go b/smug.go index 2de127c..afa7ab8 100644 --- a/smug.go +++ b/smug.go @@ -55,6 +55,17 @@ func (smug Smug) execShellCommands(commands []string, path string) error { return nil } +func (smug Smug) setEnvVariables(target string, env map[string]string) error { + for key, value := range env { + _, err := smug.tmux.SetEnv(target, key, value) + if err != nil { + return err + } + } + + return nil +} + func (smug Smug) switchOrAttach(target string, attach bool, insideTmuxSession bool) error { if insideTmuxSession && attach { return smug.tmux.SwitchClient(target) @@ -110,6 +121,11 @@ func (smug Smug) Start(config Config, options Options, context Context) error { if err != nil { return err } + + err = smug.setEnvVariables(config.Session, config.Env) + if err != nil { + return err + } } else if len(windows) == 0 { return smug.switchOrAttach(sessionName, attach, context.InsideTmuxSession) } diff --git a/tmux.go b/tmux.go index 449c8c1..e00750f 100644 --- a/tmux.go +++ b/tmux.go @@ -105,6 +105,11 @@ func (tmux Tmux) SelectLayout(target string, layoutType string) (string, error) return tmux.commander.Exec(cmd) } +func (tmux Tmux) SetEnv(target string, key string, value string) (string, error) { + cmd := exec.Command("tmux", "setenv", "-t", target, key, value) + return tmux.commander.Exec(cmd) +} + func (tmux Tmux) StopSession(target string) (string, error) { cmd := exec.Command("tmux", "kill-session", "-t", target) return tmux.commander.Exec(cmd)