Skip to content

Commit b8bdc96

Browse files
committed
Do not modify user's shell init scripts when hooks are evaled from SI
1 parent 0966979 commit b8bdc96

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/features/terminal/shellStartupSetupHandlers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ export async function handleSettingUpShellProfile(
1111
callback: (provider: ShellStartupScriptProvider, result: boolean) => void,
1212
): Promise<void> {
1313
const shells = providers.map((p) => p.shellType).join(', ');
14+
// TODO: Get opinions on potentially modifying the prompt
15+
// - If shell integration is active, we won't need to modify user's shell profile, init scripts.
16+
// - Current prompt we have below may not be the most accurate description.
1417
const response = await showInformationMessage(
1518
l10n.t(
16-
'To enable "{0}" activation, your shell profile(s) need to be updated to include the necessary startup scripts. Would you like to proceed with these changes?',
19+
'To enable "{0}" activation, your shell profile(s) may need to be updated to include the necessary startup scripts. Would you like to proceed with these changes?',
1720
ACT_TYPE_SHELL,
1821
),
1922
{ modal: true, detail: l10n.t('Shells: {0}', shells) },

src/features/terminal/shells/bash/bashStartup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import which from 'which';
55
import { traceError, traceInfo, traceVerbose } from '../../../../common/logging';
66
import { ShellConstants } from '../../../common/shellConstants';
77
import { hasStartupCode, insertStartupCode, removeStartupCode } from '../common/editUtils';
8+
import { shellIntegrationForActiveTerminal } from '../common/shellUtils';
89
import { ShellScriptEditState, ShellSetupState, ShellStartupScriptProvider } from '../startupProvider';
910
import { BASH_ENV_KEY, BASH_SCRIPT_VERSION, ZSH_ENV_KEY } from './bashConstants';
1011

@@ -69,6 +70,9 @@ async function isStartupSetup(profile: string, key: string): Promise<ShellSetupS
6970
}
7071

7172
async function setupStartup(profile: string, key: string, name: string): Promise<boolean> {
73+
if (shellIntegrationForActiveTerminal(name, profile)) {
74+
return true;
75+
}
7276
const activationContent = getActivationContent(key);
7377

7478
try {

src/features/terminal/shells/common/shellUtils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { window } from 'vscode';
12
import { PythonCommandRunConfiguration, PythonEnvironment } from '../../../../api';
3+
import { traceInfo } from '../../../../common/logging';
24
import { isWindows } from '../../../../common/utils/platformUtils';
35
import { ShellConstants } from '../../../common/shellConstants';
46
import { quoteArgs } from '../../../execution/execUtils';
@@ -95,3 +97,16 @@ export function extractProfilePath(content: string): string | undefined {
9597
}
9698
return undefined;
9799
}
100+
101+
export function shellIntegrationForActiveTerminal(name: string, profile: string): boolean {
102+
const hasShellIntegration = window.activeTerminal?.shellIntegration;
103+
104+
if (hasShellIntegration) {
105+
traceInfo(
106+
`SHELL: Shell integration is available in one of the terminals. Activate scripts will be evaluated at shell integration level.
107+
Skipping modification of ${name} profile at: ${profile}`,
108+
);
109+
return true;
110+
}
111+
return false;
112+
}

src/features/terminal/shells/fish/fishStartup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import which from 'which';
66
import { traceError, traceInfo, traceVerbose } from '../../../../common/logging';
77
import { ShellConstants } from '../../../common/shellConstants';
88
import { hasStartupCode, insertStartupCode, removeStartupCode } from '../common/editUtils';
9+
import { shellIntegrationForActiveTerminal } from '../common/shellUtils';
910
import { ShellScriptEditState, ShellSetupState, ShellStartupScriptProvider } from '../startupProvider';
1011
import { FISH_ENV_KEY, FISH_SCRIPT_VERSION } from './fishConstants';
1112

@@ -57,6 +58,9 @@ async function isStartupSetup(profilePath: string, key: string): Promise<boolean
5758

5859
async function setupStartup(profilePath: string, key: string): Promise<boolean> {
5960
try {
61+
if (shellIntegrationForActiveTerminal('fish', profilePath)) {
62+
return true;
63+
}
6064
const activationContent = getActivationContent(key);
6165
await fs.mkdirp(path.dirname(profilePath));
6266

src/features/terminal/shells/pwsh/pwshStartup.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import assert from 'assert';
1111
import { getWorkspacePersistentState } from '../../../../common/persistentState';
1212
import { ShellConstants } from '../../../common/shellConstants';
1313
import { hasStartupCode, insertStartupCode, removeStartupCode } from '../common/editUtils';
14-
import { extractProfilePath, PROFILE_TAG_END, PROFILE_TAG_START } from '../common/shellUtils';
14+
import {
15+
extractProfilePath,
16+
PROFILE_TAG_END,
17+
PROFILE_TAG_START,
18+
shellIntegrationForActiveTerminal,
19+
} from '../common/shellUtils';
1520
import { POWERSHELL_ENV_KEY, PWSH_SCRIPT_VERSION } from './pwshConstants';
1621

1722
const PWSH_PROFILE_PATH_CACHE_KEY = 'PWSH_PROFILE_PATH_CACHE';
@@ -140,6 +145,9 @@ async function isPowerShellStartupSetup(shell: string, profile: string): Promise
140145
}
141146

142147
async function setupPowerShellStartup(shell: string, profile: string): Promise<boolean> {
148+
if (shellIntegrationForActiveTerminal(shell, profile)) {
149+
return true;
150+
}
143151
const activationContent = getActivationContent();
144152

145153
try {

0 commit comments

Comments
 (0)