Add terminalCommand to FileSystemConfig

feature/ssh-config
Kelvin Schoofs 4 years ago
parent 5c82692862
commit 65fa99b554

@ -92,10 +92,12 @@ export interface FileSystemConfig extends ConnectConfig {
privateKeyPath?: string; privateKeyPath?: string;
/** A name of another config to use as a hop */ /** A name of another config to use as a hop */
hop?: string; hop?: string;
/** A command to run on the remote SSH session to start a SFTP session (defaults to sftp subsystem) */ /** The command to run on the remote SSH session to start a SFTP session (defaults to sftp subsystem) */
sftpCommand?: string; sftpCommand?: string;
/** Whether to use a sudo shell (and for which user) to run the sftpCommand in (sftpCommand defaults to /usr/lib/openssh/sftp-server if missing) */ /** Whether to use a sudo shell (and for which user) to run the sftpCommand in (sftpCommand defaults to /usr/lib/openssh/sftp-server if missing) */
sftpSudo?: string | boolean; sftpSudo?: string | boolean;
/** The command(s) to run when a new SSH terminals gets created. Defaults to `$SHELL`. Internally the command `cd ...` is run first */
terminalCommand?: string | string[];
/** The filemode to assign to created files */ /** The filemode to assign to created files */
newFileMode?: number | string; newFileMode?: number | string;
/** Internal property saying where this config comes from. Undefined if this config is merged or something */ /** Internal property saying where this config comes from. Undefined if this config is merged or something */

@ -31,8 +31,14 @@ export interface TerminalOptions {
command?: string; command?: string;
} }
function joinCommands(commands?: string | string[]): string | undefined {
if (!commands) return undefined;
if (typeof commands === 'string') return commands;
return commands.join(';');
}
export async function createTerminal(options: TerminalOptions): Promise<SSHPseudoTerminal> { export async function createTerminal(options: TerminalOptions): Promise<SSHPseudoTerminal> {
const { client, config, command } = options; const { client, config } = options;
const onDidWrite = new vscode.EventEmitter<string>(); const onDidWrite = new vscode.EventEmitter<string>();
const onDidClose = new vscode.EventEmitter<number>(); const onDidClose = new vscode.EventEmitter<number>();
const onDidOpen = new vscode.EventEmitter<void>(); const onDidOpen = new vscode.EventEmitter<void>();
@ -57,7 +63,7 @@ export async function createTerminal(options: TerminalOptions): Promise<SSHPseud
async open(dims) { async open(dims) {
onDidWrite.fire(`Connecting to ${config.label || config.name}...\r\n`); onDidWrite.fire(`Connecting to ${config.label || config.name}...\r\n`);
try { try {
let commands = [options.command || '$SHELL']; let commands: string[] = [options.command || joinCommands(options.config.terminalCommand) || '$SHELL'];
// There isn't a proper way of setting the working directory, but this should work in most cases // There isn't a proper way of setting the working directory, but this should work in most cases
let { workingDirectory } = options; let { workingDirectory } = options;
workingDirectory = workingDirectory || config.root; workingDirectory = workingDirectory || config.root;
@ -72,7 +78,7 @@ export async function createTerminal(options: TerminalOptions): Promise<SSHPseud
commands.unshift(`cd ${workingDirectory}`); commands.unshift(`cd ${workingDirectory}`);
} }
const pseudoTtyOptions: PseudoTtyOptions = { ...PSEUDO_TTY_OPTIONS, cols: dims?.columns, rows: dims?.rows }; const pseudoTtyOptions: PseudoTtyOptions = { ...PSEUDO_TTY_OPTIONS, cols: dims?.columns, rows: dims?.rows };
const channel = await toPromise<ClientChannel | undefined>(cb => client.exec(commands.join(';'), { pty: pseudoTtyOptions }, cb)); const channel = await toPromise<ClientChannel | undefined>(cb => client.exec(joinCommands(commands)!, { pty: pseudoTtyOptions }, cb));
if (!channel) throw new Error('Could not create remote terminal'); if (!channel) throw new Error('Could not create remote terminal');
pseudo.channel = channel; pseudo.channel = channel;
channel.on('exit', onDidClose.fire); channel.on('exit', onDidClose.fire);

@ -96,6 +96,8 @@ export interface FileSystemConfig extends ConnectConfig {
sftpCommand?: string; sftpCommand?: string;
/** Whether to use a sudo shell (and for which user) to run the sftpCommand in (sftpCommand defaults to /usr/lib/openssh/sftp-server if missing) */ /** Whether to use a sudo shell (and for which user) to run the sftpCommand in (sftpCommand defaults to /usr/lib/openssh/sftp-server if missing) */
sftpSudo?: string | boolean; sftpSudo?: string | boolean;
/** The command(s) to run when a new SSH terminals gets created. Defaults to `$SHELL`. Internally the command `cd ...` is run first */
terminalCommand?: string | string[];
/** The filemode to assign to created files */ /** The filemode to assign to created files */
newFileMode?: number | string; newFileMode?: number | string;
/** Internal property saying where this config comes from. Undefined if this config is merged or something */ /** Internal property saying where this config comes from. Undefined if this config is merged or something */

Loading…
Cancel
Save