From c5f85ce9f8d577c50fbb6f7f7fb2b9aade7bd212 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sun, 17 Jun 2012 17:50:23 -0700 Subject: [PATCH] Add osenv.shell() --- README.md | 5 +++++ osenv.js | 4 ++++ test/unix.js | 7 +++++++ test/windows.js | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/README.md b/README.md index 0400078..08fd900 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,8 @@ executables. Return the executable name of the editor program. This uses the EDITOR and VISUAL environment variables, and falls back to `vi` on Unix, or `notepad.exe` on Windows. + +## osenv.shell() + +The SHELL on Unix, which Windows calls the ComSpec. Defaults to 'bash' +or 'cmd'. diff --git a/osenv.js b/osenv.js index 0385bf9..e3367a7 100644 --- a/osenv.js +++ b/osenv.js @@ -74,3 +74,7 @@ memo('editor', function () { (isWindows ? 'notepad.exe' : 'vi') }) +memo('shell', function () { + return isWindows ? process.env.ComSpec || 'cmd' + : process.env.SHELL || 'bash' +}) diff --git a/test/unix.js b/test/unix.js index e3fc3f5..b72eb0b 100644 --- a/test/unix.js +++ b/test/unix.js @@ -21,6 +21,7 @@ process.env.PATH = '/opt/local/bin:/usr/local/bin:/usr/bin/:bin' process.env.PS1 = '(o_o) $ ' process.env.EDITOR = 'edit' process.env.VISUAL = 'visualedit' +process.env.SHELL = 'zsh' tap.test('basic unix sanity test', function (t) { @@ -65,5 +66,11 @@ tap.test('basic unix sanity test', function (t) { var osenv = require('../osenv.js') t.equal(osenv.editor(), 'vi') + t.equal(osenv.shell(), 'zsh') + process.env.SHELL = '' + delete require.cache[require.resolve('../osenv.js')] + var osenv = require('../osenv.js') + t.equal(osenv.shell(), 'bash') + t.end() }) diff --git a/test/windows.js b/test/windows.js index 945d49f..dd3fe80 100644 --- a/test/windows.js +++ b/test/windows.js @@ -24,6 +24,7 @@ process.env.Path = 'C:\\Program Files\\;C:\\Binary Stuff\\bin' process.env.PROMPT = '(o_o) $ ' process.env.EDITOR = 'edit' process.env.VISUAL = 'visualedit' +process.env.ComSpec = 'some-com' tap.test('basic windows sanity test', function (t) { var osenv = require('../osenv.js') @@ -71,5 +72,11 @@ tap.test('basic windows sanity test', function (t) { var osenv = require('../osenv.js') t.equal(osenv.editor(), 'notepad.exe') + t.equal(osenv.shell(), 'some-com') + process.env.ComSpec = '' + delete require.cache[require.resolve('../osenv.js')] + var osenv = require('../osenv.js') + t.equal(osenv.shell(), 'cmd') + t.end() })