From d2193ddfb79af2c31c78e10c894c308091fe54ed Mon Sep 17 00:00:00 2001 From: aminya Date: Mon, 27 Jul 2020 17:27:10 -0500 Subject: [PATCH] set start command asyncronously --- src/config.js | 3 +-- src/utils.js | 20 +++++++++++++++----- src/x-terminal.js | 5 ++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/config.js b/src/config.js index 92fa3dd0..c5e2b26f 100644 --- a/src/config.js +++ b/src/config.js @@ -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, diff --git a/src/utils.js b/src/utils.js index 48276aef..0bd22f46 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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) { @@ -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) } diff --git a/src/x-terminal.js b/src/x-terminal.js index 83d4206c..a351864a 100644 --- a/src/x-terminal.js +++ b/src/x-terminal.js @@ -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' @@ -55,6 +55,9 @@ class XTerminalSingleton { } activate (state) { + // set start command asyncronously + setShellStartCommand() + // Load profiles configuration. this.profilesSingleton = XTerminalProfilesSingleton.instance