From 9911acd715d986635b300d93669a758d1b1cc35a Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Wed, 26 Feb 2020 15:10:36 +0000 Subject: [PATCH] Start terminal in configurable directory --- pkg/terminal/terminal.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/terminal/terminal.go b/pkg/terminal/terminal.go index 75faa29..d4bfc34 100644 --- a/pkg/terminal/terminal.go +++ b/pkg/terminal/terminal.go @@ -19,6 +19,7 @@ import ( // Terminal communicates with the underlying terminal which is running shox type Terminal struct { shell string + dir string proxy *proxy.Proxy pty *os.File enableNesting bool @@ -43,6 +44,11 @@ func (t *Terminal) SetShell(shell string) { t.shell = shell } +// SetDir sets the directory the shell will start in (CWD) +func (t *Terminal) SetDir(dir string) { + t.dir = dir +} + // AddDecorator adds a decorator to alter the terminal output func (t *Terminal) AddDecorator(d decorators.Decorator) { t.proxy.AddDecorator(d) @@ -75,6 +81,10 @@ func (t *Terminal) Run() error { // Create arbitrary command. c := exec.Command(t.shell) + if t.dir != "" { + c.Dir = t.dir + } + // Start the command with a pty. var err error t.pty, err = pty.Start(c)