tabby/terminus-terminal/src/shells/linuxDefault.ts

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-07-30 18:58:31 +00:00
import * as fs from 'mz/fs'
import { Injectable } from '@angular/core'
import { HostAppService, Platform, LogService, Logger } from 'terminus-core'
import { ShellProvider, IShell } from '../api'
2019-03-07 01:05:26 +00:00
/** @hidden */
2017-07-30 18:58:31 +00:00
@Injectable()
export class LinuxDefaultShellProvider extends ShellProvider {
private logger: Logger
constructor (
private hostApp: HostAppService,
log: LogService,
) {
super()
this.logger = log.create('linuxDefaultShell')
}
async provide (): Promise<IShell[]> {
if (this.hostApp.platform !== Platform.Linux) {
return []
}
let line = (await fs.readFile('/etc/passwd', { encoding: 'utf-8' }))
.split('\n').find(x => x.startsWith(process.env.LOGNAME + ':'))
if (!line) {
this.logger.warn('Could not detect user shell')
return [{
id: 'default',
name: 'User default',
2019-05-11 19:28:04 +00:00
command: '/bin/sh',
env: {},
2017-07-30 18:58:31 +00:00
}]
} else {
return [{
id: 'default',
name: 'User default',
command: line.split(':')[6],
args: ['--login'],
2019-05-11 19:28:04 +00:00
env: {},
2017-07-30 18:58:31 +00:00
}]
}
}
}