-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
28 lines (26 loc) · 797 Bytes
/
Copy pathconfig.js
File metadata and controls
28 lines (26 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const child_process = require('child_process');
var config = {};
try {
var configPath = process.env.XDG_CONFIG_HOME || process.env.HOME + '/.config';
configPath += '/wordsafe/config.json';
config = require(configPath);
} catch(e) { /**/ }
module.exports = Object.assign(config, {
openEditor(filepath, vargs) {
if (vargs.editor) {
config.editor = vargs.editor;
config.editorArguments = [];
}
if (!config.editor) {
return require('opn')(filepath);
} else {
return new Promise((resolve, reject) => {
let editor = child_process.spawn(config.editor, [...(config.editorArguments || []), filepath], {
stdio: 'inherit'
});
editor.on('close', resolve);
editor.on('error', reject);
});
}
}
});