summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md24
-rwxr-xr-xflashot-make.sh11
-rwxr-xr-xflashot.sh11
3 files changed, 31 insertions, 15 deletions
diff --git a/README.md b/README.md
index 5b9381e..addcdbc 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,27 @@
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
+very useful for turning exam paper questions and answers into flashcards,
+effortlessly
+
+## usage
+### flashot.sh
+- will prompt for name of flashcard collection
+- then prompts for number and type of card, then allows you to take a
+ screenshot
+- no environment variables or commandline arguments
+
+### flashot-make.sh
+- prompts to combine screenshots and import into anki, or to remove all current
+ screenshots
+- environment variable `FLASHOT_ANKI_USER` defines which anki user to copy
+ screenshots to; default is "Main"
## dependencies
- *nix system with X (wayland support later?)
-- [https://apps.ankiweb.net/](Anki)
+- [Anki](https://apps.ankiweb.net/)
- bc
- coreutils
-- [https://tools.suckless.org/dmenu/](dmenu)
-- [https://www.imagemagick.org/](ImageMagick)
-- [https://github.com/resurrecting-open-source-projects/scrot](scrot)
+- [dmenu](https://tools.suckless.org/dmenu/)
+- [ImageMagick](https://www.imagemagick.org/)
+- [scrot](https://github.com/resurrecting-open-source-projects/scrot)
diff --git a/flashot-make.sh b/flashot-make.sh
index 34c921f..f601a94 100755
--- a/flashot-make.sh
+++ b/flashot-make.sh
@@ -1,16 +1,12 @@
#!/bin/sh
combine() {
- for name in $(ls | cut -d- -f1-2 | uniq); do
+ for name in $(ls | cut -d- -f1-2 | uniq | sed 's/final//'); 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
@@ -29,19 +25,20 @@ cards_txt() {
if [ -z "$FLASHOT_ANKI_USER" ]; then FLASHOT_ANKI_USER=Main; fi
+# main
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
+ if [ -d /tmp/flashot/final ]; then rm -rf /tmp/flashot/final; fi
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
+ 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
diff --git a/flashot.sh b/flashot.sh
index bc56f68..b148016 100755
--- a/flashot.sh
+++ b/flashot.sh
@@ -1,7 +1,12 @@
#!/bin/sh
mkdir -p /tmp/flashot
-photoname=$(ls /tmp/flashot | cut -d- -f1 | uniq | dmenu -i -p "name of screenshots? (no hyphens)")
+if [ -d /tmp/flashot ]; then
+ photoname=$(ls /tmp/flashot | cut -d- -f1 | uniq | dmenu -i -p "name of screenshots? (no hyphens)")
+else
+ photoname=$(dmenu -i -p "name of screenshots? (no hyphens)")
+fi
+
case "$photoname" in
*-* )
printf "ok" | dmenu -p "not a valid name (no hyphens!)"
@@ -13,7 +18,7 @@ case "$photoname" in
;;
esac
-photonumber=$(basename -a $(ls /tmp/flashot/"$photoname"*) | cut -d- -f2 | uniq | tac | dmenu -i -p "number?")
+photonumber=$(basename -a $(ls /tmp/flashot/"$photoname"* 2>/dev/null) 2>/dev/null | cut -d- -f2 | uniq | tac | dmenu -i -p "number?")
type=$(printf "question\nanswer" | dmenu -i -p "question or answer?")
if [ "$type" = "question" ]; then
@@ -22,7 +27,7 @@ else
type=a
fi
-partnumber=$(ls /tmp/flashot/"$photoname"-"$photonumber"-"$type"-* | tail -n1 | cut -d- -f4 | cut -d. -f1)
+partnumber=$(ls /tmp/flashot/"$photoname"-"$photonumber"-"$type"-* 2>/dev/null | tail -n1 | cut -d- -f4 | cut -d. -f1)
if [ -z "$partnumber" ]; then
partnumber=0
else