Skip to content

Commit

Permalink
fine tune shell integration messaging (#148856)
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed May 6, 2022
1 parent 7a26556 commit 5357dcf
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 158 deletions.
1 change: 0 additions & 1 deletion src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ export interface IShellLaunchConfigDto {
export interface ITerminalProcessOptions {
shellIntegration: {
enabled: boolean;
showWelcome: boolean;
};
windowsEnableConpty: boolean;
}
Expand Down
12 changes: 2 additions & 10 deletions src/vs/platform/terminal/node/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ export function getShellIntegrationInjection(
return undefined;
}
if (newArgs) {
const additionalArgs = options.showWelcome ? '' : ' -HideWelcome';
newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot, additionalArgs);
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot, '');
}
return { newArgs };
}
Expand All @@ -156,9 +155,6 @@ export function getShellIntegrationInjection(
}
newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot);
if (!options.showWelcome) {
envMixin['VSCODE_SHELL_HIDE_WELCOME'] = '1';
}
return { newArgs, envMixin };
}
case 'pwsh': {
Expand All @@ -170,9 +166,8 @@ export function getShellIntegrationInjection(
if (!newArgs) {
return undefined;
}
const additionalArgs = options.showWelcome ? '' : ' -HideWelcome';
newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot, additionalArgs);
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot, '');
return { newArgs };
}
case 'zsh': {
Expand Down Expand Up @@ -208,9 +203,6 @@ export function getShellIntegrationInjection(
source: path.join(appRoot, 'out/vs/workbench/contrib/terminal/browser/media/shellIntegration-login.zsh'),
dest: path.join(zdotdir, '.zlogin')
});
if (!options.showWelcome) {
envMixin['VSCODE_SHELL_HIDE_WELCOME'] = '1';
}
return { newArgs, envMixin, filesToCopy };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { NullLogService } from 'vs/platform/log/common/log';
import { ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
import { getShellIntegrationInjection, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment';

const enabledProcessOptions: ITerminalProcessOptions['shellIntegration'] = { enabled: true, showWelcome: true };
const disabledProcessOptions: ITerminalProcessOptions['shellIntegration'] = { enabled: false, showWelcome: true };
const enabledProcessOptions: ITerminalProcessOptions['shellIntegration'] = { enabled: true };
const disabledProcessOptions: ITerminalProcessOptions['shellIntegration'] = { enabled: false };
const pwshExe = process.platform === 'win32' ? 'pwsh.exe' : 'pwsh';
const repoRoot = process.platform === 'win32' ? process.cwd()[0].toLowerCase() + process.cwd().substring(1) : process.cwd();
const logService = new NullLogService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { TerminalLink } from 'vs/workbench/contrib/terminal/browser/links/termin
import { TerminalLinkDetectorAdapter } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkDetectorAdapter';
import { TerminalLocalFileLinkOpener, TerminalLocalFolderInWorkspaceLinkOpener, TerminalLocalFolderOutsideWorkspaceLinkOpener, TerminalSearchLinkOpener, TerminalUrlLinkOpener } from 'vs/workbench/contrib/terminal/browser/links/terminalLinkOpeners';
import { lineAndColumnClause, TerminalLocalLinkDetector, unixLocalLinkClause, winDrivePrefix, winLocalLinkClause } from 'vs/workbench/contrib/terminal/browser/links/terminalLocalLinkDetector';
import { TerminalShellIntegrationLinkDetector } from 'vs/workbench/contrib/terminal/browser/links/terminalShellIntegrationLinkDetector';
import { TerminalUriLinkDetector } from 'vs/workbench/contrib/terminal/browser/links/terminalUriLinkDetector';
import { TerminalWordLinkDetector } from 'vs/workbench/contrib/terminal/browser/links/terminalWordLinkDetector';
import { ITerminalExternalLinkProvider, TerminalLinkQuickPickEvent } from 'vs/workbench/contrib/terminal/browser/terminal';
Expand Down Expand Up @@ -75,7 +74,6 @@ export class TerminalLinkManager extends DisposableStore {
if (this._configurationService.getValue<ITerminalConfiguration>(TERMINAL_CONFIG_SECTION).enableFileLinks) {
this._setupLinkDetector(TerminalLocalLinkDetector.id, this._instantiationService.createInstance(TerminalLocalLinkDetector, this._xterm, capabilities, this._processManager.os || OS, this._resolvePath.bind(this)));
}
this._setupLinkDetector(TerminalShellIntegrationLinkDetector.id, this._instantiationService.createInstance(TerminalShellIntegrationLinkDetector, this._xterm));
this._setupLinkDetector(TerminalWordLinkDetector.id, this._instantiationService.createInstance(TerminalWordLinkDetector, this._xterm));

capabilities.get(TerminalCapability.CwdDetection)?.onDidChangeCwd(cwd => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ else
fi

if [[ "$PROMPT_COMMAND" =~ .*(' '.*\;)|(\;.*' ').* ]]; then
builtin echo -e "\033[1;33mShell integration cannot be activated due to complex PROMPT_COMMAND: $PROMPT_COMMAND\033[0m"
VSCODE_SHELL_HIDE_WELCOME=""
VSCODE_SHELL_INTEGRATION=""
builtin return
fi

Expand Down Expand Up @@ -151,8 +150,3 @@ else
fi

trap '__vsc_preexec' DEBUG
if [ -z "$VSCODE_SHELL_HIDE_WELCOME" ]; then
builtin echo -e "\033[1;32mShell integration activated\033[0m"
else
VSCODE_SHELL_HIDE_WELCOME=""
fi
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,3 @@ __vsc_preexec() {
}
add-zsh-hook precmd __vsc_precmd
add-zsh-hook preexec __vsc_preexec

# Show the welcome message
if [ -z "${VSCODE_SHELL_HIDE_WELCOME-}" ]; then
builtin echo "\033[1;32mShell integration activated\033[0m"
else
VSCODE_SHELL_HIDE_WELCOME=""
fi
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# ---------------------------------------------------------------------------------------------

param(
[Parameter(HelpMessage="Hides the shell integration welcome message")]
[switch] $HideWelcome = $False
)

$Global:__VSCodeOriginalPrompt = $function:Prompt

$Global:__LastHistoryId = -1
Expand Down Expand Up @@ -72,8 +67,3 @@ if (Get-Module -Name PSReadLine) {

# Set IsWindows property
[Console]::Write("`e]633;P;IsWindows=$($IsWindows)`a")

# Show the welcome message
if ($HideWelcome -eq $False) {
Write-Host "`e[1mShell integration activated`e[0m" -ForegroundColor Green
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
});
const options: ITerminalProcessOptions = {
shellIntegration: {
enabled: this._configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled),
showWelcome: this._configurationService.getValue(TerminalSettingId.ShellIntegrationShowWelcome),
enabled: this._configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled)
},
windowsEnableConpty: this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled
};
Expand Down Expand Up @@ -436,8 +435,7 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce

const options: ITerminalProcessOptions = {
shellIntegration: {
enabled: this._configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled),
showWelcome: this._configurationService.getValue(TerminalSettingId.ShellIntegrationShowWelcome),
enabled: this._configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled)
},
windowsEnableConpty: this._configHelper.config.windowsEnableConpty && !isScreenReaderModeEnabled
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class TerminalTabsRenderer implements IListRenderer<ITerminalInstance, ITerminal
}
}

