-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathedit-in-external-editor.js
More file actions
45 lines (36 loc) · 1.04 KB
/
edit-in-external-editor.js
File metadata and controls
45 lines (36 loc) · 1.04 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let EDITOR = '';
// ---- CONFIGURATION ----
// Set EDITOR to the application (note: not shell command) you want to use.
// Below are some examples.
// TextEdit
EDITOR = 'TextEdit'
// Visual Studio Code
// EDITOR = 'Visual Studio Code'
// Neovim Qt
// EDITOR = 'nvim-qt'
// -----------------------
function bash(script) {
let sh = ShellScript.create(`#!/usr/bin/env bash\n${script}`);
if (!sh.execute()) {
throw new Error(sh.standardError);
}
}
(function() {
let bookmark = Bookmark.findOrCreate("proxy-files");
let fm = FileManager.createForBookmark(bookmark);
// TODO: Get file extension from draft
if (!fm.writeString(`/${draft.uuid}.md`, draft.content)) {
alert("Error: Couldn't write file");
return;
}
let file = `${fm.basePath}/${draft.uuid}.md`;
try {
bash(`open -n -W -a "${EDITOR}" "${file}"`);
draft.content = fm.readString(`/${draft.uuid}.md`);
draft.update();
bash(`rm "${file}"`);
} catch (e) {
alert(e);
return;
}
})();