diff --git a/spec/update-process-env-spec.js b/spec/update-process-env-spec.js index 3501bfebf..41c80c842 100644 --- a/spec/update-process-env-spec.js +++ b/spec/update-process-env-spec.js @@ -2,7 +2,7 @@ /* eslint-env jasmine */ import child_process from 'child_process' -import updateProcessEnv from '../src/update-process-env' +import {updateProcessEnv, shellShouldBePatched} from '../src/update-process-env' import dedent from 'dedent' describe('updateProcessEnv(launchEnv)', function () { @@ -84,5 +84,41 @@ describe('updateProcessEnv(launchEnv)', function () { expect(process.env).toEqual({FOO: 'bar'}) }) }) + + describe('shells on osx', function () { + it('shellShouldBePatched() returns the shell when the shell should be patched', function () { + process.platform = 'darwin' + let shellsToTest = new Set([ + '/bin/sh', + '/usr/local/bin/sh', + '/bin/bash', + '/usr/local/bin/bash', + '/bin/zsh', + '/usr/local/bin/zsh', + '/bin/fish', + '/usr/local/bin/fish' + ]) + for (let shell of shellsToTest) { + process.env.SHELL = shell + expect(shellShouldBePatched()).toBe(shell) + } + }) + + it('shellShouldBePatched() returns false when the shell should not be patched', function () { + process.platform = 'darwin' + let shellsToTest = new Set([ + '/bin/unsupported', + '/bin/shh', + '/bin/tcsh', + '/usr/csh' + ]) + for (let shell of shellsToTest) { + process.env.SHELL = shell + let result = shellShouldBePatched() + console.log(result) + expect(result).toBe(false) + } + }) + }) }) }) diff --git a/src/initialize-application-window.coffee b/src/initialize-application-window.coffee index f85207153..9787977e2 100644 --- a/src/initialize-application-window.coffee +++ b/src/initialize-application-window.coffee @@ -1,6 +1,6 @@ # Like sands through the hourglass, so are the days of our lives. module.exports = ({blobStore}) -> - updateProcessEnv = require('./update-process-env') + {updateProcessEnv} = require('./update-process-env') path = require 'path' require './window' {getWindowLoadSettings} = require './window-load-settings-helpers' diff --git a/src/update-process-env.js b/src/update-process-env.js index 63dc601bb..dd9ec6299 100644 --- a/src/update-process-env.js +++ b/src/update-process-env.js @@ -8,7 +8,14 @@ const ENVIRONMENT_VARIABLES_TO_PRESERVE = new Set([ 'ATOM_HOME' ]) -export default function updateProcessEnv (launchEnv) { +const OSX_SHELLS_TO_PATCH = new Set([ + '/sh', + '/bash', + '/zsh', + '/fish' +]) + +function updateProcessEnv (launchEnv) { let envToAssign if (launchEnv && launchEnv.PWD) { envToAssign = launchEnv @@ -33,9 +40,23 @@ export default function updateProcessEnv (launchEnv) { } } -function getEnvFromShell () { +function shellShouldBePatched () { let shell = process.env.SHELL - if (shell && (shell.endsWith('/bash') || shell.endsWith('/sh'))) { + if (!shell) { + return false + } + for (let s of OSX_SHELLS_TO_PATCH) { + if (shell.endsWith(s)) { + return shell + } + } + + return false +} + +function getEnvFromShell () { + let shell = shellShouldBePatched() + if (shell) { let {stdout} = spawnSync(shell, ['-ilc', 'command env'], {encoding: 'utf8'}) if (stdout) { let result = {} @@ -51,3 +72,5 @@ function getEnvFromShell () { } } } + +export default { updateProcessEnv, shellShouldBePatched }