const shellIntegrationString = getShellIntegrationTooltip(instance, true);
const shellIntegrationString = getShellIntegrationTooltip(instance, true, this._configurationService);
const iconId = getIconId(instance);
const hasActionbar = !this.shouldHideActionBar();
let label: string = '';
Expand Down
26 changes: 9 additions & 17 deletions src/vs/workbench/contrib/terminal/browser/terminalTooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,25 @@
import { localize } from 'vs/nls';
import { ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';

function getCapabilityName(capability: TerminalCapability): string | undefined {
switch (capability) {
case TerminalCapability.CwdDetection:
case TerminalCapability.NaiveCwdDetection:
return localize('capability.cwdDetection', "Current working directory detection");
case TerminalCapability.CommandDetection:
return localize('capability.commandDetection', "Command detection");
case TerminalCapability.PartialCommandDetection:
return localize('capability.partialCommandDetection', "Command detection (partial)");
export function getShellIntegrationTooltip(instance: ITerminalInstance, markdown: boolean, configurationService: IConfigurationService): string {
if (!configurationService.getValue(TerminalSettingId.ShellIntegrationEnabled)) {
return '';
}
}

export function getShellIntegrationTooltip(instance: ITerminalInstance, markdown?: boolean): string {
let shellIntegrationString = '';
const shellIntegrationCapabilities: TerminalCapability[] = [];
if (instance.capabilities.has(TerminalCapability.CommandDetection)) {
shellIntegrationCapabilities.push(TerminalCapability.CommandDetection);
}
if (instance.capabilities.has(TerminalCapability.CwdDetection)) {
shellIntegrationCapabilities.push(TerminalCapability.CwdDetection);
}
let shellIntegrationString = '';
if (shellIntegrationCapabilities.length > 0) {
shellIntegrationString += `${markdown ? '\n\n---\n\n' : '\n\n'} ${localize('shellIntegration.enabled', "Shell integration is enabled")}`;
for (const capability of shellIntegrationCapabilities) {
shellIntegrationString += `\n- ${getCapabilityName(capability)}`;
}
shellIntegrationString += `${markdown ? '\n\n---\n\n' : '\n\n'} ${localize('shellIntegration.enabled', "Shell integration activated")}`;
} else {
shellIntegrationString += `${markdown ? '\n\n---\n\n' : '\n\n'} ${localize('shellIntegration.activationFailed', "Shell integration failed to activate")}`;
}
return shellIntegrationString;
}
11 changes: 6 additions & 5 deletions src/vs/workbench/contrib/terminal/browser/terminalView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,13 @@ class SingleTerminalTabActionViewItem extends MenuEntryActionViewItem {
@IThemeService private readonly _themeService: IThemeService,
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@ICommandService private readonly _commandService: ICommandService,
@IConfigurationService configurationService: IConfigurationService
) {
super(new MenuItemAction(
{
id: action.id,
title: getSingleTabLabel(_terminalGroupService.activeInstance, _terminalService.configHelper.config.tabs.separator),
tooltip: getSingleTabTooltip(_terminalGroupService.activeInstance, _terminalService.configHelper.config.tabs.separator)
tooltip: getSingleTabTooltip(_terminalGroupService.activeInstance, _terminalService.configHelper.config.tabs.separator, configurationService)
},
{
id: TerminalCommandId.Split,
Expand All @@ -399,12 +400,12 @@ class SingleTerminalTabActionViewItem extends MenuEntryActionViewItem {
this._register(this._terminalService.onDidChangeInstanceColor(e => this.updateLabel(e)));
this._register(this._terminalService.onDidChangeInstanceTitle(e => {
if (e === this._terminalGroupService.activeInstance) {
this._action.tooltip = getSingleTabTooltip(e, this._terminalService.configHelper.config.tabs.separator);
this._action.tooltip = getSingleTabTooltip(e, this._terminalService.configHelper.config.tabs.separator, configurationService);
this.updateLabel();
}
}));
this._register(this._terminalService.onDidChangeInstanceCapability(e => {
this._action.tooltip = getSingleTabTooltip(e, this._terminalService.configHelper.config.tabs.separator);
this._action.tooltip = getSingleTabTooltip(e, this._terminalService.configHelper.config.tabs.separator, configurationService);
this.updateLabel(e);
}));

Expand Down Expand Up @@ -529,11 +530,11 @@ function getSingleTabLabel(instance: ITerminalInstance | undefined, separator: s
return `${label} $(${primaryStatus.icon.id})`;
}

function getSingleTabTooltip(instance: ITerminalInstance | undefined, separator: string): string {
function getSingleTabTooltip(instance: ITerminalInstance | undefined, separator: string, configurationService: IConfigurationService): string {
if (!instance) {
return '';
}
const shellIntegrationString = getShellIntegrationTooltip(instance);
const shellIntegrationString = getShellIntegrationTooltip(instance, false, configurationService);
const title = getSingleTabTitle(instance, separator);
return shellIntegrationString ? title + shellIntegrationString : title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { toolbarHoverBackground } from 'vs/platform/theme/common/colorRegistry';
import { TerminalSettingId } from 'vs/platform/terminal/common/terminal';
import { TERMINAL_COMMAND_DECORATION_DEFAULT_BACKGROUND_COLOR, TERMINAL_COMMAND_DECORATION_ERROR_BACKGROUND_COLOR, TERMINAL_COMMAND_DECORATION_SUCCESS_BACKGROUND_COLOR } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
import { Color } from 'vs/base/common/color';
import { IOpenerService } from 'vs/platform/opener/common/opener';

const enum DecorationSelector {
CommandDecoration = 'terminal-command-decoration',
Expand Down Expand Up @@ -58,7 +59,8 @@ export class DecorationAddon extends Disposable implements ITerminalAddon {
@IContextMenuService private readonly _contextMenuService: IContextMenuService,
@IHoverService private readonly _hoverService: IHoverService,
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IThemeService private readonly _themeService: IThemeService
@IThemeService private readonly _themeService: IThemeService,
@IOpenerService private readonly _openerService: IOpenerService
) {
super();
this._register(toDisposable(() => this.clearDecorations(true)));
Expand Down Expand Up @@ -324,6 +326,10 @@ export class DecorationAddon extends Disposable implements ITerminalAddon {
class: 'rerun-command', tooltip: 'Rerun Command', dispose: () => { }, id: 'terminal.rerunCommand', label: localize("terminal.rerunCommand", 'Rerun Command'), enabled: true,
run: () => this._onDidRequestRunCommand.fire({ command })
});
actions.push({
class: 'how-does-this-work', tooltip: 'How does this work?', dispose: () => { }, id: 'terminal.howDoesThisWork', label: localize("terminal.howDoesThisWork", 'How does this work?'), enabled: true,
run: () => this._openerService.open('https://code.visualstudio.com/docs/editor/integrated-terminal#_shell-integration')
});
return actions;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ const terminalConfiguration: IConfigurationNode = {
},
[TerminalSettingId.ShellIntegrationEnabled]: {
restricted: true,
markdownDescription: localize('terminal.integrated.shellIntegration.enabled', "Enable the experimental shell integration feature which will turn on certain features like enhanced command tracking and current working directory detection. Shell integration works by injecting a script that is run when the shell is initialized which lets the terminal gain additional insights into what is happening within the terminal, the script injection may not work if you have custom arguments defined in the terminal profile.\n\nSupported shells:\n\n- Linux/macOS: bash, pwsh, zsh\n - Windows: pwsh\n\nThis setting applies only when terminals are created, you will need to restart terminals for the setting to take effect."),
markdownDescription: localize('terminal.integrated.shellIntegration.enabled', "Enable features like enhanced command tracking and current working directory detection. \n\nShell integration works by injecting the shell with a startup script. The script gives VSCode insight into what is happening within the terminal.\n\nSupported shells:\n\n- Linux/macOS: bash, pwsh, zsh\n - Windows: pwsh\n\nThis setting applies only when terminals are created, so you will need to restart your terminals for it to take effect.\n\n Note that the script injection may not work if you have custom arguments defined in the terminal profile, a [complex bash `PROMPT_COMMAND`](https://code.visualstudio.com/docs/editor/integrated-terminal#_complex-bash-promptcommand), or other unsupported setup."),
type: 'boolean',
default: false
},
Expand All @@ -544,12 +544,6 @@ const terminalConfiguration: IConfigurationNode = {
type: 'boolean',
default: true
},
[TerminalSettingId.ShellIntegrationShowWelcome]: {
restricted: true,
markdownDescription: localize('terminal.integrated.shellIntegration.showWelcome', "Whether to show the shell integration activated welcome message in the terminal when the feature is enabled."),
type: 'boolean',
default: true
},
[TerminalSettingId.ShellIntegrationCommandHistory]: {
restricted: true,
markdownDescription: localize('terminal.integrated.shellIntegration.history', "Controls the number of recently used commands to keep in the terminal command history. Set to 0 to disable terminal command history."),
Expand Down
4 changes: 0 additions & 4 deletions test/automation/src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ export class Terminal {
}
}

async assertShellIntegrationActivated(): Promise<void> {
await this.waitForTerminalText(buffer => buffer.some(e => e.includes('Shell integration activated')));
}

async getTerminalGroups(): Promise<TerminalGroup[]> {
const tabCount = (await this.code.waitForElements(Selector.Tabs, true)).length;
const groups: TerminalGroup[] = [];
Expand Down

0 comments on commit 5357dcf

Please sign in to comment.