From 5679260d88a70baf8237cff1b913b51034462bd6 Mon Sep 17 00:00:00 2001 From: Bryan Jenks Date: Tue, 11 Feb 2020 21:04:02 -0800 Subject: [PATCH] add flash script --- flash | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 flash diff --git a/flash b/flash new file mode 100755 index 0000000..3511f16 --- /dev/null +++ b/flash @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +set -e + +if [ ! -d $HOME/.flash ];then # If Directory does NOT exist + echo "No '.flash/' directory, make it? y/n" + read RESPONSE + if [ "$(echo $RESPONSE | tr '[:upper:]' '[:lower:]')" = "n" ];then # Does user want the script to make the directory + exit # Response NO = Exit + elif [ "$(echo $RESPONSE | tr '[:upper:]' '[:lower:]')" = "y" ]; then # Does user want the script to make the directory + mkdir $HOME/.flash + touch $HOME/.flash/deck.csv + echo "Your './flash' directory has been made and your 'deck.csv' file is ready for your flashcard data" + exit + else + echo "invalid choice, please select either 'y' or 'n'" + exit + fi +fi +if [ ! -e $HOME/.flash/deck.csv ];then # If the Deck file does NOT exist in .flash/ + echo "No 'deck.csv' in '.flash/', make it? y/n" + read RESPONSE + if [ "$(echo $RESPONSE | tr '[:upper:]' '[:lower:]')" = "n" ];then # Does user want the script to make the deck.csv file + exit # Response NO = Exit + elif [ "$(echo $RESPONSE | tr '[:upper:]' '[:lower:]')" = "y" ]; then # Does user want the script to make the deck.csv file + touch $HOME/.flash/deck.csv + echo "Your 'deck.csv' file has been made go fill it with flashcard data!" + exit + else + echo "invalid choice, please select either 'y' or 'n'" + exit + fi +fi + +# Configuration +FILE="$HOME/.flash/deck.csv" + +main(){ + IFS=$'\t'; read -a q <<<$(shuf -n 1 "$FILE") + echo "====================================================" + echo "Category: ${q[0]}" + echo "Question: ${q[1]}" + read _ + echo "Answer: ${q[2]}" + echo '' +} + +while true; do + main +done