Skip to content

Commit

Permalink
Fix fish shell integration execution order
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-n committed Sep 23, 2024
1 parent 10a8649 commit 8109d63
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/vs/platform/terminal/node/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function getShellIntegrationInjection(
} else if (shell === 'bash.exe') {
if (!originalArgs || originalArgs.length === 0) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Bash);
} else if (areZshBashLoginArgs(originalArgs)) {
} else if (areZshBashFishLoginArgs(originalArgs)) {
envMixin['VSCODE_SHELL_LOGIN'] = '1';
addEnvMixinPathPrefix(options, envMixin);
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Bash);
Expand All @@ -187,7 +187,7 @@ export function getShellIntegrationInjection(
case 'bash': {
if (!originalArgs || originalArgs.length === 0) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Bash);
} else if (areZshBashLoginArgs(originalArgs)) {
} else if (areZshBashFishLoginArgs(originalArgs)) {
envMixin['VSCODE_SHELL_LOGIN'] = '1';
addEnvMixinPathPrefix(options, envMixin);
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Bash);
Expand All @@ -201,13 +201,20 @@ export function getShellIntegrationInjection(
return { newArgs, envMixin };
}
case 'fish': {
// The injection mechanism used for fish is to add a custom dir to $XDG_DATA_DIRS which
// is similar to $ZDOTDIR in zsh but contains a list of directories to run from.
const oldDataDirs = env?.XDG_DATA_DIRS ?? '/usr/local/share:/usr/share';
const newDataDir = path.join(appRoot, 'out/vs/workbench/contrib/terminal/common/scripts/fish_xdg_data');
envMixin['XDG_DATA_DIRS'] = `${oldDataDirs}:${newDataDir}`;
addEnvMixinPathPrefix(options, envMixin);
return { newArgs: undefined, envMixin };
if (!originalArgs || originalArgs.length === 0) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Fish);
} else if (areZshBashFishLoginArgs(originalArgs)) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.FishLogin);
addEnvMixinPathPrefix(options, envMixin);
} else if (originalArgs === shellIntegrationArgs.get(ShellIntegrationExecutable.Fish) || originalArgs === shellIntegrationArgs.get(ShellIntegrationExecutable.FishLogin)) {
newArgs = originalArgs;
}
if (!newArgs) {
return undefined;
}
newArgs = [...newArgs]; // Shallow clone the array to avoid setting the default array
newArgs[newArgs.length - 1] = format(newArgs[newArgs.length - 1], appRoot);
return { newArgs, envMixin };
}
case 'pwsh': {
if (!originalArgs || arePwshImpliedArgs(originalArgs)) {
Expand All @@ -229,7 +236,7 @@ export function getShellIntegrationInjection(
case 'zsh': {
if (!originalArgs || originalArgs.length === 0) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.Zsh);
} else if (areZshBashLoginArgs(originalArgs)) {
} else if (areZshBashFishLoginArgs(originalArgs)) {
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.ZshLogin);
addEnvMixinPathPrefix(options, envMixin);
} else if (originalArgs === shellIntegrationArgs.get(ShellIntegrationExecutable.Zsh) || originalArgs === shellIntegrationArgs.get(ShellIntegrationExecutable.ZshLogin)) {
Expand Down Expand Up @@ -316,7 +323,9 @@ enum ShellIntegrationExecutable {
PwshLogin = 'pwsh-login',
Zsh = 'zsh',
ZshLogin = 'zsh-login',
Bash = 'bash'
Bash = 'bash',
Fish = 'fish',
FishLogin = 'fish-login',
}

const shellIntegrationArgs: Map<ShellIntegrationExecutable, string[]> = new Map();
Expand All @@ -328,6 +337,8 @@ shellIntegrationArgs.set(ShellIntegrationExecutable.PwshLogin, ['-l', '-noexit',
shellIntegrationArgs.set(ShellIntegrationExecutable.Zsh, ['-i']);
shellIntegrationArgs.set(ShellIntegrationExecutable.ZshLogin, ['-il']);
shellIntegrationArgs.set(ShellIntegrationExecutable.Bash, ['--init-file', '{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration-bash.sh']);
shellIntegrationArgs.set(ShellIntegrationExecutable.Fish, ['--init-command', '. {0}/out/vs/workbench/contrib/terminal/common/scripts/fish_xdg_data/fish/vendor_conf.d/shellIntegration.fish']);
shellIntegrationArgs.set(ShellIntegrationExecutable.FishLogin, ['-l', '--init-command', '. {0}/out/vs/workbench/contrib/terminal/common/scripts/fish_xdg_data/fish/vendor_conf.d/shellIntegration.fish']);
const pwshLoginArgs = ['-login', '-l'];
const shLoginArgs = ['--login', '-l'];
const shInteractiveArgs = ['-i', '--interactive'];
Expand All @@ -352,7 +363,7 @@ function arePwshImpliedArgs(originalArgs: string | string[]): boolean {
}
}

function areZshBashLoginArgs(originalArgs: string | string[]): boolean {
function areZshBashFishLoginArgs(originalArgs: string | string[]): boolean {
if (typeof originalArgs !== 'string') {
originalArgs = originalArgs.filter(arg => !shInteractiveArgs.includes(arg.toLowerCase()));
}
Expand Down

0 comments on commit 8109d63

Please sign in to comment.