mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-23 20:51:12 +08:00
Auto-detect running editor on Linux for error overlay (#3077)
* Auto-detect running editor on Linux for error overlay Basic support of auto detecting running editor for #2636. Tested on Ubuntu 16.04. It detects few editors. JetBrains products should start by wrapper like /usr/local/bin/webstorm. Otherwise it takes a lot of time to open editor. * Comments fixed. * List all processes owned by you * Comment rewording
This commit is contained in:
33
packages/react-dev-utils/launchEditor.js
vendored
33
packages/react-dev-utils/launchEditor.js
vendored
@@ -56,6 +56,20 @@ const COMMON_EDITORS_OSX = {
|
||||
'/Applications/WebStorm.app/Contents/MacOS/webstorm',
|
||||
};
|
||||
|
||||
const COMMON_EDITORS_LINUX = {
|
||||
atom: 'atom',
|
||||
Brackets: 'brackets',
|
||||
code: 'code',
|
||||
emacs: 'emacs',
|
||||
'idea.sh': 'idea',
|
||||
'phpstorm.sh': 'phpstorm',
|
||||
'pycharm.sh': 'pycharm',
|
||||
'rubymine.sh': 'rubymine',
|
||||
sublime_text: 'sublime_text',
|
||||
vim: 'vim',
|
||||
'webstorm.sh': 'webstorm',
|
||||
};
|
||||
|
||||
const COMMON_EDITORS_WIN = [
|
||||
'Brackets.exe',
|
||||
'Code.exe',
|
||||
@@ -144,8 +158,9 @@ function guessEditor() {
|
||||
return shellQuote.parse(process.env.REACT_EDITOR);
|
||||
}
|
||||
|
||||
// Using `ps x` on OSX or `Get-Process` on Windows we can find out which editor is currently running.
|
||||
// Potentially we could use similar technique for Linux
|
||||
// We can find out which editor is currently running by:
|
||||
// `ps x` on macOS and Linux
|
||||
// `Get-Process` on Windows
|
||||
try {
|
||||
if (process.platform === 'darwin') {
|
||||
const output = child_process.execSync('ps x').toString();
|
||||
@@ -176,6 +191,20 @@ function guessEditor() {
|
||||
return [fullProcessPath];
|
||||
}
|
||||
}
|
||||
} else if (process.platform === 'linux') {
|
||||
// --no-heading No header line
|
||||
// x List all processes owned by you
|
||||
// -o comm Need only names column
|
||||
const output = child_process
|
||||
.execSync('ps x --no-heading -o comm --sort=comm')
|
||||
.toString();
|
||||
const processNames = Object.keys(COMMON_EDITORS_LINUX);
|
||||
for (let i = 0; i < processNames.length; i++) {
|
||||
const processName = processNames[i];
|
||||
if (output.indexOf(processName) !== -1) {
|
||||
return [COMMON_EDITORS_LINUX[processName]];
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore...
|
||||
|
||||
Reference in New Issue
Block a user