Commit 1faee66a authored by gulderov's avatar gulderov Committed by Joe Haddad
Browse files

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
parent 12f1a8ee
3 merge requests!12191Lim.Pisey.168:/Identified - We are currently investigating reports of missing build logs. The issue has been identified and a resolution is in progress. We will provide a further update when available.Mar 21, 09:02 UTC,!12853brikk,!5717Automatically extract project file structure from build bundle file
Showing with 31 additions and 2 deletions
+31 -2
...@@ -56,6 +56,20 @@ const COMMON_EDITORS_OSX = { ...@@ -56,6 +56,20 @@ const COMMON_EDITORS_OSX = {
'/Applications/WebStorm.app/Contents/MacOS/webstorm', '/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 = [ const COMMON_EDITORS_WIN = [
'Brackets.exe', 'Brackets.exe',
'Code.exe', 'Code.exe',
...@@ -144,8 +158,9 @@ function guessEditor() { ...@@ -144,8 +158,9 @@ function guessEditor() {
return shellQuote.parse(process.env.REACT_EDITOR); 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. // We can find out which editor is currently running by:
// Potentially we could use similar technique for Linux // `ps x` on macOS and Linux
// `Get-Process` on Windows
try { try {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
const output = child_process.execSync('ps x').toString(); const output = child_process.execSync('ps x').toString();
...@@ -176,6 +191,20 @@ function guessEditor() { ...@@ -176,6 +191,20 @@ function guessEditor() {
return [fullProcessPath]; 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) { } catch (error) {
// Ignore... // Ignore...
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment