omoidasu

a flashcard review system built on oboeru
git clone anongit@rnpnr.xyz:omoidasu.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 85fef67df4d648e406c726c0f0fd78522117cf95
Author: Randy Palamar
Date:   Mon, 16 Aug 2021 18:33:40 -0600

initial import of omoidasu

some scripts will probably be modified as they see more use but they
are working now

Diffstat:
ALICENSE | 15+++++++++++++++
AMakefile | 21+++++++++++++++++++++
AREADME.md | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acard2html | 19+++++++++++++++++++
Afetchcard | 10++++++++++
Afurigana | 7+++++++
Agencard | 39+++++++++++++++++++++++++++++++++++++++
Anextcardid | 11+++++++++++
Aomoidasu | 45+++++++++++++++++++++++++++++++++++++++++++++
Areview | 30++++++++++++++++++++++++++++++
Arubify | 10++++++++++
11 files changed, 267 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,15 @@ +ISC License (ISC) + +© 2021 Randy Palamar <palamar@ualberta.ca> + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/Makefile b/Makefile @@ -0,0 +1,21 @@ +PREFIX=/usr/local + +SCRIPTS =\ + card2html\ + fetchcard\ + furigana\ + gencard\ + nextcardid\ + omoidasu\ + review\ + rubify + +default: + @echo "usage: make [install|uninstall]" + +install: + mkdir -p $(PREFIX)/bin + install -m 0755 $(SCRIPTS) $(PREFIX)/bin + +uninstall: + rm $(SCRIPTS:%=$(PREFIX)/bin/%) diff --git a/README.md b/README.md @@ -0,0 +1,60 @@ +# omoidasu - 思い出す + +A collection of scripts for working with +[oboeru](https://github.com/0x766F6964/oboeru) + +## Installation + +Use `make` to install (using root as needed): + + make install + +Scripts are installed to `PREFIX=/usr/local` by default. + +## Directory Structure + +These scripts assume a directory structure as follows: + + ./ + config + deck1.deck + deck1/ + cardid1/ + front.md + back.md + image.png + audio.ogg + extra.html + cardid2/ + ... + deck2.deck + deck2/ + ... + ... + +## Scripts + +All scripts in this repo should work with standard POSIX compliant core +utils. If they don't open an issue. + +* `omoidasu`: creates a default `config` in the current directory. +* `gencard`: creates a new card and associated directory for the specified + deck and opens the front and back in an `$EDITOR`. +* `review`: ties all the programs together starts reviews on the specified decks +* `card2html`: converts the front and back of the card to the format + expected by oboeruhttp +* `fetchcard`: takes the deck and id output by oboeru and finds the cards path +* `nextcardid`: finds the next available id in a supplied deck file + +The following are specific for studying Japanese: + +* `furigana`: uses `kakasi` and `sed` to convert text on stdin into furigana + reading pairs expected by `rubify`. +* `rubify`: converts furigana reading pairs from `furigana` into html ruby text + +## Extra + +The tag `==EXTRA==` can be used on the card to inject the file +`extra.html` into the output html. It can be used to keep the cards +clean and readable when you want to include something complicated like +a pitch graph. diff --git a/card2html b/card2html @@ -0,0 +1,19 @@ +#!/bin/sh + +# takes a path from stdin and outputs the card data in a format usable +# by oboeruhttp on stdout + +read path +front=$(smu "$path"/front.md | tr -d '\n' | + sed 's;src="\([^"]*\)";src="/_/'$path'/\1";g') +back=$(smu "$path"/back.md | tr -d '\n' | + sed 's;src="\([^"]*\)";src="/_/'$path'/\1";g') + +extra="$path"/extra.html +if [ -f "$extra" ]; then + extra=$(cat "$extra" | tr -d '\n') + front="$(echo "$front" | sed 's|==EXTRA==|'"$extra"'|g')" + back="$(echo "$back" | sed 's|==EXTRA==|'"$extra"'|g')" +fi + +printf "%s\t%s" "$front" "$back" diff --git a/fetchcard b/fetchcard @@ -0,0 +1,10 @@ +#!/bin/sh + +# takes the output of oboeru finds a card's path + +read input + +deck=$(echo "$input" | cut -f 1 | cut -d '.' -f 1) +id=$(echo "$input" | cut -f 2) + +printf "%s\n" "$deck/$id" diff --git a/furigana b/furigana @@ -0,0 +1,7 @@ +#!/bin/sh + +# generates furigana in the format used by the rubify script +# this is a little hacky + +kakasi -JH -Fl":" -Fr"}" -f -s -S"{" -i utf-8 \ +| sed -e 's:^\(.\):{\1:' -e 's:\({\([^{]*\)}\):\[\2\]:g' -e 's:{::g' diff --git a/gencard b/gencard @@ -0,0 +1,39 @@ +#!/bin/sh + +# generates a card with the next available id in the provided deck +# ledger. a folder is created for it and the templates files are copied in. +# finally the new card is opened in an editor + +. ./config + +usage() { + echo "$0 name.deck [extra]" + exit 1 +} + +[ $# -lt 1 ] && usage +[ $# -gt 2 ] && usage + +tmp=$(mktemp) +die() { + [ -f $tmp ] && rm -f $tmp +} +trap die EXIT INT TERM + +id=$(nextcardid "$1") +time=$(date $TIMEFMT) + +printf "%s\t%s\t%s\t%d\t%s\n" "$id" "$time" "$time" 0 "$2" >> "$1" + +sort "$1">|"$tmp" +mv "$tmp" "$1" + +deck=$(echo "$1" | cut -d '.' -f 1) +path=$(printf "%s/%s" "$deck" "$id") +front=${FRONT_TEMP:-front} +back=${BACK_TEMP:-back} + +mkdir -p $path +cp $front $back $path/ + +$EDITOR "$path/$back" "$path/$front" diff --git a/nextcardid b/nextcardid @@ -0,0 +1,11 @@ +#!/bin/sh + +# finds and outputs the next missing id in deck ledger +[ ! -f "$1" ] && echo 0 && exit 0 + +awk '{ + w = length($1); + for (i = p + 1; i < $1; i++) { + exit + } +} {p = $1} END {printf "%0"w"i\n", p + 1}' $1 diff --git a/omoidasu b/omoidasu @@ -0,0 +1,45 @@ +#!/bin/sh + +# create a config file in the current directory + +if [ -f ./config ]; then + echo "config already exists" + exit 1 +fi + +cat > config <<EOF +# omoidasu config + +# program used to determine the location of the cards requested by oboeru +FETCHCARD=fetchcard + +# program used to convert the cards into single line input apporiate +# for oboeruhttp. should output "%s\t%s" (notice the "\t") +CONVERTCARD=card2html + +# futher filter for card after CONVERTCARD +FILTER=rubify + +# fmt for timestamping new cards. needs to be the same format that was +# used in config.h when compiling oboeru. backup timestamp can be anything +TIMEFMT="+%Y年%m月%d日%H時%M分" + +# templates to use for new cards. the variables can be commented or empty +# the default names will be "front" and "back" +FRONT_TEMP="front.md" +BACK_TEMP="back.md" + +# port to run oboeruhttp on +PORT=6969 + +# html strings to pass to oboeruhttp +PASS="当たり" +FAIL="外れ" +QUIT="止める" +SHOW="示す" +BYE="(=^ᆺ^)ノ<br>バイバイ~" + +# use these to overwrite the default env variables if you want +#EDITOR=vis +#VISUAL=vis +EOF diff --git a/review b/review @@ -0,0 +1,30 @@ +#!/bin/sh + +. ./config + +usage() { + echo "usage: $0 cards.deck [cards1.deck ...]" + exit 1 +} + +[ $# -lt 1 ] && usage +[ ! -f $1 ] && usage + +fifo=fifo.$$ +die() { + rm -f $fifo +} +trap die EXIT INT TERM + +mkfifo -m 0600 $fifo + +oboeru $fifo "$@" \ +| $FETCHCARD \ +| $CONVERTCARD \ +| $FILTER \ +| oboeruhttp -p "$PORT" -F "$FAIL" -P "$PASS" -Q "$QUIT" -S "$SHOW" -q "$BYE" \ +> $fifo & + +browser "localhost:$PORT" + +wait diff --git a/rubify b/rubify @@ -0,0 +1,9 @@ +#!/bin/sed -f + +# convert kanji reading pairs of the form [kanji:reading] to ruby text +# ex: echo "[少女:しょうじょ]" | rubify -> <ruby>少女<rt>しょうじょ</rt></ruby> +# these can be produced with this hack: +# kakasi -JH -Fl":" -f -s -S"[" -i utf-8 | \ +# sed -e 's;^\(.\);\[\1;' -e 's;\[\([^]]*\[\);\1;g' + +s;\[\([^]:]*\):\([^]]*\)\];<ruby>\1<rt>\2</rt></ruby>;g +\ No newline at end of file