diff --git a/src/client/terminals/envCollectionActivation/service.ts b/src/client/terminals/envCollectionActivation/service.ts index 447150c0f818..b7ec224828da 100644 --- a/src/client/terminals/envCollectionActivation/service.ts +++ b/src/client/terminals/envCollectionActivation/service.ts @@ -338,6 +338,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ } private async getPS1(shell: string, resource: Resource, env: EnvironmentVariables) { + // PS1 returned by shell is not predictable: #22078 + // Hence calculate it ourselves where possible. Should no longer be needed once #22128 is available. const customShellType = identifyShellFromShellPath(shell); if (this.noPromptVariableShells.includes(customShellType)) { return env.PS1; @@ -347,7 +349,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ const interpreter = await this.interpreterService.getActiveInterpreter(resource); const shouldSetPS1 = shouldPS1BeSet(interpreter?.type, env); if (shouldSetPS1) { - const prompt = getPromptForEnv(interpreter); + const prompt = getPromptForEnv(interpreter, env); if (prompt) { return prompt; } @@ -456,7 +458,7 @@ function shouldSkip(env: string) { ].includes(env); } -function getPromptForEnv(interpreter: PythonEnvironment | undefined) { +function getPromptForEnv(interpreter: PythonEnvironment | undefined, env: EnvironmentVariables) { if (!interpreter) { return undefined; } @@ -465,6 +467,9 @@ function getPromptForEnv(interpreter: PythonEnvironment | undefined) { // If conda base environment is selected, it can lead to "(base)" appearing twice if we return the env name. return undefined; } + if (interpreter.type === PythonEnvType.Virtual && env.VIRTUAL_ENV_PROMPT) { + return `(${env.VIRTUAL_ENV_PROMPT}) `; + } return `(${interpreter.envName}) `; } if (interpreter.envPath) {