https://github.com/sindresorhus/shell-env
Get environment variables from the shell
https://github.com/sindresorhus/shell-env
Last synced: about 1 month ago
JSON representation
Get environment variables from the shell
- Host: GitHub
- URL: https://github.com/sindresorhus/shell-env
- Owner: sindresorhus
- License: mit
- Created: 2016-01-29T02:22:51.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2026-01-14T15:36:26.000Z (about 2 months ago)
- Last Synced: 2026-01-29T07:21:21.325Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 85
- Watchers: 3
- Forks: 20
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-starred-test - sindresorhus/shell-env - Get environment variables from the shell (JavaScript)
README
# shell-env
> Get [environment variables](https://en.wikipedia.org/wiki/Environment_variable) from the [shell](https://en.wikipedia.org/wiki/Shell_(computing))
Especially useful for Electron apps as GUI apps on macOS doesn't inherit the environment variables defined in your dotfiles *(.bash_profile/.zshrc/etc)*.
## Install
```sh
npm install shell-env
```
## Usage
```js
import {shellEnv} from 'shell-env';
console.log(await shellEnv());
//=> {TERM_PROGRAM: 'Apple_Terminal', SHELL: '/bin/zsh', ...}
console.log(await shellEnv('/bin/bash'));
//=> {TERM_PROGRAM: 'iTerm.app', SHELL: '/bin/zsh', ...}
```
## API
> [!NOTE]
> For Bash, it reads [`.bash_profile`, but not `.bashrc`](https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc).
> [!NOTE]
> If your default shell is a non-POSIX shell (e.g., Nushell), it will fall back to `/bin/zsh` or `/bin/bash`.
> [!NOTE]
> It disables the oh-my-zsh tmux plugin auto-start by setting `ZSH_TMUX_AUTOSTARTED` and `ZSH_TMUX_AUTOSTART=false` so the shell does not launch tmux while capturing environment variables.
### shellEnv(shell?)
Return a promise for the environment variables.
### shellEnvSync(shell?)
Returns the environment variables.
#### shell
Type: `string`\
Default: [User default shell](https://github.com/sindresorhus/default-shell)
Shell to read the environment variables from.
## Related
- [shell-path](https://github.com/sindresorhus/shell-path) - Get the $PATH from the shell
- [fix-path](https://github.com/sindresorhus/fix-path) - Fix the $PATH on macOS when run from a GUI app
- [shell-history](https://github.com/sindresorhus/shell-history) - Get the command history of the user's shell
## Maintainers
- [Sindre Sorhus](https://sindresorhus.com)
- [@silverwind](https://github.com/silverwind)