mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-28 21:24:38 +00:00
hopefully fixed #2
This commit is contained in:
@@ -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 { 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 { SessionsService } from './services/sessions.service'
|
||||||
|
import { ShellsService } from './services/shells.service'
|
||||||
import { TerminalTabComponent } from './components/terminalTab.component'
|
import { TerminalTabComponent } from './components/terminalTab.component'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -13,8 +11,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
|||||||
private app: AppService,
|
private app: AppService,
|
||||||
private sessions: SessionsService,
|
private sessions: SessionsService,
|
||||||
private config: ConfigService,
|
private config: ConfigService,
|
||||||
private electron: ElectronService,
|
private shells: ShellsService,
|
||||||
private hostApp: HostAppService,
|
|
||||||
hotkeys: HotkeysService,
|
hotkeys: HotkeysService,
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
@@ -32,35 +29,11 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
|||||||
}
|
}
|
||||||
let command = this.config.store.terminal.shell
|
let command = this.config.store.terminal.shell
|
||||||
let args = []
|
let args = []
|
||||||
// TODO move this?
|
|
||||||
if (command === '~clink~') {
|
if (command === '~clink~') {
|
||||||
command = 'cmd.exe'
|
({ command, args } = this.shells.getClinkOptions())
|
||||||
args = [
|
|
||||||
'/k',
|
|
||||||
path.join(
|
|
||||||
path.dirname(this.electron.app.getPath('exe')),
|
|
||||||
(process.platform === 'darwin') ? '../Resources' : 'resources',
|
|
||||||
'clink',
|
|
||||||
`clink_${process.arch}.exe`,
|
|
||||||
),
|
|
||||||
'inject',
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
if (command === '~default-shell~') {
|
if (command === '~default-shell~') {
|
||||||
if (this.hostApp.platform === Platform.Linux) {
|
command = await this.shells.getDefaultShell()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let sessionOptions = await this.sessions.prepareNewSession({ command, args, cwd })
|
let sessionOptions = await this.sessions.prepareNewSession({ command, args, cwd })
|
||||||
this.app.openNewTab(
|
this.app.openNewTab(
|
||||||
|
@@ -11,6 +11,7 @@ import { TerminalSettingsTabComponent } from './components/terminalSettingsTab.c
|
|||||||
import { ColorPickerComponent } from './components/colorPicker.component'
|
import { ColorPickerComponent } from './components/colorPicker.component'
|
||||||
|
|
||||||
import { SessionsService } from './services/sessions.service'
|
import { SessionsService } from './services/sessions.service'
|
||||||
|
import { ShellsService } from './services/shells.service'
|
||||||
|
|
||||||
import { ScreenPersistenceProvider } from './persistenceProviders'
|
import { ScreenPersistenceProvider } from './persistenceProviders'
|
||||||
import { ButtonProvider } from './buttonProvider'
|
import { ButtonProvider } from './buttonProvider'
|
||||||
@@ -31,6 +32,7 @@ import { hterm } from './hterm'
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
SessionsService,
|
SessionsService,
|
||||||
|
ShellsService,
|
||||||
ScreenPersistenceProvider,
|
ScreenPersistenceProvider,
|
||||||
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },
|
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },
|
||||||
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
|
{ provide: TabRecoveryProvider, useClass: RecoveryProvider, multi: true },
|
||||||
|
58
terminus-terminal/src/services/shells.service.ts
Normal file
58
terminus-terminal/src/services/shells.service.ts
Normal 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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user