-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathshell.js
More file actions
65 lines (54 loc) · 1.64 KB
/
Copy pathshell.js
File metadata and controls
65 lines (54 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
const os = require('os');
const path = require('path');
const _ = require('lodash');
const userShell = () => {
const {env} = process;
if (process.platform === 'win32') {
// If shell exists then grab that right away
if (env.SHELL) return env.SHELL;
// If we are on MING64 then return bash.exe
if (env.MSYSTEM === 'MINGW64') return 'bash.exe';
// Finally fallback to COMSPEC
return env.COMSPEC || 'cmd.exe';
}
const {shell} = os.userInfo();
if (shell) return shell;
if (process.platform === 'darwin') {
return env.SHELL || '/bin/zsh';
}
return env.SHELL || '/bin/sh';
};
module.exports = (shell = userShell()) => {
// Get some basic information about our thing
const data = {binary: shell, name: path.parse(shell).name, extension: '.sh'};
// Return helpful data about our shell
switch (data.name) {
case 'bash':
return _.assign(data, {args: ['--noprofile', '--norc', '-eo', 'pipefail', '{0}']});
case 'cmd':
return _.assign(data, {
binary: 'cmd.exe',
args: ['/D', '/E:ON', '/V:OFF', '/S', '/C', 'CALL', '{0}'],
extension: '.cmd',
});
case 'pwsh':
return _.assign(data, {
binary: 'pwsh.exe',
args: ['-command', '.', '{0}'],
extension: '.ps1',
});
case 'powershell':
return _.assign(data, {
binary: 'powershell.exe',
args: ['-command', '.', '{0}'],
extension: '.ps1',
});
case 'sh':
return _.assign(data, {args: ['-e', '{0}']});
case 'zsh':
return _.assign(data, {args: ['--norcs', '-eo', 'pipefail', '{0}']});
default:
return {binary: 'sh', name: 'sh', args: ['-e', '{0}'], extension: '.sh'};
}
};