mirror of
https://github.com/Eugeny/tabby
synced 2024-12-14 15:22:40 +00:00
use user's default shell (#2)
This commit is contained in:
parent
1e1d48a5f8
commit
bf8bb7ee80
3 changed files with 26 additions and 6 deletions
|
@ -1,6 +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 } from 'terminus-core'
|
||||
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService, ConfigService, ElectronService, HostAppService, Platform } from 'terminus-core'
|
||||
|
||||
import { SessionsService } from './services/sessions.service'
|
||||
import { TerminalTabComponent } from './components/terminalTab.component'
|
||||
|
@ -12,6 +14,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
|||
private sessions: SessionsService,
|
||||
private config: ConfigService,
|
||||
private electron: ElectronService,
|
||||
private hostApp: HostAppService,
|
||||
hotkeys: HotkeysService,
|
||||
) {
|
||||
super()
|
||||
|
@ -43,6 +46,22 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
|||
'inject',
|
||||
]
|
||||
}
|
||||
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(':')[5]
|
||||
}
|
||||
}
|
||||
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 })
|
||||
this.app.openNewTab(
|
||||
TerminalTabComponent,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Observable } from 'rxjs'
|
||||
import * as fs from 'fs-promise'
|
||||
import * as fs from 'mz/fs'
|
||||
import * as path from 'path'
|
||||
import { exec } from 'mz/child_process'
|
||||
const equal = require('deep-equal')
|
||||
|
@ -97,11 +97,12 @@ export class TerminalSettingsTabComponent {
|
|||
}
|
||||
}
|
||||
if (this.hostApp.platform === Platform.Linux || this.hostApp.platform === Platform.macOS) {
|
||||
this.shells = (await fs.readFile('/etc/shells', 'utf-8'))
|
||||
this.shells = [{ name: 'Default shell', command: '~default-shell~' }]
|
||||
this.shells = this.shells.concat((await fs.readFile('/etc/shells', { encoding: 'utf-8' }))
|
||||
.split('\n')
|
||||
.map(x => x.trim())
|
||||
.filter(x => x && !x.startsWith('#'))
|
||||
.map(x => ({ name: x, command: x }))
|
||||
.map(x => ({ name: x, command: x })))
|
||||
}
|
||||
this.colorSchemes = (await Promise.all(this.colorSchemeProviders.map(x => x.getSchemes()))).reduce((a, b) => a.concat(b))
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ export class TerminalConfigProvider extends ConfigProvider {
|
|||
[Platform.macOS]: {
|
||||
terminal: {
|
||||
font: 'Menlo',
|
||||
shell: '/bin/zsh',
|
||||
shell: '~default-shell~',
|
||||
},
|
||||
hotkeys: {
|
||||
'new-tab': [
|
||||
|
@ -67,7 +67,7 @@ export class TerminalConfigProvider extends ConfigProvider {
|
|||
[Platform.Linux]: {
|
||||
terminal: {
|
||||
font: 'Liberation Mono',
|
||||
shell: '/bin/bash',
|
||||
shell: '~default-shell~',
|
||||
},
|
||||
hotkeys: {
|
||||
'new-tab': [
|
||||
|
|
Loading…
Reference in a new issue