GithubHelp home page GithubHelp logo

default-shell's Introduction

default-shell

Get the user's default shell

Install

npm install default-shell

Usage

import defaultShell from 'default-shell';

// macOS
console.log(defaultShell);
//=> '/bin/zsh'

// Windows
console.log(defaultShell);
//=> 'C:\\WINDOWS\\system32\\cmd.exe'

There is also a method that gets the correct default shell even if it changes at runtime:

import {detectDefaultShell} from 'default-shell';

console.log(detectDefaultShell());
//=> '/bin/zsh'

default-shell's People

Contributors

mquevill avatar msipinski avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

default-shell's Issues

TypeScript support

Having a TypeScript type definition file would be nice. Without it I have to write my own type definition file or use // @ts-ignore above the import.

Only one short file is needed:

// index.d.ts
declare module 'default-shell' {
  declare const defaultShell: string // probably could also be "let" instead of "const"
  export default defaultShell
}

Don't trust process.env.SHELL

As seen in sindresorhus/shell-path#10 (comment), process.env.SHELL can't be trusted to work in certain situations, leading to hard to debug errors.

I think we should first stat and check for the executable bit, and possibly fallback to well-known shell paths like /bin/bash or /bin/zsh on error.

CommonJS module system support

Hi, I know that ECMAScript Modules are the future, but for now I have a problem using ESM packages in my Electron.js project. I think that having a "hybrid" package is better!

If my understanding is correct, we can extract the code from index.js to a new file index.cjs with a CJS style module.exports = and in index.js leave only a ESM style wrapper: import defaultShell from './index.cjs' and export default defaultShell.

Export detect function

We're using this module in hyper: https://github.com/zeit/hyper/blob/canary/app/session.js#L4

Since we require this module at startup, we won't see changes to the default shell, requiring a restart to use the new default shell after changing it.

I have some ideas on how to fix this, but the best might be to export the detect function too,

const detect = () => {
	const env = process.env;

	if (process.platform === 'darwin') {
		return env.SHELL || '/bin/bash';
	}

	if (process.platform === 'win32') {
		return env.COMSPEC || 'cmd.exe';
	}

	return env.SHELL || '/bin/sh';
})
module.exports = detect();
module.exports.detect = detect

another way would be to purge the require cache in hyper, but that feels hacky.

another way is to just copy this module code into hyper/lib.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.