Skip to content

Commit

Permalink
windows: fix editing preferences on bash (#1571)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Stefan Ivic authored and rauchg committed Feb 25, 2017
1 parent d521e8e commit 36f96ab
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions lib/actions/ui.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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({
Expand All @@ -231,7 +246,6 @@ export function showPreferences() {
uid,
[
...message,
command,
''
].join(EOL)
));
Expand Down

0 comments on commit 36f96ab

Please sign in to comment.