1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-12-23 18:44:20 +03:00

fixed #4794 - env var expansion in profiles

This commit is contained in:
Eugene Pankov 2021-10-23 19:14:33 +02:00
parent 5c976948dd
commit 9f8f2966d9
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4
3 changed files with 35 additions and 4 deletions

View File

@ -8,6 +8,13 @@
button.btn.btn-secondary((click)='removeEnvironmentVar(pair.key)')
i.fas.fa-fw.fa-trash
button.btn.btn-secondary((click)='addEnvironmentVar()')
i.fas.fa-plus.mr-2
span Add
.d-flex
button.btn.btn-secondary((click)='addEnvironmentVar()')
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

View File

@ -44,4 +44,13 @@ export class EnvironmentEditorComponent {
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()
}
}

View File

@ -95,6 +95,21 @@ function mergeEnv (...envs) {
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 */
export class Session extends BaseSession {
private pty: PTYProxy|null = null
@ -128,7 +143,7 @@ export class Session extends BaseSession {
TERM: 'xterm-256color',
TERM_PROGRAM: 'Tabby',
},
options.env,
substituteEnv(options.env ?? {}),
this.config.store.terminal.environment || {},
)