#!/usr/bin/env bash #==============================================================# # # AUTHOR: # Bryan Jenks # - www.bryanjenks.xyz # - https://github.com/tallguyjenks/flash.sh # # SOURCE: # This file is based off of the one presented in this YouTube Video by nixcasts: # - https://www.youtube.com/watch?v=lX8jqo70r1I # # PURPOSE: # To have a command line flash card tool with minimal code, plain text input and output # # VISION: # The goal i have for this script is a basic level emulation of ANKI to where i have a way to # keep track of a score for each item in each selected deck so that it can pick from a selection # of the lowest scoring items and shuf them to the user for reenforcement of active recall. # # DEPENDENCIES: # fzf - https://github.com/junegunn/fzf # bat - https://github.com/sharkdp/bat #==============================================================# PWD="$(pwd)" # Remember User's Starting Directory DIR="$HOME/.local/share/flash" # Where Decks Are Located EXAMPLE_DECK="$HOME/.local/share/flash/deck.csv" COUNTER=0 DIR_MADE_MSG=" Your '~/.local/share/flash' directory has been made and your 'deck.csv' file is ready for you to enter your flashcard data " NO_DECKS=" No decks were found, please make a new deck using ':' as a delimiter in a '.csv' file in the '.local/share/flash' directory. An example of a card: 'Math:What is the square root of 4?:2:0' " DECK_TEMPLATE="History:When was the declaration of independence signed?:1776:0 Math:What is the square root of 4?:2:4 Science:What is the charge of a proton?:Positive:2 Philosophy:What was socrates known as?:The Gadfly of Athens:0 Programming:What is the typical starting value of an array?:0:5 History:What did Abraham Lincoln Typically Keep In his hat?:Mail:0 Math:what is the first 2 decimal places of PI:3.14:4 Science:What is the charge of an electron?:Negative:3 Programming:What does OOP stand for?:Object Oriented Programming:2 History:What did socrates drink to commit suicide?:Hemlock Tea:2 Math:What is the equation for a slope of a line?:y=mx+b:4 Science:What is the charge of a neutron?:Neutral:1 Programming:What is Vim?:God's Text Editor:999 History:What were the british known buy during the american revolution?:The redcoats:1 Math:What is the value of this equation - log10(100)?:2:0 Science:What are protons/neutrons/electrons made of?:quarks:5 Programming:What does RAM stand for?:Random Access Memory:1 History:What was the year 2000 also known as?:Y2K:0 Math:What is the formula for mean?:Sum/count:4 Science:What is cold?:The absense of heat:3 Programming:What languages are the worst?:Proprietary:999 History:When did man land on the moon?:1969:4 Math:10^3=?:1000:1 Science:The _____ ______ Project mapped all of man's genes.:Human Genome:3 Programming:What is the best computer to program on?:Thinkpad:999 History:When was flash.sh created?:April 2020:999 Math:What do you call a number only divisible by itself and 1?:Prime:0 Science:What is the distance between the Earth and Sol called?:An Astronomical Unit (AU):1 Programming:Best operating system?:Arch, because BTW i run Arch:999 " if [ ! -d $DIR ];then # If Directory does NOT exist echo "No '.local/share/flash' directory, make it? y/n" read RESPONSE case "$RESPONSE" in [Nn]) exit ;; [Qq]) exit ;; [Yy]) mkdir "$DIR" && touch $EXAMPLE_DECK && echo "$DECK_TEMPLATE" >> $EXAMPLE_DECK && echo "$DIR_MADE_MSG" ;; *) echo "invalid choice, please select either 'y' or 'n'" ;; esac fi cd "$DIR" if [ "$(find -maxdepth 999 -iname "*.csv" | wc -l)" = 0 ]; then # If there are no flashcard decks available echo "$NO_DECKS" && cd "$PWD" && exit fi # Show pretty FZF preview of decks using BAT DECK="$(find -maxdepth 999 -iname "*.csv" | fzf --preview='bat --theme="Solarized (dark)" --style=numbers --color=always {} | head -500')" main(){ IFS=$':'; read -a q <<<$(sort "$DECK" -n --field-separator=: --key=4 | head | shuf -n 1) clear echo "====================================================" echo "Cards Reviewed: $COUNTER" echo "Category: ${q[0]}" echo "Question: ${q[1]}" echo '' read -sn 1 NEXT if [ "$NEXT" = q ]; then cd "$PWD" && exit fi echo "Answer: ${q[2]}" echo '' echo "====================================================" echo '' echo "How Difficult Was This Question?" echo '' echo "Hard [1] Difficult [2] Normal [3] Mild [4] Easy [5]" echo '' read -sn 1 DIFFICULTY_SCORE clear COUNTER="$(($COUNTER+1))" # Increment count for above test and card review count increment if [ "${q[3]}" = 0 ]; then NEW_ITEM_SCORE=0 case "$DIFFICULTY_SCORE" in [123]) NEW_ITEM_SCORE=0 ;;#HARD DIFFICULTY & NORMAL 4) NEW_ITEM_SCORE=1 ;;#MILD 5) NEW_ITEM_SCORE=2 ;;#EASY *) NEW_ITEM_SCORE=0 ;;#INVALID esac elif [ "${q[3]}" = 1 ]; then case "$DIFFICULTY_SCORE" in 1) NEW_ITEM_SCORE=0 ;;#HARD 2) NEW_ITEM_SCORE=0 ;;#DIFFICULT 3) NEW_ITEM_SCORE=1 ;;#NORMAL 4) NEW_ITEM_SCORE=2 ;;#MILD 5) NEW_ITEM_SCORE=3 ;;#EASY *) NEW_ITEM_SCORE=1 ;;#INVALID esac else case "$DIFFICULTY_SCORE" in 1) NEW_ITEM_SCORE="$((${q[3]}-2))" ;;#HARD 2) NEW_ITEM_SCORE="$((${q[3]}-1))" ;;#DIFFICULTY 3) NEW_ITEM_SCORE="${q[3]}" ;;#NORMAL 4) NEW_ITEM_SCORE="$((${q[3]}+1))" ;;#MILD 5) NEW_ITEM_SCORE="$((${q[3]}+2))" ;;#EASY *) NEW_ITEM_SCORE="${q[3]}" ;;#INVALID esac fi # Update item score for each flashcard item sed -i "s/${q[0]}:${q[1]}:${q[2]}:${q[3]}/${q[0]}:${q[1]}:${q[2]}:$NEW_ITEM_SCORE/g" "$DECK" } while true; do main done