Skip to content

Commit

Permalink
Add taskCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Mar 19, 2021
1 parent 7a4df82 commit 7d94bb8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/fileSystemConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface FileSystemConfig extends ConnectConfig {
sftpSudo?: string | boolean;
/** The command(s) to run when a new SSH terminal gets created. Defaults to `$SHELL`. Internally the command `cd ...` is run first */
terminalCommand?: string | string[];
/** The command(s) to run when a `ssh-shell` gets run. Defaults to the placeholder `$COMMAND`. Internally the command `cd ...` is run first */
taskCommand?: string | string[];
/** The filemode to assign to created files */
newFileMode?: number | string;
/** Whether this config was created from an instant connection string. Enables fuzzy matching for e.g. PuTTY, config-by-host, ... */
Expand Down
13 changes: 11 additions & 2 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,22 @@ export class Manager implements vscode.TaskProvider, vscode.TerminalLinkProvider
`SSH Task '${task.name}'`,
'ssh',
new vscode.CustomExecution(async (resolved: SSHShellTaskOptions) => {
const { createTerminal, createTextTerminal } = await import('./pseudoTerminal');
const { createTerminal, createTextTerminal, joinCommands } = await import('./pseudoTerminal');
try {
if (!resolved.host) throw new Error('Missing field \'host\' in task description');
if (!resolved.command) throw new Error('Missing field \'command\' in task description');
const connection = await this.connectionManager.createConnection(resolved.host);
resolved = await this.replaceTaskVariablesRecursive(resolved, value => this.replaceTaskVariables(value, connection.actualConfig));
const { command, workingDirectory } = resolved;
let { command, workingDirectory } = resolved;
let { taskCommand = '$COMMAND' } = connection.actualConfig;
taskCommand = joinCommands(taskCommand)!;
if (taskCommand.includes('$COMMAND')) {
command = taskCommand.replace(/\$COMMAND/g, command);
} else {
const message = `The taskCommand '${taskCommand}' is missing the '$COMMAND' placeholder!`;
Logging.warning(message, LOGGING_NO_STACKTRACE);
command = `echo "Missing '$COMMAND' placeholder"`;
}
//if (workingDirectory) workingDirectory = this.getRemotePath(config, workingDirectory);
this.connectionManager.update(connection, con => con.pendingUserCount++);
const pty = await createTerminal({
Expand Down
4 changes: 2 additions & 2 deletions src/pseudoTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export interface TerminalOptions {
command?: string;
}

function joinCommands(commands?: string | string[]): string | undefined {
export function joinCommands(commands?: string | string[]): string | undefined {
if (!commands) return undefined;
if (typeof commands === 'string') return commands;
return commands.join(';');
return commands.join('; ');
}

export async function createTerminal(options: TerminalOptions): Promise<SSHPseudoTerminal> {
Expand Down

0 comments on commit 7d94bb8

Please sign in to comment.