title: “Feasibility of Specifying a Startup File When Opening an SSH2 Session” tags:
- WebShell
- Linux
- Development Tools slug: c57a1702 date: 2024-06-29 23:51:19 summary: “This post explores whether an SSH2-based web terminal can specify a startup file when opening an interactive session, outlines possible approaches, and notes their trade-offs.”
While reading the inshellisense code, I noticed it controls loading a startup file from a specific directory when spawning a local shell. That made me wonder: can an SSH2 web terminal session do something similar? Here’s a quick feasibility discussion.
inshellisense’s approach
Taking bash as an example:
shellArgs = ["--init-file", path.join(shellFolderPath, "shellIntegration.bash")];
this.#pty = pty.spawn(shellTarget, shellArgs ?? [], {
name: "xterm-256color",
cols,
rows,
cwd: process.cwd(),
env: { ...convertToPtyEnv(shell, underTest, login), ...env },
});
This works by passing shell-specific arguments as the second parameter to spawn; for bash, there is an --init-file option.

SSH2
https://github.com/mscdex/ssh2?tab=readme-ov-file#client-methods
There is no analogous parameter in the SSH2 connect method, so you can’t pass a startup file that way.
Two possible workarounds:
In an interactive session, run
sourceto load your integration script. Downside: it will produce visible echo/output artifacts.stream.write('');Modify the shell’s startup file (e.g.,
.bashrc) to load your script by default. This avoids echo issues on subsequent connections.conn.exec('');
Final Thoughts
Done.

