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:
parent
5c976948dd
commit
9f8f2966d9
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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 || {},
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user