Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Add osenv.shell()
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jun 18, 2012
1 parent 87f56bb commit c5f85ce
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -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'.
4 changes: 4 additions & 0 deletions osenv.js
Expand Up @@ -74,3 +74,7 @@ memo('editor', function () {
(isWindows ? 'notepad.exe' : 'vi')
})

memo('shell', function () {
return isWindows ? process.env.ComSpec || 'cmd'
: process.env.SHELL || 'bash'
})
7 changes: 7 additions & 0 deletions test/unix.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
})
7 changes: 7 additions & 0 deletions test/windows.js
Expand Up @@ -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')
Expand Down Expand Up @@ -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.