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
Changes from 1 commit
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
@@ -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) {
@@ -42,7 +42,7 @@ import { assertNoRpc } from '../utils';
}));
const terminal = platform() === 'win32'
? window.createTerminal()
: window.createTerminal({ shellPath: '/bin/bash' });
: window.createTerminal({ shellPath: shellPath ?? '/bin/bash' });
terminal.show();
});
}
@@ -102,8 +102,23 @@ 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 () => {
const { terminal, shellIntegration } = await createTerminalAndWaitForShellIntegration();
const events: string[] = [];
Original file line number Diff line number Diff line change
@@ -111,6 +111,17 @@ __vsc_update_cwd() {
builtin printf '\e]633;P;Cwd=%s\a' "$(__vsc_escape_value "${PWD}")"
}

__vsc_update_env() {
builtin printf '\e]633;EnvStart;%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;EnvEntry;%s;%s;%s\a' "$var" "$(__vsc_escape_value "$value")" $__vsc_nonce
fi
done
builtin printf '\e]633;EnvEnd;%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'
@@ -139,6 +150,8 @@ __vsc_command_complete() {
builtin printf '\e]633;D;%s\a' "$__vsc_status"
fi
__vsc_update_cwd
# Is there stable/insider flag in zsh?
__vsc_update_env
}

if [[ -o NOUNSET ]]; then
@@ -173,6 +186,8 @@ __vsc_precmd() {
# non null
__vsc_update_prompt
fi
# TODO: Is there stable/insider flag in zsh?
__vsc_update_env
}

__vsc_preexec() {