hopefully fixed #2

This commit is contained in:
Eugene Pankov 2017-07-05 12:49:01 +02:00
parent f2a8eb92a1
commit c0c2373ed6
3 changed files with 65 additions and 32 deletions

View File

@ -1,10 +1,8 @@
import * as path from 'path'
import { exec } from 'mz/child_process'
import * as fs from 'mz/fs'
import { Injectable } from '@angular/core'
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService, ConfigService, ElectronService, HostAppService, Platform } from 'terminus-core'
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService, ConfigService } from 'terminus-core'
import { SessionsService } from './services/sessions.service'
import { ShellsService } from './services/shells.service'
import { TerminalTabComponent } from './components/terminalTab.component'
@Injectable()
@ -13,8 +11,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
private app: AppService,
private sessions: SessionsService,
private config: ConfigService,
private electron: ElectronService,
private hostApp: HostAppService,
private shells: ShellsService,
hotkeys: HotkeysService,
) {
super()
@ -32,35 +29,11 @@ export class ButtonProvider extends ToolbarButtonProvider {
}
let command = this.config.store.terminal.shell
let args = []
// TODO move this?
if (command === '~clink~') {
command = 'cmd.exe'
args = [
'/k',
path.join(
path.dirname(this.electron.app.getPath('exe')),
(process.platform === 'darwin') ? '../Resources' : 'resources',
'clink',
`clink_${process.arch}.exe`,
),
'inject',
]
({ command, args } = this.shells.getClinkOptions())
}
if (command === '~default-shell~') {
if (this.hostApp.platform === Platform.Linux) {
let line = (await fs.readFile('/etc/passwd', { encoding: 'utf-8' }))
.split('\n').find(x => x.startsWith(process.env.LOGNAME + ':'))
if (!line) {
console.warn('Could not detect user shell')
command = '/bin/sh'
} else {
command = line.split(':')[6]
}
}
if (this.hostApp.platform === Platform.macOS) {
let shellEntry = (await exec(`dscl . -read /Users/${process.env.LOGNAME} UserShell`))[0].toString()
command = shellEntry.split(':')[1].trim()
}
command = await this.shells.getDefaultShell()
}
let sessionOptions = await this.sessions.prepareNewSession({ command, args, cwd })
this.app.openNewTab(

View File

@ -11,6 +11,7 @@ import { TerminalSettingsTabComponent } from './components/terminalSettingsTab.c
import { ColorPickerComponent } from './components/colorPicker.component'
import { SessionsService } from './services/sessions.service'
import { ShellsService } from './services/shells.service'
import { ScreenPersistenceProvider } from './persistenceProviders'
import { ButtonProvider } from './buttonProvider'
@ -31,6 +32,7 @@ import { hterm } from './hterm'
],
providers: [
SessionsService,
ShellsService,
ScreenPersistenceProvider,
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },

View File

@ -0,0 +1,58 @@
import * as path from 'path'
import { exec } from 'mz/child_process'
import * as fs from 'mz/fs'
import { Injectable } from '@angular/core'
import { ElectronService, HostAppService, Platform, Logger, LogService } from 'terminus-core'
@Injectable()
export class ShellsService {
private logger: Logger
constructor (
log: LogService,
private electron: ElectronService,
private hostApp: HostAppService,
) {
this.logger = log.create('shells')
}
getClinkOptions (): { command, args } {
return {
command: 'cmd.exe',
args: [
'/k',
path.join(
path.dirname(this.electron.app.getPath('exe')),
'resources',
'clink',
`clink_${process.arch}.exe`,
),
'inject',
]
}
}
async getDefaultShell (): Promise<string> {
if (this.hostApp.platform === Platform.macOS) {
return this.getDefaultMacOSShell()
} else {
return this.getDefaultLinuxShell()
}
}
async getDefaultMacOSShell (): Promise<string> {
let shellEntry = (await exec(`dscl . -read /Users/${process.env.LOGNAME} UserShell`))[0].toString()
return shellEntry.split(' ')[1].trim()
}
async getDefaultLinuxShell (): Promise<string> {
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 '/bin/sh'
} else {
return line.split(':')[6]
}
}
}