├── .editorconfig ├── .gitattributes ├── .github ├── funding.yml └── security.md ├── .gitignore ├── .npmrc ├── .travis.yml ├── 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/funding.yml: -------------------------------------------------------------------------------- 1 | github: kevva 2 | tidelift: npm/shebang-command 3 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '12' 4 | - '10' 5 | - '8' 6 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | Get the command from a shebang. 3 | 4 | @example 5 | ``` 6 | import shebangCommand = require('shebang-command'); 7 | 8 | shebangCommand('#!/usr/bin/env node'); 9 | //=> 'node' 10 | 11 | shebangCommand('#!/bin/bash'); 12 | //=> 'bash' 13 | ``` 14 | */ 15 | declare function shebangCommand(shebang?: string): string | null; 16 | 17 | export = shebangCommand; 18 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const shebangRegex = require('shebang-regex'); 3 | 4 | module.exports = (string = '') => { 5 | const match = string.match(shebangRegex); 6 | 7 | if (!match) { 8 | return null; 9 | } 10 | 11 | const [path, argument] = match[0].replace(/#! ?/, '').split(' '); 12 | const binary = path.split('/').pop(); 13 | 14 | if (binary === 'env') { 15 | return argument; 16 | } 17 | 18 | return argument ? `${binary} ${argument}` : binary; 19 | }; 20 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType} from 'tsd'; 2 | import shebangCommand = require('.'); 3 | 4 | expectType(shebangCommand('#!/usr/bin/env node')); 5 | expectType(shebangCommand('#!/bin/bash')); 6 | expectType(shebangCommand()); 7 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Kevin Mårtensson (github.com/kevva) 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": "shebang-command", 3 | "version": "2.0.0", 4 | "description": "Get the command from a shebang", 5 | "license": "MIT", 6 | "repository": "kevva/shebang-command", 7 | "author": { 8 | "name": "Kevin Mårtensson", 9 | "email": "kevinmartensson@gmail.com", 10 | "url": "github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=8" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js", 20 | "index.d.ts" 21 | ], 22 | "keywords": [ 23 | "cmd", 24 | "command", 25 | "parse", 26 | "shebang" 27 | ], 28 | "dependencies": { 29 | "shebang-regex": "^3.0.0" 30 | }, 31 | "devDependencies": { 32 | "ava": "^2.3.0", 33 | "tsd": "^0.7.4", 34 | "xo": "^0.24.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # shebang-command [![Build Status](https://travis-ci.org/kevva/shebang-command.svg?branch=master)](https://travis-ci.org/kevva/shebang-command) 2 | 3 | > Get the command from a shebang 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install shebang-command 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const shebangCommand = require('shebang-command'); 17 | 18 | shebangCommand('#!/usr/bin/env node'); 19 | //=> 'node' 20 | 21 | shebangCommand('#!/bin/bash'); 22 | //=> 'bash' 23 | ``` 24 | 25 | 26 | ## API 27 | 28 | ### shebangCommand(string) 29 | 30 | #### string 31 | 32 | Type: `string` 33 | 34 | String containing a shebang. 35 | 36 | 37 | --- 38 | 39 |
40 | 41 | Get professional support for this package with a Tidelift subscription 42 | 43 |
44 | 45 | Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. 46 |
47 |
48 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import shebangCommand from '.'; 3 | 4 | test('main', t => { 5 | t.is(shebangCommand('#!/usr/bin/env node'), 'node'); 6 | t.is(shebangCommand('#!/bin/bash'), 'bash'); 7 | t.is(shebangCommand('#!/bin/bash -ex'), 'bash -ex'); 8 | t.is(shebangCommand('#! /bin/bash'), 'bash'); 9 | t.is(shebangCommand('#! /bin/bash -ex'), 'bash -ex'); 10 | t.is(shebangCommand('#!/sh'), 'sh'); 11 | t.is(shebangCommand('node'), null); 12 | t.is(shebangCommand(), null); 13 | }); 14 | --------------------------------------------------------------------------------