├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── index.d.ts ├── index.js ├── index.test-d.ts ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 16 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-node@v2 17 | with: 18 | node-version: ${{ matrix.node-version }} 19 | - run: npm install 20 | - run: npm test 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | The user's default shell. 3 | 4 | @example 5 | ``` 6 | import defaultShell from 'default-shell'; 7 | 8 | // macOS 9 | console.log(defaultShell); 10 | //=> '/bin/zsh' 11 | 12 | // Windows 13 | console.log(defaultShell); 14 | //=> 'C:\\WINDOWS\\system32\\cmd.exe' 15 | ``` 16 | */ 17 | declare const defaultShell: string; 18 | 19 | export default defaultShell; 20 | 21 | /** 22 | This can be useful if the default shell changes at runtime. 23 | 24 | @returns The user's current default shell. 25 | 26 | @example 27 | ``` 28 | import {detectDefaultShell} from 'default-shell'; 29 | 30 | console.log(detectDefaultShell()); 31 | //=> '/bin/zsh' 32 | ``` 33 | */ 34 | export function detectDefaultShell(): string; 35 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import process from 'node:process'; 2 | import {userInfo} from 'node:os'; 3 | 4 | export const detectDefaultShell = () => { 5 | const {env} = process; 6 | 7 | if (process.platform === 'win32') { 8 | return env.COMSPEC || 'cmd.exe'; 9 | } 10 | 11 | try { 12 | const {shell} = userInfo(); 13 | if (shell) { 14 | return shell; 15 | } 16 | } catch {} 17 | 18 | if (process.platform === 'darwin') { 19 | return env.SHELL || '/bin/zsh'; 20 | } 21 | 22 | return env.SHELL || '/bin/sh'; 23 | }; 24 | 25 | // Stores default shell when imported. 26 | const defaultShell = detectDefaultShell(); 27 | 28 | export default defaultShell; 29 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType} from 'tsd'; 2 | import defaultShell, {detectDefaultShell} from './index.js'; 3 | 4 | expectType(defaultShell); 5 | expectType(detectDefaultShell()); 6 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "default-shell", 3 | "version": "2.2.0", 4 | "description": "Get the user's default shell", 5 | "license": "MIT", 6 | "repository": "sindresorhus/default-shell", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": "./index.js", 15 | "engines": { 16 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava && tsd" 20 | }, 21 | "files": [ 22 | "index.js", 23 | "index.d.ts" 24 | ], 25 | "keywords": [ 26 | "default", 27 | "shell", 28 | "sh", 29 | "zsh", 30 | "bash", 31 | "cmd", 32 | "comspec", 33 | "env", 34 | "environment", 35 | "variables", 36 | "get", 37 | "user" 38 | ], 39 | "devDependencies": { 40 | "ava": "^3.15.0", 41 | "tsd": "^0.17.0", 42 | "xo": "^0.44.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # default-shell 2 | 3 | > Get the user's default [shell](https://en.wikipedia.org/wiki/Shell_(computing)) 4 | 5 | ## Install 6 | 7 | ```sh 8 | npm install default-shell 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | import defaultShell from 'default-shell'; 15 | 16 | // macOS 17 | console.log(defaultShell); 18 | //=> '/bin/zsh' 19 | 20 | // Windows 21 | console.log(defaultShell); 22 | //=> 'C:\\WINDOWS\\system32\\cmd.exe' 23 | ``` 24 | 25 | There is also a method that gets the correct default shell even if it changes at runtime: 26 | 27 | ```js 28 | import {detectDefaultShell} from 'default-shell'; 29 | 30 | console.log(detectDefaultShell()); 31 | //=> '/bin/zsh' 32 | ``` 33 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import process from 'node:process'; 2 | import test from 'ava'; 3 | import defaultShell, {detectDefaultShell} from './index.js'; 4 | 5 | test('main', t => { 6 | t.true(defaultShell.startsWith(process.platform === 'win32' ? 'C:\\' : '/bin/')); 7 | }); 8 | 9 | test('detect', t => { 10 | t.is(detectDefaultShell(), defaultShell); 11 | }); 12 | --------------------------------------------------------------------------------