diff options
| author | not_a_robot06 <temporarythrowaway@tutamail.com> | 2025-07-06 23:07:38 +0100 |
|---|---|---|
| committer | not_a_robot06 <temporarythrowaway@tutamail.com> | 2025-07-06 23:07:38 +0100 |
| commit | be35de785e659cc080dd902cf296b5ce270e2e3f (patch) | |
| tree | d2c5f630b79aaa299d8922f7584a406d15c00672 | |
| parent | b8fc75f962891aa7def3b1829d83534350dfe21d (diff) | |
| download | flashot-be35de785e659cc080dd902cf296b5ce270e2e3f.tar.gz flashot-be35de785e659cc080dd902cf296b5ce270e2e3f.tar.bz2 flashot-be35de785e659cc080dd902cf296b5ce270e2e3f.zip | |
first proper version
- use hyphens only for separation
- only two scripts: one for screenshots and one for making the cards
- add README
- a little bit of error checking
- TODO: if question or answer non existent, then don't break cards.txt
| -rw-r--r-- | README.md | 14 | ||||
| -rwxr-xr-x | cards.sh | 22 | ||||
| -rwxr-xr-x | flashcards.sh | 19 | ||||
| -rwxr-xr-x | flashot-make.sh | 50 | ||||
| -rwxr-xr-x | flashot.sh | 32 | ||||
| -rwxr-xr-x | question_shot.sh | 21 |
6 files changed, 96 insertions, 62 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b9381e --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# flashot +make flashcards out of screenshots, without any manual dragging and dropping! +multiple screenshots for one side of a flashcard? no problem! + +very useful for turning exam paper questions and answers into flashcards, effortlessly + +## dependencies +- *nix system with X (wayland support later?) +- [https://apps.ankiweb.net/](Anki) +- bc +- coreutils +- [https://tools.suckless.org/dmenu/](dmenu) +- [https://www.imagemagick.org/](ImageMagick) +- [https://github.com/resurrecting-open-source-projects/scrot](scrot) diff --git a/cards.sh b/cards.sh deleted file mode 100755 index 7df324e..0000000 --- a/cards.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# file prefixes cant have underscores or dashes in their names -if [ $(ls cards.txt) ]; then - rm cards.txt -fi - -for name in $(ls *.png | cut -d- -f1 | uniq); do - old_card=-1 - for file in "$name"*; do - echo "file = $file" - card=$(echo "$file" | cut -d_ -f2 | cut -d- -f1) - echo "card = $card" - if [[ "$card" = "$old_card" ]] - then - echo "$file\"/>;Card_$card" >> cards.txt - else - # TODO: use printf as echo -n is not portable - /bin/echo -n "<img src=\"$file\"/>;<img src=\"" >> cards.txt - fi - old_card=$card - done -done diff --git a/flashcards.sh b/flashcards.sh deleted file mode 100755 index 242d44a..0000000 --- a/flashcards.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -action=$(echo "make flashcards\nreset" | dmenu -i -p "action?") -if [ "$action" = "make flashcards" ]; then - confirm=$(echo "no\nyes" | dmenu -i -p "are you sure? screenshot names can overwrite others in media folder") - if [ "$confirm" = "yes" ]; then - cd /tmp/question_shots - combine.sh - cd final - cards.sh - cp *.png ~/.local/share/Anki2/Main/collection.media/ - thunar /tmp/question_shots/final & - echo "yay" | dmenu -p "done! import cards.txt into Anki. remember to reset if done" - fi -elif [ "$action" = "reset" ]; then - confirm=$(echo "no\nyes" | dmenu -i -p "are you sure? this action cannot be undone") - if [ "$confirm" = "yes" ]; then - rm -rf /tmp/question_shots/ - fi -fi diff --git a/flashot-make.sh b/flashot-make.sh new file mode 100755 index 0000000..34c921f --- /dev/null +++ b/flashot-make.sh @@ -0,0 +1,50 @@ +#!/bin/sh +combine() { + for name in $(ls | cut -d- -f1-2 | uniq); do + magick "$name"-q* -append final/"$name"-0.png + magick "$name"-a* -append final/"$name"-1.png + done +} + +cards_txt() { + if [ $(ls cards.txt) ]; then + rm cards.txt + fi + + for name in $(ls *.png | cut -d- -f1 | uniq); do + old_card=-1 + for file in "$name"*; do + card=$(printf "$file" | cut -d- -f2 | cut -d. -f1) + if [[ "$card" = "$old_card" ]] + then + echo "$file\"/>;Card_$card" >> cards.txt + else + printf "<img src=\"%s\"/>;<img src=\"" "$file" >> cards.txt + fi + old_card=$card + done + done +} + +if [ -z "$FLASHOT_ANKI_USER" ]; then FLASHOT_ANKI_USER=Main; fi + + +action=$(printf "make flashcards\nreset" | dmenu -i -p "action?") +if [ "$action" = "make flashcards" ]; then + confirm=$(printf "no\nyes" | dmenu -i -p "are you sure? screenshot names can overwrite others in media folder") + if [ "$confirm" = "yes" ]; then + cd /tmp/flashot + mkdir -p final + combine + cd final + cards_txt + cp *.png ~/.local/share/Anki2/"$FLASHOT_ANKI_USER"/collection.media/ + anki /tmp/flashot/final/cards.txt + fi + +elif [ "$action" = "reset" ]; then + confirm=$(printf "no\nyes" | dmenu -i -p "are you sure? this action cannot be undone") + if [ "$confirm" = "yes" ]; then + rm -rf /tmp/flashot/ + fi +fi diff --git a/flashot.sh b/flashot.sh new file mode 100755 index 0000000..bc56f68 --- /dev/null +++ b/flashot.sh @@ -0,0 +1,32 @@ +#!/bin/sh +mkdir -p /tmp/flashot + +photoname=$(ls /tmp/flashot | cut -d- -f1 | uniq | dmenu -i -p "name of screenshots? (no hyphens)") +case "$photoname" in + *-* ) + printf "ok" | dmenu -p "not a valid name (no hyphens!)" + exit 1 + ;; + final ) + printf "ok" | dmenu -p "not a valid name (don't call it \"final\")" + exit 1 + ;; +esac + +photonumber=$(basename -a $(ls /tmp/flashot/"$photoname"*) | cut -d- -f2 | uniq | tac | dmenu -i -p "number?") + +type=$(printf "question\nanswer" | dmenu -i -p "question or answer?") +if [ "$type" = "question" ]; then + type=q +else + type=a +fi + +partnumber=$(ls /tmp/flashot/"$photoname"-"$photonumber"-"$type"-* | tail -n1 | cut -d- -f4 | cut -d. -f1) +if [ -z "$partnumber" ]; then + partnumber=0 +else + partnumber=$(printf "%s+1\n" "$partnumber" | bc) +fi + +scrot -s /tmp/flashot/"$photoname"-"$photonumber"-"$type"-"$partnumber".png diff --git a/question_shot.sh b/question_shot.sh deleted file mode 100755 index a511dec..0000000 --- a/question_shot.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -mkdir -p /tmp/question_shots -photoname=$(ls /tmp/question_shots | cut -d_ -f1 | uniq | dmenu -i -p "name of screenshots? (no underscores or hyphens)") -echo "$photoname" -photonumber=$(basename -a $(ls /tmp/question_shots/"$photoname"*) | cut -d_ -f2 | cut -d- -f1 | uniq | tac | dmenu -i -p "number?") - -type=$(echo "question\nanswer" | dmenu -i -p "question or answer?") -if [ "$type" = "question" ]; then - type=q -else - type=a -fi - -partnumber=$(ls /tmp/question_shots/"$photoname"_"$photonumber"-"$type"-* | tail -n1 | cut -d- -f3 | cut -d. -f1) -if [ -z "$partnumber" ]; then - partnumber=0 -else - partnumber=$(echo "$partnumber"+1 | bc) -fi - -scrot -s /tmp/question_shots/"$photoname"_"$photonumber"-"$type"-"$partnumber".png |
