git-bash-shell
Use Git Bash as cross-platform shell for Windows
Why
Install
npm install --save git-bash-shell
Please restart your terminal after successful installation.
Usage
-
npm config
These npm config items will be compatible under Windows:
You can edit .npmrc to use a unified terminal:
shell=/bin/bash
script-shell=/bin/sh
-
env
command
In your package.json
file, you can add script prefix env
to compatible with Widnows:
"scripts": {
"posix": "env echo $SHELL",
}
Just run npm run posix
, it will run for Windows and POSIX
-
Node API:
await require('git-bash-shell')();
const spawnSync = require('cross-spawn').sync;
spawnSync('echo $(git --version)', {
shell: '/bin/sh',
stdio: 'inherit',
});
Environment Variables
SHELL
- Default:
/bin/sh
- Type: path
POSIX specific implementations of shell path.