Skip to content

Commit

Permalink
set start command asyncronously
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 27, 2020
1 parent 90f593d commit d2193dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import os from 'os'
import path from 'path'
import { getShellStartCommand } from './utils'

export function resetConfigDefaults () {
return {
command: getShellStartCommand(),
command: process.platform === 'win32' ? (process.env.COMSPEC || 'cmd.exe') : (process.env.SHELL || '/bin/sh'),
args: '[]',
termType: process.env.TERM || 'xterm-256color',
cwd: process.platform === 'win32' ? process.env.USERPROFILE : process.env.HOME,
Expand Down
20 changes: 15 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { sync as whichSync } from 'which'
import which from 'which'

export function clearDiv (div) {
while (div.firstChild) {
Expand Down Expand Up @@ -64,22 +64,32 @@ export function recalculateActive (terminalsSet, active) {
}

// finds the default shell start commmand
export function getShellStartCommand () {
async function getShellStartCommand () {
let shellStartCommand
if (process.platform === 'win32') {
// Windows
try {
shellStartCommand = whichSync('pwsh.exe')
shellStartCommand = await which('pwsh.exe')
return shellStartCommand
} catch (e1) {
try {
shellStartCommand = whichSync('powershell.exe')
shellStartCommand = await which('powershell.exe')
return shellStartCommand
} catch (e2) {
shellStartCommand = process.env.COMSPEC || 'cmd.exe'
return shellStartCommand
}
}
} else {
// Unix
shellStartCommand = process.env.SHELL || '/bin/sh'
return shellStartCommand
}
return shellStartCommand
}

// set start command asyncronously
export async function setShellStartCommand () {
const shellStartCommand = await getShellStartCommand()
console.log(shellStartCommand)
atom.config.set('x-terminal.command', shellStartCommand)
}
5 changes: 4 additions & 1 deletion src/x-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { CompositeDisposable } from 'atom'

import { CONFIG_DATA } from './config'
import { recalculateActive } from './utils'
import { recalculateActive, setShellStartCommand } from './utils'
import { XTerminalElement } from './element'
import { XTerminalModel, isXTerminalModel } from './model'
import { X_TERMINAL_BASE_URI, XTerminalProfilesSingleton } from './profiles'
Expand Down Expand Up @@ -55,6 +55,9 @@ class XTerminalSingleton {
}

activate (state) {
// set start command asyncronously
setShellStartCommand()

// Load profiles configuration.
this.profilesSingleton = XTerminalProfilesSingleton.instance

Expand Down

0 comments on commit d2193dd

Please sign in to comment.