提交 7566bcaa 编写于 作者: E Eugene Pankov

custom environment vars (fixes #346)

上级 4682ef72
......@@ -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
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()
}
}
......@@ -48,7 +48,8 @@ export class TerminalConfigProvider extends ConfigProvider {
'#ffffff',
]
},
customColorSchemes: []
customColorSchemes: [],
environment: {},
},
}
......
......@@ -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({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册