Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Node.js 8, add support for nano and Emacs, add TypeScript definition #6

Merged
merged 3 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '6'
- '4'
- '10'
- '8'
50 changes: 50 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export interface Editor {
id: string;
name: string;
bin: string;
BendingBender marked this conversation as resolved.
Show resolved Hide resolved
isTerminalEditor: boolean;
paths: string[];
keywords: string[];
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Get info about the default editor.

The user is expected to have the `$EDITOR` environment variable set, and if not, a user-friendly error is thrown.

@returns Info about the default editor.
*/
export default function(): Editor;

/**
Get info about a specific editor.

@param editor - This can be pretty flexible. It matches against all the data it has.

BendingBender marked this conversation as resolved.
Show resolved Hide resolved
For example, to get Sublime Text, you could write either of the following: `sublime`, `Sublime Text`, `subl`.
@returns Info about the specified editor.
BendingBender marked this conversation as resolved.
Show resolved Hide resolved

@example
```
import * as envEditor from 'env-editor';
BendingBender marked this conversation as resolved.
Show resolved Hide resolved

envEditor.get('sublime');
// {
// id: 'sublime',
// name: 'Sublime Text',
// bin: 'subl',
// isTerminalEditor: false,
// paths: [
// '/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl',
// '/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl'
// ],
// keywords: []
// }
```
*/
export function get(editor: string): Editor;
BendingBender marked this conversation as resolved.
Show resolved Hide resolved

/**
@returns Info on all the editors.
*/
export function all(): Editor[];
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,29 @@ const editors = () => [{
'jetbrains',
'ide'
]
}, {
id: 'nano',
name: 'GNU nano',
bin: 'nano',
isTerminalEditor: true,
paths: [],
keywords: []
}, {
id: 'emacs',
name: 'GNU Emacs',
bin: 'emacs',
isTerminalEditor: true,
paths: [],
keywords: []
}, {
id: 'emacsforosx',
name: 'GNU Emacs for Mac OS X',
bin: 'Emacs',
isTerminalEditor: false,
paths: [
'/Applications/Emacs.app/Contents/MacOS/Emacs'
],
keywords: []
}];

