From 64a6ed7619bec5e675b40591bbb949473410b102 Mon Sep 17 00:00:00 2001 From: Danila Gulderov Date: Wed, 6 Sep 2017 15:07:01 +0300 Subject: [PATCH 1/4] 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. --- packages/react-dev-utils/launchEditor.js | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/react-dev-utils/launchEditor.js b/packages/react-dev-utils/launchEditor.js index e1ea29c8869..4b43f98f3e2 100644 --- a/packages/react-dev-utils/launchEditor.js +++ b/packages/react-dev-utils/launchEditor.js @@ -43,7 +43,7 @@ const COMMON_EDITORS_OSX = { '/Applications/CLion.app/Contents/MacOS/clion': '/Applications/CLion.app/Contents/MacOS/clion', '/Applications/IntelliJ IDEA.app/Contents/MacOS/idea': - '/Applications/IntelliJ IDEA.app/Contents/MacOS/idea', + '/Applications/IntelliJ IDEA.app/Contents/MacOS/idea', '/Applications/PhpStorm.app/Contents/MacOS/phpstorm': '/Applications/PhpStorm.app/Contents/MacOS/phpstorm', '/Applications/PyCharm.app/Contents/MacOS/pycharm': @@ -53,7 +53,19 @@ const COMMON_EDITORS_OSX = { '/Applications/RubyMine.app/Contents/MacOS/rubymine': '/Applications/RubyMine.app/Contents/MacOS/rubymine', '/Applications/WebStorm.app/Contents/MacOS/webstorm': - '/Applications/WebStorm.app/Contents/MacOS/webstorm', + '/Applications/WebStorm.app/Contents/MacOS/webstorm', +}; + +const COMMON_EDITORS_LINUX = { + atom: 'atom', + Brackets: 'brackets', + code: 'code', + 'idea.sh': 'idea', + 'phpstorm.sh': 'phpstorm', + 'pycharm.sh': 'pycharm', + 'rubymine.sh': 'rubymine', + sublime_text: 'sublime_text', + 'webstorm.sh': 'webstorm', }; const COMMON_EDITORS_WIN = [ @@ -145,7 +157,6 @@ function guessEditor() { } // 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 try { if (process.platform === 'darwin') { const output = child_process.execSync('ps x').toString(); @@ -176,6 +187,17 @@ function guessEditor() { return [fullProcessPath]; } } + } else if (process.platform === 'linux') { + const output = child_process + .execSync('ps --no-heading -e -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... From 992104c5f1275821287a9ede77d193af2c9bbe41 Mon Sep 17 00:00:00 2001 From: Danila Gulderov Date: Thu, 7 Sep 2017 14:07:25 +0300 Subject: [PATCH 2/4] Comments fixed. --- packages/react-dev-utils/launchEditor.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-dev-utils/launchEditor.js b/packages/react-dev-utils/launchEditor.js index 4b43f98f3e2..a7d8f370b3f 100644 --- a/packages/react-dev-utils/launchEditor.js +++ b/packages/react-dev-utils/launchEditor.js @@ -60,11 +60,13 @@ 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', }; @@ -156,7 +158,10 @@ 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. + // We can find out which editor is currently running by: + // `ps x` on OSX + // `Get-Process` on Windows + // `ps -e` on Linux try { if (process.platform === 'darwin') { const output = child_process.execSync('ps x').toString(); @@ -188,6 +193,9 @@ function guessEditor() { } } } else if (process.platform === 'linux') { + // --no-heading No header line + // -e Select all processes + // -o comm Need only names column const output = child_process .execSync('ps --no-heading -e -o comm --sort=comm') .toString(); From 94566696ec7061209784f4327b0b8422861aff50 Mon Sep 17 00:00:00 2001 From: Danila Gulderov Date: Thu, 7 Sep 2017 14:55:27 +0300 Subject: [PATCH 3/4] List all processes owned by you --- packages/react-dev-utils/launchEditor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-dev-utils/launchEditor.js b/packages/react-dev-utils/launchEditor.js index a7d8f370b3f..01f317da8f1 100644 --- a/packages/react-dev-utils/launchEditor.js +++ b/packages/react-dev-utils/launchEditor.js @@ -194,10 +194,10 @@ function guessEditor() { } } else if (process.platform === 'linux') { // --no-heading No header line - // -e Select all processes + // x List all processes owned by you // -o comm Need only names column const output = child_process - .execSync('ps --no-heading -e -o comm --sort=comm') + .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++) { From 9197752f3b312f2f62a0351302d78db4f4d273aa Mon Sep 17 00:00:00 2001 From: Danila Gulderov Date: Mon, 11 Sep 2017 11:29:21 +0300 Subject: [PATCH 4/4] Comment rewording --- packages/react-dev-utils/launchEditor.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-dev-utils/launchEditor.js b/packages/react-dev-utils/launchEditor.js index 01f317da8f1..a6f7226efa3 100644 --- a/packages/react-dev-utils/launchEditor.js +++ b/packages/react-dev-utils/launchEditor.js @@ -159,9 +159,8 @@ function guessEditor() { } // We can find out which editor is currently running by: - // `ps x` on OSX + // `ps x` on macOS and Linux // `Get-Process` on Windows - // `ps -e` on Linux try { if (process.platform === 'darwin') { const output = child_process.execSync('ps x').toString();