Add real usage scripts an_sync and interactive_runner
dkl9

dkl9 commited on 2025-337 23:22:46
Showing 2 changed files, with 40 additions and 0 deletions.

... ...
@@ -0,0 +1,31 @@
1
+#!/bin/sh
2
+# an_sync - interactively update the deck with new cards from commonplace
3
+# usage: an_sync [commonplace [deckfile]]
4
+
5
+AN="${1:-$HOME/perennial/general_notes/arbitrary_notes.txt}"
6
+DECK="${2:-personal.rec}"
7
+DC=`mktemp`
8
+NL=`mktemp`
9
+NN=`mktemp`
10
+
11
+grep '^BaseNote:' <"$DECK" | sed 's/^BaseNote: //' >"$DC"
12
+
13
+sed '/#memoire/,/^$/ p; d' <"$AN" | grep -v '#memoire\|^$' | tac >"$NL"
14
+while read -r CARD
15
+do
16
+    if grep -Fq "$CARD" "$DC"
17
+    then
18
+        break
19
+    fi
20
+    printf '%s\n\n' "$CARD"
21
+done <"$NL" | tee "$NN"
22
+
23
+CN=`wc -l "$NN"`
24
+CN="${CN%% *}"
25
+printf 'Add all these (%d cards)? ' "$((CN/2))"
26
+read RESP
27
+if [ "${RESP#y}" != "$RESP" ] || [ "${RESP#Y}" != "$RESP" ]
28
+then
29
+    src/main.lua a <"$NN"
30
+fi
31
+rm "$DC" "$NL" "$NN"
... ...
@@ -0,0 +1,9 @@
1
+#!/bin/sh
2
+
3
+X='true' # hacky way to run the shell only on iterations past the first
4
+while "$X"
5
+do
6
+    printf '\e]2;%s\a' 'Memoire'
7
+    src/main.lua r
8
+    X="$SHELL"
9
+done
0 10