Allow arguments in the editor env var
Reviewed By: frantic Differential Revision: D4129207 fbshipit-source-id: a92fbbbe917db9c9afc0d970e3ac546e2a14bced
This commit is contained in:
parent
c02c7f3024
commit
a643784144
|
@ -13,6 +13,7 @@ var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
const isAbsolutePath = require('absolute-path');
|
const isAbsolutePath = require('absolute-path');
|
||||||
|
const shellQuote = require('shell-quote');
|
||||||
|
|
||||||
function isTerminalEditor(editor) {
|
function isTerminalEditor(editor) {
|
||||||
switch (editor) {
|
switch (editor) {
|
||||||
|
@ -49,7 +50,8 @@ function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
|
||||||
case 'mvim':
|
case 'mvim':
|
||||||
return [fileName, '+' + lineNumber];
|
return [fileName, '+' + lineNumber];
|
||||||
case 'atom':
|
case 'atom':
|
||||||
return addWorkspaceToArgumentsIfExists([fileName + ':' + lineNumber], workspace);
|
case 'Atom':
|
||||||
|
case 'Atom Beta':
|
||||||
case 'subl':
|
case 'subl':
|
||||||
case 'sublime':
|
case 'sublime':
|
||||||
case 'wstorm':
|
case 'wstorm':
|
||||||
|
@ -77,7 +79,7 @@ function getArgumentsForLineNumber(editor, fileName, lineNumber, workspace) {
|
||||||
function guessEditor() {
|
function guessEditor() {
|
||||||
// Explicit config always wins
|
// Explicit config always wins
|
||||||
if (process.env.REACT_EDITOR) {
|
if (process.env.REACT_EDITOR) {
|
||||||
return process.env.REACT_EDITOR;
|
return shellQuote.parse(process.env.REACT_EDITOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using `ps x` on OSX we can find out which editor is currently running.
|
// Using `ps x` on OSX we can find out which editor is currently running.
|
||||||
|
@ -89,7 +91,7 @@ function guessEditor() {
|
||||||
for (var i = 0; i < processNames.length; i++) {
|
for (var i = 0; i < processNames.length; i++) {
|
||||||
var processName = processNames[i];
|
var processName = processNames[i];
|
||||||
if (output.indexOf(processName) !== -1) {
|
if (output.indexOf(processName) !== -1) {
|
||||||
return COMMON_EDITORS[processName];
|
return [COMMON_EDITORS[processName]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
@ -98,7 +100,13 @@ function guessEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last resort, use old skool env vars
|
// Last resort, use old skool env vars
|
||||||
return process.env.VISUAL || process.env.EDITOR;
|
if (process.env.VISUAL) {
|
||||||
|
return [process.env.VISUAL];
|
||||||
|
} else if (process.env.EDITOR) {
|
||||||
|
return [process.env.EDITOR];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printInstructions(title) {
|
function printInstructions(title) {
|
||||||
|
@ -142,16 +150,17 @@ function launchEditor(fileName, lineNumber, projectRoots) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var editor = guessEditor();
|
const [editor, ...args] = guessEditor();
|
||||||
if (!editor) {
|
if (!editor) {
|
||||||
printInstructions('PRO TIP');
|
printInstructions('PRO TIP');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var workspace = findRootForFile(projectRoots, fileName);
|
var workspace = findRootForFile(projectRoots, fileName);
|
||||||
var args = [fileName];
|
|
||||||
if (lineNumber) {
|
if (lineNumber) {
|
||||||
args = getArgumentsForLineNumber(editor, fileName, lineNumber, workspace);
|
args.push(getArgumentsForLineNumber(editor, fileName, lineNumber, workspace));
|
||||||
|
} else {
|
||||||
|
args.push(fileName);
|
||||||
}
|
}
|
||||||
console.log('Opening ' + chalk.underline(fileName) + ' with ' + chalk.bold(editor));
|
console.log('Opening ' + chalk.underline(fileName) + ' with ' + chalk.bold(editor));
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,7 @@
|
||||||
"regenerator-runtime": "^0.9.5",
|
"regenerator-runtime": "^0.9.5",
|
||||||
"sane": "~1.4.1",
|
"sane": "~1.4.1",
|
||||||
"semver": "^5.0.3",
|
"semver": "^5.0.3",
|
||||||
|
"shell-quote": "1.6.1",
|
||||||
"source-map": "^0.5.6",
|
"source-map": "^0.5.6",
|
||||||
"stacktrace-parser": "^0.1.3",
|
"stacktrace-parser": "^0.1.3",
|
||||||
"temp": "0.8.3",
|
"temp": "0.8.3",
|
||||||
|
|
Loading…
Reference in New Issue