mirror of
https://github.com/tomasriveral/NoteWrapper.git
synced 2026-08-12 10:20:46 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0eac451751 | ||
|
|
9d7e2efe17 | ||
|
|
0b92270e15 | ||
|
|
7db5bfb44a | ||
|
|
eceaf723f1 | ||
|
|
cb6ac9bce6 | ||
|
|
847f0dae5d | ||
|
|
411ed0939a | ||
|
|
83008d8da8 | ||
|
|
44f14803e0 | ||
|
|
3190da3cc5 | ||
|
|
adbc56fb36 | ||
|
|
9ad71fb4f5 | ||
|
|
5aee1f540c | ||
|
|
f131316fa7 | ||
|
|
7ced9e735f |
@@ -22,7 +22,7 @@ The goal was to create a terminal-based interface for accessing vaults and notes
|
||||
* Journal support with flexible entry formats
|
||||
* Real-time Markdown rendering via Vivify
|
||||
* Backup support using `rsync`
|
||||
* Supports multiple editors (vim, neovim, nano)
|
||||
* Supports multiple editors
|
||||
|
||||
---
|
||||
|
||||
@@ -40,11 +40,15 @@ Before building NoteWrapper, you must install the following dependencies:
|
||||
* `ripgrep`
|
||||
* `fzf`
|
||||
|
||||
You must also have a [supported editor](#editor-support) installed:
|
||||
You must also have a [supported editor (and their associated plugin if needed)](#editor-support) installed:
|
||||
|
||||
* `vim`
|
||||
* `neovim`
|
||||
* `helix`
|
||||
* `kakoune`
|
||||
* `micro`
|
||||
* `nano`
|
||||
* `neovim`
|
||||
* `vi`
|
||||
* `vim`
|
||||
|
||||
---
|
||||
|
||||
@@ -139,11 +143,15 @@ The first two features depend on [Vivify's editor integration](https://github.co
|
||||
|
||||
If your editor does not support these features, you can implement a plugin using [Vivify's API](https://github.com/jannis-baum/Vivify?tab=readme-ov-file#editor-support).
|
||||
|
||||
| Editor | Bufferless | Cursor | Jump to end | Plugin required |
|
||||
| ------ | ---------- | ------ | ----------- | ------------------------------------------------------- |
|
||||
| Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
||||
| Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
||||
| Nano | ❌ | ❌ | ✅ | — |
|
||||
| Editor | Bufferless | Cursor | Jump to end | Aditional requirements |
|
||||
| --------- | ----------- | ------- | ------------ | ---------------------------------------------------------|
|
||||
| Helix | ❌ | ❌ | ✅ | — |
|
||||
| Kakoune | ❌ | ❌ | ✅ | — |
|
||||
| Micro | ❌ | ✅ | ✅ | [micro-vivify](https://codeberg.org/gibbert/micro-vivify) and [modifications to your `init.lua`](./docs/micro.md)|
|
||||
| Nano | ❌ | ❌ | ✅ | — |
|
||||
| Neovim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
||||
| Vi | ❌ | ❌ | ✅ | |
|
||||
| Vim | ✅ | ✅ | ✅ | [vivify-vim](https://github.com/jannis-baum/vivify.vim) |
|
||||
|
||||
[How to add support for another editor](./CONTRIBUTING.md#adding-editor-support)
|
||||
|
||||
@@ -200,4 +208,5 @@ It is recommended to use a browser different from your main one for rendering.
|
||||
|
||||
* [ ] A converter between journal types
|
||||
* [ ] Support multiple vault directories
|
||||
* [ ] Port NoteWrapper to other editors
|
||||
* [ ] Port NoteWrapper to other editors (non-exhaustive list of planned ports: `emacs -nw`, `jed`, `ad`, flow-control, `ee`, `amp`, `dte`, `cano`, `mle`, `zee`, `ptext`, `kibi`, `ox`, `ne`, `dit`, `zile`, `moe`, `joe`, `pico`, `vis`)
|
||||
* [ ] Default to $EDITOR
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
You must add the following code to your `init.lua`:
|
||||
|
||||
```lua
|
||||
local buffer = import("micro/buffer")
|
||||
local shell = import("micro/shell")
|
||||
|
||||
function vivifyOpen(buf)
|
||||
local cursor = buf:GetActiveCursor()
|
||||
local line = cursor.Loc.Y + 1
|
||||
|
||||
shell.ExecCommand("viv", string.format("%s:%d", buf.AbsPath, line))
|
||||
end
|
||||
|
||||
function onBufferOpen(buf)
|
||||
if os.getenv("MICRO_VIVIFY") ~= "1" then
|
||||
return
|
||||
end
|
||||
|
||||
if buf.Type.Kind == buffer.BTDefault then
|
||||
vivifyOpen(buf)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
This enables Vivify to run automatically when a file is opened, effectively simulating “startup” behavior (since Micro does not provide a true startup command hook for this use case).
|
||||
|
||||
Big thanks to @Andriamanitra for answering [my questions](https://github.com/micro-editor/micro/discussions/4078).
|
||||
|
||||
+4
-1
@@ -221,11 +221,14 @@ arg_next:
|
||||
cJSON *rsyncArgsJSON = cJSON_GetObjectItem(backupJSON, "rsyncArgs");
|
||||
if (rsyncArgsJSON && cJSON_IsArray(rsyncArgsJSON)) { // if it is what we expected
|
||||
rsyncArgsNumber = cJSON_GetArraySize(rsyncArgsJSON);
|
||||
debug("In %s, rsyncArgsNumber is calculated to %d.", configPath, rsyncArgsNumber);
|
||||
rsyncArgs = realloc(rsyncArgs, (size_t)rsyncArgsNumber);
|
||||
debug("In %c, rsyncArgs are:", configPath);
|
||||
for (int i = 0; i < rsyncArgsNumber; i++) {
|
||||
cJSON *argJSON = cJSON_GetArrayItem(rsyncArgsJSON, i);
|
||||
if (argJSON && cJSON_IsString(argJSON)) {
|
||||
rsyncArgs[i] = cJSON_GetStringValue(argJSON);
|
||||
rsyncArgs[i] = strdup(cJSON_GetStringValue(argJSON));
|
||||
altDebug("%s\n", rsyncArgs[i]);
|
||||
} else {error(1, "user", "One element in rsyncArgs array in %s is not a string", configPath);}
|
||||
}
|
||||
} else {error(1, "user", "%s did not contained a rsyncArgs array inside the backup section or the value is from an unexpected type", configPath);}
|
||||
|
||||
+159
-7
@@ -1,8 +1,8 @@
|
||||
#include "utils.h"
|
||||
#include <stddef.h>
|
||||
#include "string.h"
|
||||
|
||||
const char *supportedEditor[] = {"neovim", "vim", "nano"};
|
||||
const int numEditors = 3;
|
||||
const char *supportedEditor[] = {"helix", "kakoune", "micro", "nano", "neovim", "vi", "vim"};
|
||||
const int numEditors = 7;
|
||||
|
||||
int compareString(const void *a, const void *b) {
|
||||
const char *str1 = *(const char **)a;
|
||||
@@ -73,6 +73,7 @@ void _error(const int shouldDebug, const int condition, const char *type, const
|
||||
|
||||
static void copyDir(const char *source, const char *destination, const char **rsyncArgs, const int rsyncArgsNumber, const int shouldDebug) {
|
||||
debug("Backuping... source: %s and destination: %s", source, destination);
|
||||
debug("Rsync has %d extra arguments", rsyncArgsNumber);
|
||||
pid_t pid = fork();
|
||||
|
||||
error(pid < 0, "program", "fork() faild. pid = %d", pid);
|
||||
@@ -87,6 +88,11 @@ static void copyDir(const char *source, const char *destination, const char **rs
|
||||
args[i+2] = (char*)source;
|
||||
args[i+3] = (char*)destination;
|
||||
args[i+4] = NULL; // execvp expect last arg to be NULL
|
||||
debug("rsync command:");
|
||||
for (int k = 0; k <= i+4; k++) {
|
||||
altDebug("%s ", args[k]);
|
||||
}
|
||||
altDebug("\n");
|
||||
}
|
||||
}
|
||||
execvp("rsync", args);
|
||||
@@ -204,8 +210,11 @@ int doesEditorExist (char *editorToCheck, int shouldDebug) { // Some exectua
|
||||
char *editor;
|
||||
if (strcmp(editorToCheck, "neovim") == 0) {
|
||||
editor = strdup("nvim"); // we must use strdup and not just copy as we would have modified editorToOpen in main
|
||||
}
|
||||
else {
|
||||
} else if (strcmp(editorToCheck, "helix") == 0) {
|
||||
editor = strdup("hx");
|
||||
} else if (strcmp(editorToCheck, "kakoune") == 0) {
|
||||
editor = strdup("kak");
|
||||
} else {
|
||||
editor = strdup(editorToCheck);
|
||||
}
|
||||
char *path_env = getenv("PATH");
|
||||
@@ -338,6 +347,8 @@ int openEditor(char *path, char *editor, int render, int shouldJumpToEndOfFile,
|
||||
pid_t editor_pid = fork();
|
||||
error(editor_pid < 0, "program", "fork() failed.");
|
||||
|
||||
// instead of reusing part of the codes, for any new editor copy an example and adapt it. This is in case we need a custom fix for an editor.
|
||||
|
||||
if (editor_pid == 0) {
|
||||
// =========================
|
||||
// CHILD: launch editor
|
||||
@@ -365,6 +376,30 @@ if (editor_pid == 0) {
|
||||
}
|
||||
}
|
||||
|
||||
error(1, "program", "execlp() failed.");
|
||||
// ---- MICRO ----
|
||||
} else if (strcmp(editor, "micro") == 0) {
|
||||
|
||||
if (render) {
|
||||
if (shouldJumpToEndOfFile) {
|
||||
debug("Running MICRO_VIVIFY=1 micro %s +99999", path);
|
||||
setenv("MICRO_VIVIFY", "1", 1);
|
||||
execlp("micro", "micro", path, "+999999", NULL);
|
||||
} else {
|
||||
debug("Running MICRO_VIVIFY=1 micro %s", path);
|
||||
setenv("MICRO_VIVIFY", "1", 1);
|
||||
execlp("micro", "micro", path, NULL);
|
||||
}
|
||||
} else {
|
||||
if (shouldJumpToEndOfFile) {
|
||||
debug("Running micro %s +999999", path);
|
||||
execlp("micro", "micro", path, "+999999", NULL);
|
||||
} else {
|
||||
debug("Running micro %s", path);
|
||||
execlp("micro", "micro", path, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
error(1, "program", "execlp() failed.");
|
||||
}
|
||||
|
||||
@@ -407,10 +442,127 @@ if (editor_pid == 0) {
|
||||
}
|
||||
|
||||
error(1, "program", "execlp() failed.");
|
||||
}
|
||||
// ---- HELIX ----
|
||||
} else if (strcmp(editor, "helix") == 0) {
|
||||
|
||||
// If render enabled → spawn viv in parallel
|
||||
if (render) {
|
||||
debug("Running the editor...");
|
||||
pid_t viv_pid = fork();
|
||||
error(viv_pid < 0, "program", "fork() failed.");
|
||||
|
||||
if (viv_pid == 0) {
|
||||
// GRANDCHILD → viv
|
||||
|
||||
|
||||
char viv_path[PATH_MAX];
|
||||
strncpy(viv_path, path, PATH_MAX - 1);
|
||||
viv_path[PATH_MAX - 1] = '\0';
|
||||
|
||||
if (shouldJumpToEndOfFile) {
|
||||
strncat(viv_path, ":99999",
|
||||
PATH_MAX - strlen(viv_path) - 1);
|
||||
}
|
||||
|
||||
debug("Running viv %s", viv_path);
|
||||
execlp("viv", "viv", viv_path, NULL);
|
||||
error(1, "program", "execlp() failed.");
|
||||
}
|
||||
// IMPORTANT: do NOT wait for viv
|
||||
}
|
||||
|
||||
// Now run helix (this replaces the child process)
|
||||
if (shouldJumpToEndOfFile) {
|
||||
strncat(path, ":99999", PATH_MAX);
|
||||
debug("Running hx %s", path);
|
||||
execlp("hx", "hx", path, NULL);
|
||||
} else {
|
||||
debug("Running hx %s", path);
|
||||
execlp("hx", "hx", path, NULL);
|
||||
}
|
||||
|
||||
error(1, "program", "execlp() failed.");
|
||||
}
|
||||
// ---- kakoune ----
|
||||
else if (strcmp(editor, "kakoune") == 0) {
|
||||
|
||||
// If render enabled → spawn viv in parallel
|
||||
if (render) {
|
||||
debug("Running the editor...");
|
||||
pid_t viv_pid = fork();
|
||||
error(viv_pid < 0, "program", "fork() failed.");
|
||||
|
||||
if (viv_pid == 0) {
|
||||
// GRANDCHILD → viv
|
||||
|
||||
|
||||
char viv_path[PATH_MAX];
|
||||
strncpy(viv_path, path, PATH_MAX - 1);
|
||||
viv_path[PATH_MAX - 1] = '\0';
|
||||
|
||||
if (shouldJumpToEndOfFile) {
|
||||
strncat(viv_path, ":99999",
|
||||
PATH_MAX - strlen(viv_path) - 1);
|
||||
}
|
||||
|
||||
debug("Running viv %s", viv_path);
|
||||
execlp("viv", "viv", viv_path, NULL);
|
||||
error(1, "program", "execlp() failed.");
|
||||
}
|
||||
// IMPORTANT: do NOT wait for viv
|
||||
}
|
||||
|
||||
// Now run nano (this replaces the child process)
|
||||
if (shouldJumpToEndOfFile) {
|
||||
debug("Running kak + %s", path);
|
||||
execlp("kak", "kak", "+", path, NULL);
|
||||
} else {
|
||||
debug("Running kak %s", path);
|
||||
execlp("kak", "kak", path, NULL);
|
||||
}
|
||||
|
||||
error(1, "program", "execlp() failed.");
|
||||
// ---- VI ----
|
||||
} else if (strcmp(editor, "vi") == 0) {
|
||||
|
||||
// If render enabled → spawn viv in parallel
|
||||
if (render) {
|
||||
debug("Running the editor...");
|
||||
pid_t viv_pid = fork();
|
||||
error(viv_pid < 0, "program", "fork() failed.");
|
||||
|
||||
if (viv_pid == 0) {
|
||||
// GRANDCHILD → viv
|
||||
|
||||
|
||||
char viv_path[PATH_MAX];
|
||||
strncpy(viv_path, path, PATH_MAX - 1);
|
||||
viv_path[PATH_MAX - 1] = '\0';
|
||||
|
||||
if (shouldJumpToEndOfFile) {
|
||||
strncat(viv_path, ":99999",
|
||||
PATH_MAX - strlen(viv_path) - 1);
|
||||
}
|
||||
|
||||
debug("Running viv %s", viv_path);
|
||||
execlp("viv", "viv", viv_path, NULL);
|
||||
error(1, "program", "execlp() failed.");
|
||||
}
|
||||
// IMPORTANT: do NOT wait for viv
|
||||
}
|
||||
|
||||
// Now run vi (this replaces the child process)
|
||||
if (shouldJumpToEndOfFile) {
|
||||
debug("Running vi +:$ %s", path);
|
||||
execlp("vi", "vi", "+:$", path, NULL);
|
||||
} else {
|
||||
debug("Running vi %s", path);
|
||||
execlp("vi", "vi", path, NULL);
|
||||
}
|
||||
|
||||
error(1, "program", "execlp() failed.");
|
||||
// ---- UNKNOWN EDITOR ----
|
||||
else {
|
||||
} else {
|
||||
error(1, "program", "Unknown editor.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user