Skip to content

Commit

Permalink
Merge pull request #155046 from microsoft/tyriar/si_cli
Browse files Browse the repository at this point in the history
Provide simpler route for activating shell integration
  • Loading branch information
Tyriar authored and jrieken committed Jul 18, 2022
2 parents 7f000ac + 1baeb71 commit c4fb45e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/vs/code/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { chmodSync, existsSync, readFileSync, statSync, truncateSync, unlinkSync
import { homedir, release, tmpdir } from 'os';
import type { ProfilingSession, Target } from 'v8-inspect-profiler';
import { Event } from 'vs/base/common/event';
import { isAbsolute, resolve } from 'vs/base/common/path';
import { isAbsolute, resolve, join } from 'vs/base/common/path';
import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform';
import { randomPort } from 'vs/base/common/ports';
import { isString } from 'vs/base/common/types';
Expand All @@ -24,6 +24,8 @@ import product from 'vs/platform/product/common/product';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { randomPath } from 'vs/base/common/extpath';
import { Utils } from 'vs/platform/profiling/common/profiling';
import { dirname } from 'vs/base/common/resources';
import { FileAccess } from 'vs/base/common/network';

function shouldSpawnCliProcess(argv: NativeParsedArgs): boolean {
return !!argv['install-source']
Expand Down Expand Up @@ -59,6 +61,25 @@ export async function main(argv: string[]): Promise<any> {
console.log(buildVersionMessage(product.version, product.commit));
}

// Shell integration
else if (args['shell-integration']) {
// Silently fail when the terminal is not VS Code's integrated terminal
if (process.env['TERM_PROGRAM'] !== 'vscode') {
return;
}
let file: string;
switch (args['shell-integration']) {
// Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --shell-integration bash)"`
case 'bash': file = 'shellIntegration-bash.sh'; break;
// Usage: `if ($env:TERM_PROGRAM -eq "vscode") { . "$(code --shell-integration pwsh)" }`
case 'pwsh': file = 'shellIntegration.ps1'; break;
// Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --shell-integration zsh)"`
case 'zsh': file = 'shellIntegration-rc.zsh'; break;
default: throw new Error('Error using --shell-integration: Invalid shell type');
}
console.log(join(dirname(FileAccess.asFileUri('', require)).fsPath, 'out', 'vs', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));
}

// Extensions Management
else if (shouldSpawnCliProcess(args)) {
const cli = await new Promise<IMainCli>((resolve, reject) => require(['vs/code/node/cliProcessMain'], resolve, reject));
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/common/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface NativeParsedArgs {
'logsPath'?: string;
'__enable-file-policy'?: boolean;
editSessionId?: string;
'shell-integration'?: string;

// chromium command line args: https://electronjs.org/docs/all#supported-chrome-command-line-switches
'no-proxy-server'?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
'waitMarkerFilePath': { type: 'string' },
'locale': { type: 'string', cat: 'o', args: 'locale', description: localize('locale', "The locale to use (e.g. en-US or zh-TW).") },
'user-data-dir': { type: 'string', cat: 'o', args: 'dir', description: localize('userDataDir', "Specifies the directory that user data is kept in. Can be used to open multiple distinct instances of Code.") },
'shell-integration': { type: 'string', cat: 'o', args: ['bash', 'pwsh', 'zsh'], description: localize('shellIntergation', "Print the shell integration script file path for the specified shell.") },
'help': { type: 'boolean', cat: 'o', alias: 'h', description: localize('help', "Print usage.") },

'extensions-dir': { type: 'string', deprecates: ['extensionHomePath'], cat: 'e', args: 'dir', description: localize('extensionHomePath', "Set the root path for extensions.") },
Expand Down
2 changes: 2 additions & 0 deletions src/vs/server/node/serverEnvironmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const serverOptions: OptionDescriptions<ServerParsedArgs> = {

'help': OPTIONS['help'],
'version': OPTIONS['version'],
'shell-integration': OPTIONS['shell-integration'],

'compatibility': { type: 'string' },

Expand Down Expand Up @@ -193,6 +194,7 @@ export interface ServerParsedArgs {
/* ----- server cli ----- */
help: boolean;
version: boolean;
'shell-integration'?: string;

compatibility: string;

Expand Down

0 comments on commit c4fb45e

Please sign in to comment.