aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/notes/README.md
blob: 42f989f4ca4b0c2fc7b115ca05a3f62db0c6d93c (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# notes

`bash-notes` in the drawer: a tile with the note count, a list, and an editor
that writes, edits and deletes notes in place. The store is `notes.sh`'s own,
under its `BASEDIR` (default `~/.local/share/bash-notes`), so the page and the
CLI work on the same notes: `db.json` is the index and `notes/` holds one file
per note, named by its creation time in epoch seconds.

- The list is newest first with a title search. A row opens the note.
- The title lives only in `db.json` and the body only in the note's file, as
  `notes.sh` keeps them.
- The editor shows the title and the body, with a **Preview** switch that
  renders the body as Markdown. Qt's Markdown is a subset: headings, emphasis,
  lists, links, inline code and quotes render; tables and fenced-code
  highlighting do not.
- **Save** is two clicks: the first writes the note, the second reads
  **Commit & push?**, writes whatever you have typed since, and pushes it.
  **Delete** asks first, then removes the note and pushes the removal. With git
  off there is no second half, so Save writes and returns in one.
- Leaving the editor with **Cancel**, the back arrow, Escape or a click
  outside drops unsaved text. The save is the explicit act.
- **Update list** runs `git pull` and stamps `git.lastpull`.

Nothing pulls on open, so the list shows local state until **Update list** is
pressed.

**The page writes what `notes.sh` reads.** `id`, `title` and `file` are stored
as strings, because `notes.sh` looks a note up with `select(.id == $i)` and
would stop finding a note written with a numeric id. Only the `.notes` array is
replaced; `params` and `git` carry through untouched.

**A write is refused when `db.json` cannot be read as the index.** A
`git pull --rebase --autostash` whose stash pop conflicts over a remote change
leaves merge markers in `db.json` and still exits 0; reading that as "no notes"
and writing it back would delete every title. The write reports
`db.json could not be read; resolve it in <BASEDIR>` and leaves the file for
git to resolve instead. A change made on two machines at once conflicts here
for the same reason it conflicts for `notes.sh`: every machine appends to the
one `db.json`.

A write that fails is reported rather than assumed. A body is written by a
`Process` running `cat > <file>` with the text on stdin, not by a `FileView`:
`setText` with an empty string, on a path that view has not loaded, creates no
file and reports no error, which once put an empty note into `db.json` with no
file beside it. `cat` takes any content at any length, including none, and its
exit code is the outcome; a failed commit or push shows git's own message.

**Git order.** `notes.sh` pulls before it writes and commits after, and the
page keeps that order: creating a note pulls first, then writes on what the
pull brought in, and the commit and push are the second click. The one
difference is `--autostash`, because a save here is two clicks and an
unconfirmed save leaves `db.json` uncommitted where `notes.sh`'s write and
commit are one invocation. `lastpull` is stamped after a pull that worked, not
before it.

`Notes.js` holds the parsing, sorting and transforms, tested with:

    node desktop/modules/notes/test_notes.js

Not here: opening a note in `$EDITOR`, backups (`--backup` / `--restore`),
Markdown export, `--showconf` / `--userconf`, and pulling on open.