Skip to content

Commit eccd0d6

Browse files
committed
Cover & for shell integration enabled pwsh case
1 parent fefc113 commit eccd0d6

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/features/terminal/runInTerminal.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Terminal, TerminalShellExecution } from 'vscode';
22
import { PythonEnvironment, PythonTerminalExecutionOptions } from '../../api';
3-
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
43
import { createDeferred } from '../../common/utils/deferred';
5-
import { quoteArgs } from '../execution/execUtils';
6-
import { identifyTerminalShell } from '../common/shellDetector';
4+
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
75
import { ShellConstants } from '../common/shellConstants';
6+
import { identifyTerminalShell } from '../common/shellDetector';
7+
import { quoteArgs } from '../execution/execUtils';
88

99
export async function runInTerminal(
1010
environment: PythonEnvironment,
@@ -15,11 +15,10 @@ export async function runInTerminal(
1515
terminal.show();
1616
}
1717

18-
const executable =
19-
environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
18+
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
2019
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
2120
const allArgs = [...args, ...(options.args ?? [])];
22-
21+
const shellType = identifyTerminalShell(terminal);
2322
if (terminal.shellIntegration) {
2423
let execution: TerminalShellExecution | undefined;
2524
const deferred = createDeferred<void>();
@@ -29,10 +28,13 @@ export async function runInTerminal(
2928
deferred.resolve();
3029
}
3130
});
31+
if (shellType === ShellConstants.PWSH && !executable.startsWith('&')) {
32+
// PowerShell requires commands to be prefixed with '&' to run them.
33+
executable = `& ${executable}`;
34+
}
3235
execution = terminal.shellIntegration.executeCommand(executable, allArgs);
3336
await deferred.promise;
3437
} else {
35-
const shellType = identifyTerminalShell(terminal);
3638
let text = quoteArgs([executable, ...allArgs]).join(' ');
3739
if (shellType === ShellConstants.PWSH && !text.startsWith('&')) {
3840
// PowerShell requires commands to be prefixed with '&' to run them.

0 commit comments

Comments
 (0)