Interface TerminalShellIntegration

Shell integration-powered capabilities owned by a terminal.

Stubbed

interface TerminalShellIntegration {
    cwd: undefined | Uri;
    executeCommand(commandLine): TerminalShellExecution;
    executeCommand(executable, args): TerminalShellExecution;
}

Properties

Methods

Properties

cwd: undefined | Uri

The current working directory of the terminal. This Uri may represent a file on another machine (eg. ssh into another machine). This requires the shell integration to support working directory reporting.

Stubbed

Methods

  • Execute a command, sending ^C as necessary to interrupt any running command if needed.

    Parameters

    • commandLine: string

      The command line to execute, this is the exact text that will be sent to the terminal.

    Returns TerminalShellExecution

    Example

    // Execute a command in a terminal immediately after being created
    const myTerm = window.createTerminal();
    window.onDidChangeTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
    if (terminal === myTerm) {
    const execution = shellIntegration.executeCommand('echo "Hello world"');
    window.onDidEndTerminalShellExecution(event => {
    if (event.execution === execution) {
    console.log(`Command exited with code ${event.exitCode}`);
    }
    }
    }));
    // Fallback to sendText if there is no shell integration within 3 seconds of launching
    setTimeout(() => {
    if (!myTerm.shellIntegration) {
    myTerm.sendText('echo "Hello world"');
    // Without shell integration, we can't know when the command has finished or what the
    // exit code was.
    }
    }, 3000);

    Example

    // Send command to terminal that has been alive for a while
    const commandLine = 'echo "Hello world"';
    if (term.shellIntegration) {
    const execution = shellIntegration.executeCommand({ commandLine });
    window.onDidEndTerminalShellExecution(event => {
    if (event.execution === execution) {
    console.log(`Command exited with code ${event.exitCode}`);
    }
    } else {
    term.sendText(commandLine);
    // Without shell integration, we can't know when the command has finished or what the
    // exit code was.
    }

    Stubbed

  • Execute a command, sending ^C as necessary to interrupt any running command if needed.

    Note This is not guaranteed to work as shell integration must be activated. Check whether TerminalShellExecution.exitCode is rejected to verify whether it was successful.

    Parameters

    • executable: string
    • args: string[]

      Arguments to launch the executable with which will be automatically escaped based on the executable type.

    Returns TerminalShellExecution

    Example

    // Execute a command in a terminal immediately after being created
    const myTerm = window.createTerminal();
    window.onDidActivateTerminalShellIntegration(async ({ terminal, shellIntegration }) => {
    if (terminal === myTerm) {
    const command = shellIntegration.executeCommand({
    command: 'echo',
    args: ['Hello world']
    });
    const code = await command.exitCode;
    console.log(`Command exited with code ${code}`);
    }
    }));
    // Fallback to sendText if there is no shell integration within 3 seconds of launching
    setTimeout(() => {
    if (!myTerm.shellIntegration) {
    myTerm.sendText('echo "Hello world"');
    // Without shell integration, we can't know when the command has finished or what the
    // exit code was.
    }
    }, 3000);

    Example

    // Send command to terminal that has been alive for a while
    const commandLine = 'echo "Hello world"';
    if (term.shellIntegration) {
    const command = term.shellIntegration.executeCommand({
    command: 'echo',
    args: ['Hello world']
    });
    const code = await command.exitCode;
    console.log(`Command exited with code ${code}`);
    } else {
    term.sendText(commandLine);
    // Without shell integration, we can't know when the command has finished or what the
    // exit code was.
    }

    Stubbed