Skip to content

Commit

Permalink
Auto-detect running editor on Linux for error overlay (#3077)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gulderov authored and Timer committed Sep 11, 2017
1 parent 12f1a8e commit 1faee66
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions packages/react-dev-utils/launchEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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...
Expand Down

0 comments on commit 1faee66

Please sign in to comment.