Allow to set env variables per session (#69)

master
Ivan 3 years ago committed by GitHub
parent 0fee0268ba
commit 6b6960cb24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 {

@ -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)
}

@ -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)

Loading…
Cancel
Save