diff --git a/tabby-local/src/components/environmentEditor.component.pug b/tabby-local/src/components/environmentEditor.component.pug index cd804c8a39b8d44c7c2803e9c4aa96f89a5d80b6..222c546262a20f7661c363bd8ef73297dd13bd95 100644 --- a/tabby-local/src/components/environmentEditor.component.pug +++ b/tabby-local/src/components/environmentEditor.component.pug @@ -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 diff --git a/tabby-local/src/components/environmentEditor.component.ts b/tabby-local/src/components/environmentEditor.component.ts index 7eeea06b27da38fc55bd8b72c4616b8ddcf9001e..ed4fe365f207fb50b1eecff2b223db47b41610f4 100644 --- a/tabby-local/src/components/environmentEditor.component.ts +++ b/tabby-local/src/components/environmentEditor.component.ts @@ -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() + } } diff --git a/tabby-local/src/session.ts b/tabby-local/src/session.ts index 5b4639bdef902c3b5d49ed052f0c3b316faa77fc..19fb76180cbf543f4d0354b7791e88cf828d479d 100644 --- a/tabby-local/src/session.ts +++ b/tabby-local/src/session.ts @@ -95,6 +95,21 @@ function mergeEnv (...envs) { return result } +function substituteEnv (env: Record) { + 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 || {}, )