1
1
mirror of https://github.com/Eugeny/tabby.git synced 2024-11-28 05:36:31 +03:00

custom environment vars (fixes #346)

This commit is contained in:
Eugene Pankov 2018-10-25 15:51:46 +02:00
parent 4682ef72a1
commit 7566bcaaac
4 changed files with 51 additions and 2 deletions

View File

@ -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

View File

@ -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()
}
}

View File

@ -48,7 +48,8 @@ export class TerminalConfigProvider extends ConfigProvider {
'#ffffff',
]
},
customColorSchemes: []
customColorSchemes: [],
environment: {},
},
}

View File

@ -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({