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)