-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathzshEnvs.ts
More file actions
52 lines (47 loc) · 2.06 KB
/
zshEnvs.ts
File metadata and controls
52 lines (47 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { EnvironmentVariableCollection } from 'vscode';
import { PythonEnvironment } from '../../../../api';
import { traceError } from '../../../../common/logging';
import { ShellConstants } from '../../../common/shellConstants';
import { getShellActivationCommand, getShellCommandAsString } from '../common/shellUtils';
import { ShellEnvsProvider } from '../startupProvider';
import { ZSH_ENV_KEY } from './zshConstants';
export class ZshEnvsProvider implements ShellEnvsProvider {
readonly shellType: string = ShellConstants.ZSH;
updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): void {
try {
const zshActivation = getShellActivationCommand(this.shellType, env);
if (zshActivation) {
const command = getShellCommandAsString(this.shellType, zshActivation);
const v = collection.get(ZSH_ENV_KEY);
if (v?.value === command) {
return;
}
collection.replace(ZSH_ENV_KEY, command);
} else {
collection.delete(ZSH_ENV_KEY);
}
} catch (err) {
traceError('Failed to update env variables for zsh', err);
collection.delete(ZSH_ENV_KEY);
}
}
removeEnvVariables(collection: EnvironmentVariableCollection): void {
collection.delete(ZSH_ENV_KEY);
}
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
if (!env) {
return new Map([[ZSH_ENV_KEY, undefined]]);
}
try {
const zshActivation = getShellActivationCommand(this.shellType, env);
if (zshActivation) {
const command = getShellCommandAsString(this.shellType, zshActivation);
return new Map([[ZSH_ENV_KEY, command]]);
}
return undefined;
} catch (err) {
traceError('Failed to get env variables for zsh', err);
return undefined;
}
}
}