diff --git a/host.go b/host.go index f575229..4c54fba 100644 --- a/host.go +++ b/host.go @@ -97,6 +97,10 @@ func (h *Host) Connect(term *sshd.Terminal) { cfg.Theme = &h.theme user.SetConfig(cfg) + // Load user config overrides from ENV + // TODO: Would be nice to skip the command parsing pipeline just to load + // config values. Would need to factor out some command handler logic into + // accessible helpers. env := term.Env() for _, e := range env { switch e.Key { diff --git a/sshd/terminal.go b/sshd/terminal.go index 480fa59..7e40a5d 100644 --- a/sshd/terminal.go +++ b/sshd/terminal.go @@ -93,6 +93,7 @@ type Terminal struct { } // Make new terminal from a session channel +// TODO: For v2, make a separate `Serve(ctx context.Context) error` method to activate the Terminal func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) { if ch.ChannelType() != "session" { return nil, ErrNotSessionChannel @@ -131,15 +132,18 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) { } }() + // We need to wait for term.ready to acquire a shell before we return, this + // gives the SSH session a chance to populate the env vars and other state. + // TODO: Make the timeout configurable + // TODO: Use context.Context for abort/timeout in the future, will need to change the API. select { - case <-ready: // ok... + case <-ready: // shell acquired + return &term, nil case <-term.done: return nil, errors.New("terminal aborted") case <-time.NewTimer(time.Minute).C: return nil, errors.New("timed out starting terminal") } - - return &term, nil } // NewSession Finds a session channel and make a Terminal from it @@ -169,7 +173,7 @@ func (t *Terminal) Close() error { return err } -// Negotiate terminal type and settings +// listen negotiates the terminal type and state // ready is closed when the terminal is ready. func (t *Terminal) listen(requests <-chan *ssh.Request, ready chan<- struct{}) { hasShell := false