()
| 194 | } |
| 195 | |
| 196 | function guessEditor() { |
| 197 | // Explicit config always wins |
| 198 | if (process.env.REACT_EDITOR) { |
| 199 | return shellQuote.parse(process.env.REACT_EDITOR); |
| 200 | } |
| 201 | |
| 202 | // We can find out which editor is currently running by: |
| 203 | // `ps x` on macOS and Linux |
| 204 | // `Get-Process` on Windows |
| 205 | try { |
| 206 | if (process.platform === 'darwin') { |
| 207 | const output = child_process.execSync('ps x').toString(); |
| 208 | const processNames = Object.keys(COMMON_EDITORS_OSX); |
| 209 | for (let i = 0; i < processNames.length; i++) { |
| 210 | const processName = processNames[i]; |
| 211 | if (output.indexOf(processName) !== -1) { |
| 212 | return [COMMON_EDITORS_OSX[processName]]; |
| 213 | } |
| 214 | } |
| 215 | } else if (process.platform === 'win32') { |
| 216 | // Some processes need elevated rights to get its executable path. |
| 217 | // Just filter them out upfront. This also saves 10-20ms on the command. |
| 218 | const output = child_process |
| 219 | .execSync( |
| 220 | 'wmic process where "executablepath is not null" get executablepath' |
| 221 | ) |
| 222 | .toString(); |
| 223 | const runningProcesses = output.split('\r\n'); |
| 224 | for (let i = 0; i < runningProcesses.length; i++) { |
| 225 | const processPath = runningProcesses[i].trim(); |
| 226 | const processName = path.basename(processPath); |
| 227 | if (COMMON_EDITORS_WIN.indexOf(processName) !== -1) { |
| 228 | return [processPath]; |
| 229 | } |
| 230 | } |
| 231 | } else if (process.platform === 'linux') { |
| 232 | // --no-heading No header line |
| 233 | // x List all processes owned by you |
| 234 | // -o comm Need only names column |
| 235 | const output = child_process |
| 236 | .execSync('ps x --no-heading -o comm --sort=comm') |
| 237 | .toString(); |
| 238 | const processNames = Object.keys(COMMON_EDITORS_LINUX); |
| 239 | for (let i = 0; i < processNames.length; i++) { |
| 240 | const processName = processNames[i]; |
| 241 | if (output.indexOf(processName) !== -1) { |
| 242 | return [COMMON_EDITORS_LINUX[processName]]; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } catch (error) { |
| 247 | // Ignore... |
| 248 | } |
| 249 | |
| 250 | // Last resort, use old skool env vars |
| 251 | if (process.env.VISUAL) { |
| 252 | return [process.env.VISUAL]; |
| 253 | } else if (process.env.EDITOR) { |
no test coverage detected