Skip to content

Commit aae154b

Browse files
mustard-mhroboquat
authored andcommitted
[supervisor] change default directory of ssh
1 parent dbda2c1 commit aae154b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

components/supervisor/pkg/supervisor/ssh.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,18 @@ func writeSSHEnv(cfg *Config, envvars []string) error {
213213

214214
return nil
215215
}
216+
217+
func configureSSHDefaultDir(cfg *Config) {
218+
if cfg.RepoRoot == "" {
219+
log.Error("cannot configure ssh default dir with empty repo root")
220+
return
221+
}
222+
file, err := os.OpenFile("/home/gitpod/.bashrc", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o644)
223+
if err != nil {
224+
log.WithError(err).Error("cannot write .bashrc")
225+
}
226+
defer file.Close()
227+
if _, err := file.WriteString(fmt.Sprintf("\nif [[ -n $SSH_CONNECTION ]]; then cd \"%s\"; fi\n", cfg.RepoRoot)); err != nil {
228+
log.WithError(err).Error("write .bashrc failed")
229+
}
230+
}

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childP
12341234
log.WithError(err).Error("err creating SSH server")
12351235
return
12361236
}
1237-
1237+
configureSSHDefaultDir(cfg)
12381238
err = ssh.listenAndServe()
12391239
if err != nil {
12401240
log.WithError(err).Error("err starting SSH server")

0 commit comments

Comments
 (0)