flashcard.sh/flashcard.sh

38 行
803 B
Bash

#!/bin/bash
#Enumerate memorization items
for item in `cut -f 1 "$1"`; do
front+=($item)
done
#Enuerate answers
for item in `cut -f 2 "$1" | sed -e 's: :_:g'`; do
back+=($item)
done
#Generate random flash card order
order=$(shuf -e $(seq 0 $(expr ${#front[@]} \- 1)))
flashcards(){
for card in ${order[@]}; do
whiptail --msgbox "Unmemorized ${#repeat[@]} \n\n ${front[$card]} |" --ok-button "Show" 15 60
whiptail --yesno "Unmemorized ${#repeat[@]} \n\n ${front[$card]} | ${back[$card]}" --yes-button "Know" --no-button "Don't know" 15 60
#Catalogue unmemorized cards
if [[ $? = 1 ]]; then
repeat+=($card)
fi
done
#Load unmemorized cards back into deck and repeat
if [[ "${#repeat[@]}" > 0 ]]; then
order="${repeat[@]}"
unset repeat
flashcards
else
exit 0
fi
}
flashcards
exit 0