From 65fa99b554b32c11796a7c7d3c0f6cf910ef39a2 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Wed, 16 Dec 2020 23:15:42 +0100 Subject: [PATCH] Add terminalCommand to FileSystemConfig --- src/fileSystemConfig.ts | 4 +++- src/pseudoTerminal.ts | 12 +++++++++--- webview/src/types/fileSystemConfig.ts | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/fileSystemConfig.ts b/src/fileSystemConfig.ts index 549f698..b66daf1 100644 --- a/src/fileSystemConfig.ts +++ b/src/fileSystemConfig.ts @@ -92,10 +92,12 @@ export interface FileSystemConfig extends ConnectConfig { privateKeyPath?: string; /** A name of another config to use as a hop */ 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; /** 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; + /** 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 */ newFileMode?: number | string; /** Internal property saying where this config comes from. Undefined if this config is merged or something */ diff --git a/src/pseudoTerminal.ts b/src/pseudoTerminal.ts index 05575fd..179e191 100644 --- a/src/pseudoTerminal.ts +++ b/src/pseudoTerminal.ts @@ -31,8 +31,14 @@ export interface TerminalOptions { 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 { - const { client, config, command } = options; + const { client, config } = options; const onDidWrite = new vscode.EventEmitter(); const onDidClose = new vscode.EventEmitter(); const onDidOpen = new vscode.EventEmitter(); @@ -57,7 +63,7 @@ export async function createTerminal(options: TerminalOptions): Promise(cb => client.exec(commands.join(';'), { pty: pseudoTtyOptions }, cb)); + const channel = await toPromise(cb => client.exec(joinCommands(commands)!, { pty: pseudoTtyOptions }, cb)); if (!channel) throw new Error('Could not create remote terminal'); pseudo.channel = channel; channel.on('exit', onDidClose.fire); diff --git a/webview/src/types/fileSystemConfig.ts b/webview/src/types/fileSystemConfig.ts index 4ec8378..5fa3686 100644 --- a/webview/src/types/fileSystemConfig.ts +++ b/webview/src/types/fileSystemConfig.ts @@ -96,6 +96,8 @@ export interface FileSystemConfig extends ConnectConfig { 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) */ 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 */ newFileMode?: number | string; /** Internal property saying where this config comes from. Undefined if this config is merged or something */