diff --git a/terminus-terminal/src/components/shellSettingsTab.component.pug b/terminus-terminal/src/components/shellSettingsTab.component.pug index be8f9fb8f8c71c9c95ed7e1282256a5b543faea6..73484369cdfffc95f55a193ff71cb351ad46464a 100644 --- a/terminus-terminal/src/components/shellSettingsTab.component.pug +++ b/terminus-terminal/src/components/shellSettingsTab.component.pug @@ -51,3 +51,19 @@ h3.mb-3 Shell .input-group-btn button.btn.btn-secondary((click)='pickWorkingDirectory()') i.fa.fa-folder-open + +.form-line + .header + .title Environment + .description Inject additional environment variables + + div + .mb-2.d-flex.align-items-center(*ngFor='let pair of environmentVars') + input.form-control.w-50([(ngModel)]='pair.key', (blur)='saveEnvironment()', placeholder='Variable name') + input.form-control.w-50.mr-1([(ngModel)]='pair.value', (blur)='saveEnvironment()', placeholder='Value') + button.btn.btn-secondary((click)='removeEnvironmentVar(pair.key)') + i.fa.fa-trash-o + + button.btn.btn-secondary((click)='addEnvironmentVar()') + i.fa.fa-plus.mr-2 + span Add diff --git a/terminus-terminal/src/components/shellSettingsTab.component.ts b/terminus-terminal/src/components/shellSettingsTab.component.ts index 107777fabbf4fe4910fc0cf770e35c5185dcd8c3..fb1c0625070dc859f8b876e3f4cdfe2b86bd45d1 100644 --- a/terminus-terminal/src/components/shellSettingsTab.component.ts +++ b/terminus-terminal/src/components/shellSettingsTab.component.ts @@ -1,4 +1,5 @@ import { Component, Inject } from '@angular/core' +import { Subscription } from 'rxjs' import { ConfigService, ElectronService } from 'terminus-core' import { IShell, ShellProvider, SessionPersistenceProvider } from '../api' @@ -9,6 +10,9 @@ export class ShellSettingsTabComponent { shells: IShell[] = [] persistenceProviders: SessionPersistenceProvider[] + environmentVars: {key: string, value: string}[] = [] + private configSubscription: Subscription + constructor ( public config: ConfigService, private electron: ElectronService, @@ -16,12 +20,20 @@ export class ShellSettingsTabComponent { @Inject(SessionPersistenceProvider) persistenceProviders: SessionPersistenceProvider[], ) { this.persistenceProviders = this.config.enabledServices(persistenceProviders).filter(x => x.isAvailable()) + + config.store.terminal.environment = config.store.terminal.environment || {} + this.reloadEnvironment() + this.configSubscription = config.changed$.subscribe(() => this.reloadEnvironment()) } async ngOnInit () { this.shells = (await Promise.all(this.config.enabledServices(this.shellProviders).map(x => x.provide()))).reduce((a, b) => a.concat(b)) } + ngOnDestroy () { + this.configSubscription.unsubscribe() + } + pickWorkingDirectory () { let shell = this.shells.find(x => x.id === this.config.store.terminal.shell) console.log(shell) @@ -33,4 +45,24 @@ export class ShellSettingsTabComponent { this.config.store.terminal.workingDirectory = paths[0] } } + + reloadEnvironment () { + this.environmentVars = Object.entries(this.config.store.terminal.environment).map(([k, v]) => ({ key: k, value: v as string })) + } + + saveEnvironment () { + this.config.store.terminal.environment = {} + for (let pair of this.environmentVars) { + this.config.store.terminal.environment[pair.key] = pair.value + } + } + + addEnvironmentVar () { + this.environmentVars.push({ key: '', value: '' }) + } + + removeEnvironmentVar (key: string) { + this.environmentVars = this.environmentVars.filter(x => x.key !== key) + this.saveEnvironment() + } } diff --git a/terminus-terminal/src/config.ts b/terminus-terminal/src/config.ts index 0fcdc1fa582290afd6171dc39362dbe6671b36ad..6f3f966939831abf1910e99fc67f1bbd83537859 100644 --- a/terminus-terminal/src/config.ts +++ b/terminus-terminal/src/config.ts @@ -48,7 +48,8 @@ export class TerminalConfigProvider extends ConfigProvider { '#ffffff', ] }, - customColorSchemes: [] + customColorSchemes: [], + environment: {}, }, } diff --git a/terminus-terminal/src/services/terminal.service.ts b/terminus-terminal/src/services/terminal.service.ts index 325a4f7687081db8bcc7669f465c2a370599f070..10e179f770ff7926c5eca8821e2ec3abbe4fbd02 100644 --- a/terminus-terminal/src/services/terminal.service.ts +++ b/terminus-terminal/src/services/terminal.service.ts @@ -52,7 +52,7 @@ export class TerminalService { let shells = await this.shells$.toPromise() shell = shells.find(x => x.id === this.config.store.terminal.shell) || shells[0] } - let env: any = Object.assign({}, process.env, shell.env || {}) + let env: any = Object.assign({}, process.env, shell.env || {}, this.config.store.terminal.environment || {}) this.logger.log(`Starting shell ${shell.name}`, shell) let sessionOptions = await this.sessions.prepareNewSession({