Skip to content

Commit b8c65f3

Browse files
gulderovkasperpeulen
authored andcommitted
Auto-detect running editor on Linux for error overlay (facebook#3077)
* Auto-detect running editor on Linux for error overlay Basic support of auto detecting running editor for facebook#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
1 parent 573c2f2 commit b8c65f3

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

packages/react-dev-utils/launchEditor.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ const COMMON_EDITORS_OSX = {
5656
'/Applications/WebStorm.app/Contents/MacOS/webstorm',
5757
};
5858

59+
const COMMON_EDITORS_LINUX = {
60+
atom: 'atom',
61+
Brackets: 'brackets',
62+
code: 'code',
63+
emacs: 'emacs',
64+
'idea.sh': 'idea',
65+
'phpstorm.sh': 'phpstorm',
66+
'pycharm.sh': 'pycharm',
67+
'rubymine.sh': 'rubymine',
68+
sublime_text: 'sublime_text',
69+
vim: 'vim',
70+
'webstorm.sh': 'webstorm',
71+
};
72+
5973
const COMMON_EDITORS_WIN = [
6074
'Brackets.exe',
6175
'Code.exe',
@@ -144,8 +158,9 @@ function guessEditor() {
144158
return shellQuote.parse(process.env.REACT_EDITOR);
145159
}
146160

147-
// Using `ps x` on OSX or `Get-Process` on Windows we can find out which editor is currently running.
148-
// Potentially we could use similar technique for Linux
161+
// We can find out which editor is currently running by:
162+
// `ps x` on macOS and Linux
163+
// `Get-Process` on Windows
149164
try {
150165
if (process.platform === 'darwin') {
151166
const output = child_process.execSync('ps x').toString();
@@ -176,6 +191,20 @@ function guessEditor() {
176191
return [fullProcessPath];
177192
}
178193
}
194+
} else if (process.platform === 'linux') {
195+
// --no-heading No header line
196+
// x List all processes owned by you
197+
// -o comm Need only names column
198+
const output = child_process
199+
.execSync('ps x --no-heading -o comm --sort=comm')
200+
.toString();
201+
const processNames = Object.keys(COMMON_EDITORS_LINUX);
202+
for (let i = 0; i < processNames.length; i++) {
203+
const processName = processNames[i];
204+
if (output.indexOf(processName) !== -1) {
205+
return [COMMON_EDITORS_LINUX[processName]];
206+
}
207+
}
179208
}
180209
} catch (error) {
181210
// Ignore...

0 commit comments

Comments
 (0)