const get = input => {
Expand Down Expand Up @@ -119,6 +142,7 @@ module.exports.default = () => {

if (!editor) {
throw new Error(
// eslint-disable-next-line indent
`
Your $EDITOR environment variable is not set.
Set it to the command/path of your editor in ~/.zshenv or ~/.bashrc:
Expand Down
6 changes: 6 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {expectType} from 'tsd';
import * as envEditor from '.';

expectType<envEditor.Editor>(envEditor.get('sublime'));
expectType<envEditor.Editor>(envEditor.default());
expectType<envEditor.Editor[]>(envEditor.all());
20 changes: 4 additions & 16 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)

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:
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:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
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.
98 changes: 51 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
{
"name": "env-editor",
"version": "0.3.1",
"description": "Get info about the default editor or a specific editor",
"license": "MIT",
"repository": "sindresorhus/env-editor",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"env",
"editor",
"environment",
"variable",
"default",
"editors",
"main",
"user",
"meta",
"metadata",
"info",
"name",
"binary",
"path",
"sublime",
"atom",
"vscode",
"webstorm",
"textmate",
"vim",
"neovim",
"intellij"
],
"devDependencies": {
"ava": "*",
"xo": "*"
}
"name": "env-editor",
"version": "0.3.1",
"description": "Get info about the default editor or a specific editor",
"license": "MIT",
"repository": "sindresorhus/env-editor",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"env",
"editor",
"environment",
"variable",
"default",
"editors",
"main",
"user",
"meta",
"metadata",
"info",
"name",
"binary",
"path",
"sublime",
"atom",
"vscode",
"webstorm",
"textmate",
"vim",
"neovim",
"intellij",
"nano",
"emacs"
],
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ This module is used by [`open-editor`](https://github.com/sindresorhus/open-edit
- Vim
- NeoVim
- IntelliJ
- GNU nano
- GNU Emacs


## Install

```
$ npm install --save env-editor
$ npm install env-editor
```


Expand Down
75 changes: 45 additions & 30 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,87 @@
import test from 'ava';
import m from '.';
import envEditor from '.';

test.serial('.default()', t => {
const editor = process.env.EDITOR;
process.env.EDITOR = 'subl';
t.is(m.default().id, 'sublime');
t.is(envEditor.default().id, 'sublime');
process.env.EDITOR = editor;
});

test('.get() - generic (no match)', t => {
const result = m.get('Generic Editor');
const result = envEditor.get('Generic Editor');
t.is(result.id, 'generic-editor');
t.is(result.name, 'Generic Editor');
t.is(result.bin, 'generic');
});

test('.get() - Sublime', t => {
t.is(m.get('sublime').id, 'sublime');
t.is(m.get('Sublime').id, 'sublime');
t.is(m.get('subl').id, 'sublime');
t.is(m.get('Sublime Text').id, 'sublime');
t.is(m.get('/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl').id, 'sublime');
t.is(envEditor.get('sublime').id, 'sublime');
t.is(envEditor.get('Sublime').id, 'sublime');
t.is(envEditor.get('subl').id, 'sublime');
t.is(envEditor.get('Sublime Text').id, 'sublime');
t.is(envEditor.get('/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl').id, 'sublime');
});

test('.get() - Atom', t => {
t.is(m.get('atom').id, 'atom');
t.is(m.get('Atom').id, 'atom');
t.is(envEditor.get('atom').id, 'atom');
t.is(envEditor.get('Atom').id, 'atom');
});

test('.get() - Visual Studio Code', t => {
t.is(m.get('vscode').id, 'vscode');
t.is(m.get('code').id, 'vscode');
t.is(m.get('vs code').id, 'vscode');
t.is(m.get('Visual Studio Code').id, 'vscode');
t.is(envEditor.get('vscode').id, 'vscode');
t.is(envEditor.get('code').id, 'vscode');
t.is(envEditor.get('vs code').id, 'vscode');
t.is(envEditor.get('Visual Studio Code').id, 'vscode');
});

test('.get() - WebStorm', t => {
t.is(m.get('webstorm').id, 'webstorm');
t.is(m.get('wstorm').id, 'webstorm');
t.is(m.get('WebStorm').id, 'webstorm');
t.is(envEditor.get('webstorm').id, 'webstorm');
t.is(envEditor.get('wstorm').id, 'webstorm');
t.is(envEditor.get('WebStorm').id, 'webstorm');
});

test('.get() - TextMate', t => {
t.is(m.get('textmate').id, 'textmate');
t.is(m.get('mate').id, 'textmate');
t.is(m.get('TextMate').id, 'textmate');
t.is(envEditor.get('textmate').id, 'textmate');
t.is(envEditor.get('mate').id, 'textmate');
t.is(envEditor.get('TextMate').id, 'textmate');
});

test('.get() - Vim', t => {
t.is(m.get('vim').id, 'vim');
t.is(m.get('Vim').id, 'vim');
t.is(envEditor.get('vim').id, 'vim');
t.is(envEditor.get('Vim').id, 'vim');
});

test('.get() - NeoVim', t => {
t.is(m.get('neovim').id, 'neovim');
t.is(m.get('nvim').id, 'neovim');
t.is(m.get('NeoVim').id, 'neovim');
t.is(envEditor.get('neovim').id, 'neovim');
t.is(envEditor.get('nvim').id, 'neovim');
t.is(envEditor.get('NeoVim').id, 'neovim');
});

test('.get() - IntelliJ IDEA', t => {
t.is(m.get('intellij').id, 'intellij');
t.is(m.get('idea').id, 'intellij');
t.is(m.get('IntelliJ').id, 'intellij');
t.is(m.get('IntelliJ IDEA').id, 'intellij');
t.is(envEditor.get('intellij').id, 'intellij');
t.is(envEditor.get('idea').id, 'intellij');
t.is(envEditor.get('IntelliJ').id, 'intellij');
t.is(envEditor.get('IntelliJ IDEA').id, 'intellij');
});

test('.get() - GNU nano', t => {
t.is(envEditor.get('nano').id, 'nano');
t.is(envEditor.get('GNU nano').id, 'nano');
});

test('.get() - GNU Emacs', t => {
t.is(envEditor.get('emacs').id, 'emacs');
t.is(envEditor.get('GNU Emacs').id, 'emacs');
});

test('.get() - GNU Emacs for Mac OS X', t => {
t.is(envEditor.get('emacsforosx').id, 'emacsforosx');
t.is(envEditor.get('GNU Emacs for Mac OS X').id, 'emacsforosx');
});

test('.all()', t => {
const all = m.all();
const all = envEditor.all();
t.true(Array.isArray(all));
t.true(all.length > 0);
t.is(all[0].id, 'sublime');
Expand Down