Permalink
Browse files

Add osenv.shell()

  • Loading branch information...
1 parent 87f56bb commit c5f85ce9f8d577c50fbb6f7f7fb2b9aade7bd212 @isaacs isaacs committed Jun 18, 2012
Showing with 23 additions and 0 deletions.
  1. +5 −0 README.md
  2. +4 −0 osenv.js
  3. +7 −0 test/unix.js
  4. +7 −0 test/windows.js
View
@@ -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'.
View
@@ -74,3 +74,7 @@ memo('editor', function () {
(isWindows ? 'notepad.exe' : 'vi')
})
+memo('shell', function () {
+ return isWindows ? process.env.ComSpec || 'cmd'
+ : process.env.SHELL || 'bash'
+})
View
@@ -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()
})
View
@@ -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()
})

0 comments on commit c5f85ce

Please sign in to comment.