Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose shell's environment - zsh #237977

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { assertNoRpc } from '../utils';
disposables.length = 0;
});

function createTerminalAndWaitForShellIntegration(): Promise<{ terminal: Terminal; shellIntegration: TerminalShellIntegration }> {
function createTerminalAndWaitForShellIntegration(shellPath?: string): Promise<{ terminal: Terminal; shellIntegration: TerminalShellIntegration }> {
return new Promise<{ terminal: Terminal; shellIntegration: TerminalShellIntegration }>(resolve => {
disposables.push(window.onDidChangeTerminalShellIntegration(e => {
if (e.terminal === terminal) {
Expand All @@ -41,8 +41,8 @@ import { assertNoRpc } from '../utils';
}
}));
const terminal = platform() === 'win32'
? window.createTerminal()
: window.createTerminal({ shellPath: '/bin/bash' });
? window.createTerminal({ shellPath })
: window.createTerminal({ shellPath: shellPath ?? '/bin/bash' });
terminal.show();
});
}
Expand Down Expand Up @@ -102,6 +102,20 @@ import { assertNoRpc } from '../utils';
ok(shellIntegration.env.PATH);
ok(shellIntegration.env.PATH.length > 0, 'env.PATH should have a length greater than 0');
});

test.skip('Test if zsh env is set', async () => {
const { shellIntegration } = await createTerminalAndWaitForShellIntegration('/bin/zsh');
await new Promise<void>(r => {
disposables.push(window.onDidChangeTerminalShellIntegration(e => {
if (e.shellIntegration.env) {
r();
}
}));
});
ok(shellIntegration.env);
ok(shellIntegration.env.PATH);
ok(shellIntegration.env.PATH.length > 0, 'env.PATH should have a length greater than 0');
});
}

test('execution events should fire in order when a command runs', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/terminal/node/terminalEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export function getShellIntegrationInjection(
source: path.join(appRoot, 'out/vs/workbench/contrib/terminal/common/scripts/shellIntegration-login.zsh'),
dest: path.join(zdotdir, '.zlogin')
});
envMixin['VSCODE_STABLE'] = productService.quality === 'stable' ? '1' : '0';
return { newArgs, envMixin, filesToCopy };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ suite('platform - terminalEnvironment', () => {
/.+\/out\/vs\/workbench\/contrib\/terminal\/common\/scripts\/shellIntegration-login.zsh/
];
function assertIsEnabled(result: IShellIntegrationConfigInjection, globalZdotdir = homedir()) {
strictEqual(Object.keys(result.envMixin!).length, 3);
ok(result.envMixin!['ZDOTDIR']?.match(expectedDir));
strictEqual(result.envMixin!['USER_ZDOTDIR'], globalZdotdir);
ok(result.envMixin!['VSCODE_INJECTION']?.match('1'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ __vsc_escape_value() {
out+="$token"
done

builtin print -r "$out"
builtin print -r -- "$out"
}

__vsc_in_command_execution="1"
Expand All @@ -99,6 +99,10 @@ __vsc_current_command=""
__vsc_nonce="$VSCODE_NONCE"
unset VSCODE_NONCE

# Some features should only work in Insiders
__vsc_stable="$VSCODE_STABLE"
unset VSCODE_STABLE

__vsc_prompt_start() {
builtin printf '\e]633;A\a'
}
Expand All @@ -111,6 +115,17 @@ __vsc_update_cwd() {
builtin printf '\e]633;P;Cwd=%s\a' "$(__vsc_escape_value "${PWD}")"
}

__vsc_update_env() {
builtin printf '\e]633;EnvSingleStart;%s;\a' $__vsc_nonce
for var in ${(k)parameters}; do
if printenv "$var" >/dev/null 2>&1; then
value=$(builtin printf '%s' "${(P)var}")
builtin printf '\e]633;EnvSingleEntry;%s;%s;%s\a' "$var" "$(__vsc_escape_value "$value")" $__vsc_nonce
fi
done
builtin printf '\e]633;EnvSingleEnd;%s;\a' $__vsc_nonce
}

__vsc_command_output_start() {
builtin printf '\e]633;E;%s;%s\a' "$(__vsc_escape_value "${__vsc_current_command}")" $__vsc_nonce
builtin printf '\e]633;C\a'
Expand Down Expand Up @@ -139,6 +154,10 @@ __vsc_command_complete() {
builtin printf '\e]633;D;%s\a' "$__vsc_status"
fi
__vsc_update_cwd

if [[ "$__vsc_stable" == "0" ]]; then
__vsc_update_env
fi
}

if [[ -o NOUNSET ]]; then
Expand Down Expand Up @@ -173,6 +192,10 @@ __vsc_precmd() {
# non null
__vsc_update_prompt
fi

if [[ "$__vsc_stable" == "0" ]]; then
__vsc_update_env
fi
}

__vsc_preexec() {
Expand Down
Loading