windows: fix editing preferences on bash (#1571)

* windows: fix editing preferences on bash

* linter: fix the linting error

* cleanCode : move the code to a function

* cleanCode: move the constants to the function

* clean: remove unnecessary eslint comment

* clean: use platform instead of defining it
This commit is contained in:
Stefan Ivic 2017-02-25 05:50:20 +01:00 committed by Guillermo Rauch
parent d521e8e162
commit 36f96abb1d

View file

@ -1,5 +1,6 @@
import {EOL} from 'os';
import {remote} from 'electron';
import * as shellEscape from 'php-escape-shell';
import last from '../utils/array';
import isExecutable from '../utils/file';
@ -209,15 +210,29 @@ export function moveTo(i) {
};
}
function getEditCommand(shell, isWin) {
if (isWin && shell.includes('bash')) {
return [
' nano .hyper.js',
'echo Attempting to open .hyper.js with nano'
];
} else if (isWin) {
return [
' start notepad "%userprofile%\\.hyper.js"',
'echo Attempting to open .hyper.js with notepad'
];
}
return [
// eslint-disable-next-line no-template-curly-in-string
' bash -c \'exec env ${EDITOR:=nano} ~/.hyper.js\'',
'echo Attempting to open ~/.hyper.js with your \\$EDITOR'
];
}
export function showPreferences() {
const isWin = process.platform === 'win32';
// eslint-disable-next-line no-template-curly-in-string
const command = isWin ? ' start notepad "%userprofile%\\.hyper.js"' : ' bash -c \'exec env ${EDITOR:=nano} ~/.hyper.js\'';
const message = [];
message.push(isWin ?
' echo Attempting to open ^%userprofile^%\\.hyper.js with notepad' :
' echo Attempting to open ~/.hyper.js with your \\$EDITOR');
message.push(' echo If it fails, open it manually with your favorite editor!');
const plugins = remote.require('./plugins');
const {shell} = plugins.getDecoratedConfig();
const message = getEditCommand(shell, process.platform === 'win32');
return dispatch => {
dispatch({
@ -231,7 +246,6 @@ export function showPreferences() {
uid,
[
...message,
command,
''
].join(EOL)
));