fixed #4794 - env var expansion in profiles

上级 5c976948
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
button.btn.btn-secondary((click)='removeEnvironmentVar(pair.key)') button.btn.btn-secondary((click)='removeEnvironmentVar(pair.key)')
i.fas.fa-fw.fa-trash i.fas.fa-fw.fa-trash
button.btn.btn-secondary((click)='addEnvironmentVar()') .d-flex
i.fas.fa-plus.mr-2 button.btn.btn-secondary((click)='addEnvironmentVar()')
span Add i.fas.fa-plus.mr-2
span Add
.ml-auto
.text-muted Substitutions allowed.
.d-flex.ml-1(*ngIf='shouldShowExample()')
.text-muted Example:
a.ml-1((click)='addExample()', href='#') extend PATH
...@@ -44,4 +44,13 @@ export class EnvironmentEditorComponent { ...@@ -44,4 +44,13 @@ export class EnvironmentEditorComponent {
this.emitUpdate() this.emitUpdate()
} }
shouldShowExample (): boolean {
return !this.vars.find(v => v.key.toLowerCase() === 'path')
}
addExample (): void {
const value = process.platform === 'win32' ? 'C:\\Program Files\\Custom:%PATH%' : '/opt/custom:$PATH'
this.vars.push({ key: 'PATH', value })
this.emitUpdate()
}
} }
...@@ -95,6 +95,21 @@ function mergeEnv (...envs) { ...@@ -95,6 +95,21 @@ function mergeEnv (...envs) {
return result return result
} }
function substituteEnv (env: Record<string, string>) {
env = { ...env }
const pattern = process.platform === 'win32' ? /%(\w+)%/g : /\$(\w+)\b/g
for (const [key, value] of Object.entries(env)) {
env[key] = value.replace(pattern, function (substring, p1) {
if (process.platform === 'win32') {
return Object.entries(process.env).find(x => x[0].toLowerCase() === p1.toLowerCase())?.[1] ?? ''
} else {
return process.env[p1] ?? ''
}
})
}
return env
}
/** @hidden */ /** @hidden */
export class Session extends BaseSession { export class Session extends BaseSession {
private pty: PTYProxy|null = null private pty: PTYProxy|null = null
...@@ -128,7 +143,7 @@ export class Session extends BaseSession { ...@@ -128,7 +143,7 @@ export class Session extends BaseSession {
TERM: 'xterm-256color', TERM: 'xterm-256color',
TERM_PROGRAM: 'Tabby', TERM_PROGRAM: 'Tabby',
}, },
options.env, substituteEnv(options.env ?? {}),
this.config.store.terminal.environment || {}, this.config.store.terminal.environment || {},
) )
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册