summaryrefslogtreecommitdiff
path: root/flashot-make.sh
blob: 34c921f66271c28305855210e9a18a05afd37db6 (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
#!/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