Skip to content

Commit 9c618ec

Browse files
authored
Merge pull request microsoft#161783 from microsoft/tyriar/159182
Include applicationName in zsh shell integration folder name
2 parents 811fbff + 8cd272d commit 9c618ec

File tree

5 files changed

+49
-61
lines changed

5 files changed

+49
-61
lines changed

src/vs/platform/terminal/node/ptyHostMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ delete process.env.VSCODE_RECONNECT_GRACE_TIME;
4444
delete process.env.VSCODE_RECONNECT_SHORT_GRACE_TIME;
4545
delete process.env.VSCODE_RECONNECT_SCROLLBACK;
4646

47-
const ptyService = new PtyService(lastPtyId, logService, reconnectConstants);
47+
const ptyService = new PtyService(lastPtyId, logService, productService, reconnectConstants);
4848
server.registerChannel(TerminalIpcChannels.PtyHost, ProxyChannel.fromService(ptyService));
4949

5050
process.once('exit', () => {

src/vs/platform/terminal/node/ptyService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { ErrorNoTelemetry } from 'vs/base/common/errors';
2828
import { ShellIntegrationAddon } from 'vs/platform/terminal/common/xterm/shellIntegrationAddon';
2929
import { formatMessageForTerminal } from 'vs/platform/terminal/common/terminalStrings';
3030
import { IPtyHostProcessReplayEvent } from 'vs/platform/terminal/common/capabilities/capabilities';
31+
import { IProductService } from 'vs/platform/product/common/productService';
3132

3233
type WorkspaceId = string;
3334

@@ -64,6 +65,7 @@ export class PtyService extends Disposable implements IPtyService {
6465
constructor(
6566
private _lastPtyId: number,
6667
private readonly _logService: ILogService,
68+
private readonly _productService: IProductService,
6769
private readonly _reconnectConstants: IReconnectConstants
6870
) {
6971
super();
@@ -244,7 +246,7 @@ export class PtyService extends Disposable implements IPtyService {
244246
throw new Error('Attempt to create a process when attach object was provided');
245247
}
246248
const id = ++this._lastPtyId;
247-
const process = new TerminalProcess(shellLaunchConfig, cwd, cols, rows, env, executableEnv, options, this._logService);
249+
const process = new TerminalProcess(shellLaunchConfig, cwd, cols, rows, env, executableEnv, options, this._logService, this._productService);
248250
process.onProcessData(event => this._onProcessData.fire({ id, event }));
249251
const processLaunchOptions: IPersistentTerminalProcessLaunchConfig = {
250252
env,

src/vs/platform/terminal/node/terminalEnvironment.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { format } from 'vs/base/common/strings';
1313
import { isString } from 'vs/base/common/types';
1414
import * as pfs from 'vs/base/node/pfs';
1515
import { ILogService } from 'vs/platform/log/common/log';
16+
import { IProductService } from 'vs/platform/product/common/productService';
1617
import { IShellLaunchConfig, ITerminalEnvironment, ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal';
1718

1819
export function getWindowsBuildNumber(): number {
@@ -105,7 +106,8 @@ export function getShellIntegrationInjection(
105106
shellLaunchConfig: IShellLaunchConfig,
106107
options: ITerminalProcessOptions['shellIntegration'],
107108
env: ITerminalEnvironment | undefined,
108-
logService: ILogService
109+
logService: ILogService,
110+
productService: IProductService
109111
): IShellIntegrationConfigInjection | undefined {
110112
// Shell integration arg injection is disabled when:
111113
// - The global setting is disabled
@@ -184,8 +186,9 @@ export function getShellIntegrationInjection(
184186
}
185187
newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
186188
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot);
189+
187190
// Move .zshrc into $ZDOTDIR as the way to activate the script
188-
const zdotdir = path.join(os.tmpdir(), `${os.userInfo().username}-vscode-zsh`);
191+
const zdotdir = path.join(os.tmpdir(), `${os.userInfo().username}-${productService.applicationName}-zsh`);
189192
envMixin['ZDOTDIR'] = zdotdir;
190193
const userZdotdir = env?.ZDOTDIR ?? os.homedir() ?? `~`;
191194
envMixin['USER_ZDOTDIR'] = userZdotdir;

src/vs/platform/terminal/node/terminalProcess.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
import { exec } from 'child_process';
77
import { promises as fs } from 'fs';
88
import type * as pty from 'node-pty';
9-
import { tmpdir } from 'os';
109
import { timeout } from 'vs/base/common/async';
1110
import { Emitter, Event } from 'vs/base/common/event';
1211
import { Disposable } from 'vs/base/common/lifecycle';
13-
import { FileAccess } from 'vs/base/common/network';
1412
import * as path from 'vs/base/common/path';
1513
import { IProcessEnvironment, isLinux, isMacintosh, isWindows } from 'vs/base/common/platform';
1614
import { URI } from 'vs/base/common/uri';
1715
import { Promises } from 'vs/base/node/pfs';
1816
import { localize } from 'vs/nls';
1917
import { ILogService } from 'vs/platform/log/common/log';
18+
import { IProductService } from 'vs/platform/product/common/productService';
2019
import { FlowControlConstants, IShellLaunchConfig, ITerminalChildProcess, ITerminalLaunchError, IProcessProperty, IProcessPropertyMap as IProcessPropertyMap, ProcessPropertyType, TerminalShellType, IProcessReadyEvent, ITerminalProcessOptions, PosixShellType } from 'vs/platform/terminal/common/terminal';
2120
import { ChildProcessMonitor } from 'vs/platform/terminal/node/childProcessMonitor';
2221
import { findExecutable, getShellIntegrationInjection, getWindowsBuildNumber, IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment';
@@ -145,7 +144,8 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess
145144
*/
146145
private readonly _executableEnv: IProcessEnvironment,
147146
private readonly _options: ITerminalProcessOptions,
148-
@ILogService private readonly _logService: ILogService
147+
@ILogService private readonly _logService: ILogService,
148+
@IProductService private readonly _productService: IProductService
149149
) {
150150
super();
151151
let name: string;
@@ -201,7 +201,7 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess
201201

202202
let injection: IShellIntegrationConfigInjection | undefined;
203203
if (this._options.shellIntegration.enabled) {
204-
injection = getShellIntegrationInjection(this.shellLaunchConfig, this._options.shellIntegration, this._ptyOptions.env, this._logService);
204+
injection = getShellIntegrationInjection(this.shellLaunchConfig, this._options.shellIntegration, this._ptyOptions.env, this._logService, this._productService);
205205
if (injection) {
206206
this._onDidChangeProperty.fire({ type: ProcessPropertyType.UsedShellIntegrationInjection, value: true });
207207
if (injection.envMixin) {
@@ -228,25 +228,6 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess
228228
}
229229
}
230230

231-
// Handle zsh shell integration - Set $ZDOTDIR to a temp dir and create $ZDOTDIR/.zshrc
232-
if (this.shellLaunchConfig.env?.['_ZDOTDIR'] === '1') {
233-
const zdotdir = path.join(tmpdir(), 'vscode-zsh');
234-
await fs.mkdir(zdotdir, { recursive: true });
235-
const source = path.join(path.dirname(FileAccess.asFileUri('', require).fsPath), 'out/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh');
236-
// TODO: Does filesToCopy make this unnecessary now?
237-
try {
238-
await fs.copyFile(source, path.join(zdotdir, '.zshrc'));
239-
} catch {
240-
// Swallow error, this should only happen when multiple users are on the same
241-
// machine. Since the shell integration scripts rarely change, plus the other user
242-
// should be using the same version of the server in this case, assume the script is
243-
// fine if copy fails and swallow the error.
244-
}
245-
this._ptyOptions.env = this._ptyOptions.env || {};
246-
this._ptyOptions.env['ZDOTDIR'] = zdotdir;
247-
delete this._ptyOptions.env['_ZDOTDIR'];
248-
}
249-
250231
try {
251232
await this.setupPtyProcess(this.shellLaunchConfig, this._ptyOptions, injection);
252233
return undefined;

0 commit comments

Comments
 (0)