get shell integration to work for zsh (#143305)

This commit is contained in:
Megan Rogge 2022-02-17 19:30:05 -06:00 committed by GitHub
parent 7be5b48a14
commit 7181933eab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 6 deletions

View file

@ -76,7 +76,7 @@ const serverResources = [
// Terminal shell integration
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-zsh.sh',
'out-build/vs/workbench/contrib/terminal/browser/media/.zshrc',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1',
'!**/test/**'

View file

@ -1,3 +1,5 @@
autoload -Uz add-zsh-hook
IN_COMMAND_EXECUTION="1"
prompt_start() {
printf "\033]633;A\007"
@ -47,8 +49,8 @@ preexec() {
IN_COMMAND_EXECUTION="1"
command_output_start
}
precmd_functions+=($precmd_functions precmd)
preexec_functions+=($preexec_functions preexec)
add-zsh-hook precmd precmd
add-zsh-hook preexec preexec
# Show the welcome message
if [ -z "${VSCODE_SHELL_HIDE_WELCOME-}" ]; then

View file

@ -273,6 +273,10 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
shellLaunchConfig.env = shellLaunchConfig.env || {} as IProcessEnvironment;
shellLaunchConfig.env['VSCODE_SHELL_LOGIN'] = '1';
}
if (env?.['ZDOTDIR']) {
shellLaunchConfig.env = shellLaunchConfig.env || {} as IProcessEnvironment;
shellLaunchConfig.env['ZDOTDIR'] = env['ZDOTDIR'].replace('${execInstallFolder}', remoteEnv.appRoot.fsPath);
}
newProcess = await backend.createProcess(
shellLaunchConfig,
@ -451,6 +455,13 @@ export class TerminalProcessManager extends Disposable implements ITerminalProce
const shellIntegration = terminalEnvironment.injectShellIntegrationArgs(this._logService, this._configurationService, env, this._configHelper.config.shellIntegration?.enabled || false, shellLaunchConfig, OS);
if (shellIntegration.enableShellIntegration) {
shellLaunchConfig.args = shellIntegration.args;
if (env?.['ZDOTDIR']) {
shellLaunchConfig.env = shellLaunchConfig.env || {} as IProcessEnvironment;
const activeWorkspaceRootUri = this._historyService.getLastActiveWorkspaceRoot(Schemas.file);
const lastActiveWorkspaceRoot = activeWorkspaceRootUri ? withNullAsUndefined(this._workspaceContextService.getWorkspaceFolder(activeWorkspaceRootUri)) : undefined;
const resolved = await this._configurationResolverService.resolveAsync(lastActiveWorkspaceRoot, env['ZDOTDIR']);
env['ZDOTDIR'] = resolved;
}
// Always resolve the injected arguments on local processes
await this._terminalProfileResolverService.resolveShellLaunchConfig(shellLaunchConfig, {
remoteAuthority: undefined,

View file

@ -416,8 +416,8 @@ shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwsh, ['-noexit', ' -
shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwshLogin, ['-l', '-noexit', ' -command', '. \"${execInstallFolder}\\out\\vs\\workbench\\contrib\\terminal\\browser\\media\\shellIntegration.ps1\"{0}']);
shellIntegrationArgs.set(ShellIntegrationExecutable.Pwsh, ['-noexit', '-command', '. "${execInstallFolder}/out/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1"{0}']);
shellIntegrationArgs.set(ShellIntegrationExecutable.PwshLogin, ['-l', '-noexit', '-command', '. "${execInstallFolder}/out/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1"']);
shellIntegrationArgs.set(ShellIntegrationExecutable.Zsh, ['-c', '"${execInstallFolder}/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-zsh.sh"; zsh -i']);
shellIntegrationArgs.set(ShellIntegrationExecutable.ZshLogin, ['-c', '"${execInstallFolder}/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-zsh.sh"; zsh -il']);
shellIntegrationArgs.set(ShellIntegrationExecutable.Zsh, ['-i']);
shellIntegrationArgs.set(ShellIntegrationExecutable.ZshLogin, ['-il']);
shellIntegrationArgs.set(ShellIntegrationExecutable.Bash, ['--init-file', '${execInstallFolder}/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh']);
const loginArgs = ['-login', '-l'];
const pwshImpliedArgs = ['-nol', '-nologo'];
@ -491,7 +491,12 @@ export function injectShellIntegrationArgs(
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Zsh);
} else if (areZshBashLoginArgs(originalArgs)) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.ZshLogin);
} else if (originalArgs === shellIntegrationArgs.get(ShellIntegrationExecutable.Zsh) || originalArgs === shellIntegrationArgs.get(ShellIntegrationExecutable.ZshLogin)) {
newArgs = originalArgs;
}
// Set the ZDOTDIR to be the dir of the shell integration script so that it runs
// as a .zshrc file and the autoload hook will work and set precmd and preexec correctly
env['ZDOTDIR'] = '${execInstallFolder}/out/vs/workbench/contrib/terminal/browser/media';
const showWelcome = configurationService.getValue(TerminalSettingId.ShellIntegrationShowWelcome);
if (!showWelcome) {
env['VSCODE_SHELL_HIDE_WELCOME'] = '1';

View file

@ -90,7 +90,10 @@ suite('Workbench - TerminalProcessManager', () => {
await configurationService.setUserConfiguration('terminal', {
integrated: {
fontFamily: 'bar',
enablePersistentSessions: true
enablePersistentSessions: true,
shellIntegration: {
enabled: false
}
}
});
instantiationService.stub(IConfigurationService, configurationService);