diff --git a/terminus-terminal/src/buttonProvider.ts b/terminus-terminal/src/buttonProvider.ts index 975709b1..b5c89b12 100644 --- a/terminus-terminal/src/buttonProvider.ts +++ b/terminus-terminal/src/buttonProvider.ts @@ -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, diff --git a/terminus-terminal/src/components/terminalSettingsTab.component.ts b/terminus-terminal/src/components/terminalSettingsTab.component.ts index 4d996a9a..8dcfb6d7 100644 --- a/terminus-terminal/src/components/terminalSettingsTab.component.ts +++ b/terminus-terminal/src/components/terminalSettingsTab.component.ts @@ -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)) } diff --git a/terminus-terminal/src/config.ts b/terminus-terminal/src/config.ts index 60851bd0..f657ca91 100644 --- a/terminus-terminal/src/config.ts +++ b/terminus-terminal/src/config.ts @@ -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': [