From d20d4be92d573d84b98250cc34158db556bcb044 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Wed, 14 Apr 2021 14:46:05 +0200 Subject: [PATCH] Add WINDOWS_COMMAND_SEPARATOR config flag (issue #255) --- src/manager.ts | 6 ++++-- src/pseudoTerminal.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/manager.ts b/src/manager.ts index ecf42c0..a4b0f49 100644 --- a/src/manager.ts +++ b/src/manager.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import type { Client, ClientChannel } from 'ssh2'; import * as vscode from 'vscode'; -import { getConfig, loadConfigsRaw } from './config'; +import { getConfig, getFlagBoolean, loadConfigsRaw } from './config'; import { Connection, ConnectionManager } from './connection'; import type { FileSystemConfig } from './fileSystemConfig'; import { getRemotePath } from './fileSystemRouter'; @@ -183,8 +183,10 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider const connection = await this.connectionManager.createConnection(resolved.host); resolved = await replaceVariablesRecursive(resolved, value => replaceVariables(value, connection.actualConfig)); let { command, workingDirectory } = resolved; + const [useWinCmdSep] = getFlagBoolean('WINDOWS_COMMAND_SEPARATOR', false, connection.actualConfig.flags); + const separator = useWinCmdSep ? ' && ' : '; '; let { taskCommand = '$COMMAND' } = connection.actualConfig; - taskCommand = joinCommands(taskCommand)!; + taskCommand = joinCommands(taskCommand, separator)!; if (taskCommand.includes('$COMMAND')) { command = taskCommand.replace(/\$COMMAND/g, command); } else { diff --git a/src/pseudoTerminal.ts b/src/pseudoTerminal.ts index 4611629..9e4680b 100644 --- a/src/pseudoTerminal.ts +++ b/src/pseudoTerminal.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import type { Client, ClientChannel, PseudoTtyOptions } from "ssh2"; import type { Readable } from "stream"; import * as vscode from "vscode"; +import { getFlagBoolean } from './config'; import type { FileSystemConfig } from "./fileSystemConfig"; import { getRemotePath } from './fileSystemRouter'; import { Logging, LOGGING_NO_STACKTRACE } from "./logging"; @@ -39,10 +40,10 @@ export interface TerminalOptions { command?: string; } -export function joinCommands(commands?: string | string[]): string | undefined { +export function joinCommands(commands: string | string[] | undefined, separator: string): string | undefined { if (!commands) return undefined; if (typeof commands === 'string') return commands; - return commands.join('; '); + return commands.join(separator); } @@ -169,11 +170,13 @@ export async function createTerminal(options: TerminalOptions): Promise(cb => client.exec(joinCommands(commands)!, { pty: pseudoTtyOptions }, cb)); + const channel = await toPromise(cb => client.exec(joinCommands(commands, separator)!, { pty: pseudoTtyOptions }, cb)); if (!channel) throw new Error('Could not create remote terminal'); pseudo.channel = channel; channel.on('exit', onDidClose.fire);