diff --git a/pkg/commands/container.go b/pkg/commands/container.go index 56aaa1e..b45feef 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -100,7 +100,7 @@ func (c *Container) Attach() (*exec.Cmd, error) { c.Log.Warn(fmt.Sprintf("attaching to container %s", c.Name)) // TODO: use SDK - cmd := c.OSCommand.PrepareSubProcess("docker", "attach", "--sig-proxy=false", c.ID) + cmd := c.OSCommand.NewCmd("docker", "attach", "--sig-proxy=false", c.ID) return cmd, nil } diff --git a/pkg/commands/os.go b/pkg/commands/os.go index a94acc3..259f782 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -87,7 +87,7 @@ func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error { // ExecutableFromString takes a string like `docker ps -a` and returns an executable command for it func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd { splitCmd := str.ToArgv(commandStr) - return c.command(splitCmd[0], splitCmd[1:]...) + return c.NewCmd(splitCmd[0], splitCmd[1:]...) } // Same as ExecutableFromString but cancellable via a context @@ -96,6 +96,12 @@ func (c *OSCommand) ExecutableFromStringContext(ctx context.Context, commandStr return exec.CommandContext(ctx, splitCmd[0], splitCmd[1:]...) } +func (c *OSCommand) NewCmd(cmdName string, commandArgs ...string) *exec.Cmd { + cmd := c.command(cmdName, commandArgs...) + cmd.Env = os.Environ() + return cmd +} + func (c *OSCommand) NewCommandStringWithShell(commandStr string) string { var quotedCommand string // Windows does not seem to like quotes around the command @@ -187,12 +193,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) { return nil, errors.New("No editor defined in $VISUAL or $EDITOR") } - return c.PrepareSubProcess(editor, filename), nil -} - -// PrepareSubProcess iniPrepareSubProcessrocess then tells the Gui to switch to it -func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *exec.Cmd { - return c.command(cmdName, commandArgs...) + return c.NewCmd(editor, filename), nil } // Quote wraps a message in platform-specific quotation marks @@ -301,7 +302,7 @@ func (c *OSCommand) GetLazydockerPath() string { // RunCustomCommand returns the pointer to a custom command func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd { - return c.PrepareSubProcess(c.Platform.shell, c.Platform.shellArg, command) + return c.NewCmd(c.Platform.shell, c.Platform.shellArg, command) } // PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C diff --git a/pkg/commands/os_test.go b/pkg/commands/os_test.go index 978844d..92be790 100644 --- a/pkg/commands/os_test.go +++ b/pkg/commands/os_test.go @@ -90,7 +90,7 @@ func TestOSCommandEditFile(t *testing.T) { assert.EqualValues(t, "nano", name) - return nil + return exec.Command("exit", "0") }, func(env string) string { if env == "VISUAL" { @@ -112,7 +112,7 @@ func TestOSCommandEditFile(t *testing.T) { assert.EqualValues(t, "emacs", name) - return nil + return exec.Command("exit", "0") }, func(env string) string { if env == "EDITOR" { @@ -134,7 +134,7 @@ func TestOSCommandEditFile(t *testing.T) { assert.EqualValues(t, "vi", name) - return nil + return exec.Command("exit", "0") }, func(env string) string { return ""