resolves #9 + tidying and commenting
This commit is contained in:
parent
4427fdd48d
commit
b2a3168454
63
flash
63
flash
|
|
@ -23,31 +23,40 @@
|
||||||
# bat - https://github.com/sharkdp/bat
|
# bat - https://github.com/sharkdp/bat
|
||||||
#==============================================================#
|
#==============================================================#
|
||||||
|
|
||||||
#ANSI FOREGROUND ESCAPE COLORS
|
# USER CUSTOMIZABLE VARIABLES
|
||||||
RED='\033[0;31m'
|
CARD_POOL_SIZE=10 # How large the pool size is for shuf to draw from
|
||||||
LRED='\033[1;31m'
|
SEARCH_DEPTH=999 # How many levels to recursively search for .csv's in .local/share/flash
|
||||||
YELLOW='\033[1;33m'
|
|
||||||
GREEN='\033[0;32m'
|
|
||||||
LGREEN='\033[1;32m'
|
|
||||||
ORANGE='\033[0;33m'
|
|
||||||
LGREY='\033[0;37m'
|
|
||||||
WHITE='\033[1;37m'
|
|
||||||
NC='\033[0m' # No Color
|
|
||||||
|
|
||||||
#ANSI BACKGROUND ESCAPE COLORS
|
|
||||||
WHITEBG='\033[1;47m'
|
|
||||||
|
|
||||||
|
# ANSI FOREGROUND ESCAPE COLORS
|
||||||
|
RED='\033[0;31m'
|
||||||
|
LRED='\033[1;31m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
LGREEN='\033[1;32m'
|
||||||
|
ORANGE='\033[0;33m'
|
||||||
|
LGREY='\033[0;37m'
|
||||||
|
WHITE='\033[1;37m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
# ANSI BACKGROUND ESCAPE COLORS
|
||||||
|
WHITEBG='\033[1;47m'
|
||||||
# FONT FORMAT EXCAPE CODES
|
# FONT FORMAT EXCAPE CODES
|
||||||
BOLD='\e[1m'
|
BOLD='\e[1m'
|
||||||
|
|
||||||
PWD="$(pwd)" # Remember User's Starting Directory
|
# Remember User's Starting Directory
|
||||||
DIR="$HOME/.local/share/flash" # Where Decks Are Located
|
PWD="$(pwd)"
|
||||||
EXAMPLE_DECK="$HOME/.local/share/flash/deck.csv"
|
# Where Decks Are Located
|
||||||
COUNTER=0
|
DIR="$HOME/.local/share/flash"
|
||||||
|
# Where the example deck with be placed and named
|
||||||
|
EXAMPLE_DECK="$HOME/.local/share/flash/deck.csv"
|
||||||
|
# Iterator for Count of cards reveiwed
|
||||||
|
COUNTER=0
|
||||||
|
# Success message of setup process
|
||||||
DIR_MADE_MSG="
|
DIR_MADE_MSG="
|
||||||
Your ${LRED}~/.local/share/flash${NC} directory has been made and
|
Your ${LRED}~/.local/share/flash${NC} directory has been made and
|
||||||
your ${ORANGE}deck.csv${NC} file is ready for you to enter your flashcard data
|
your ${ORANGE}deck.csv${NC} file is ready for you to enter your flashcard data
|
||||||
"
|
"
|
||||||
|
# User has .local/share directory but no decks inside
|
||||||
NO_DECKS="
|
NO_DECKS="
|
||||||
No decks were found, please make a new deck
|
No decks were found, please make a new deck
|
||||||
using ${ORANGE}:${NC} as a delimiter in a ${ORANGE}.csv${NC} file in
|
using ${ORANGE}:${NC} as a delimiter in a ${ORANGE}.csv${NC} file in
|
||||||
|
|
@ -56,6 +65,7 @@ the ${LRED}.local/share/flash${NC} directory.
|
||||||
An example of a card:
|
An example of a card:
|
||||||
${GREEN}Math:What is the square root of 4?:2:0${NC}
|
${GREEN}Math:What is the square root of 4?:2:0${NC}
|
||||||
"
|
"
|
||||||
|
# The example flashcard deck to be made
|
||||||
DECK_TEMPLATE="History:When was the declaration of independence signed?:1776:0
|
DECK_TEMPLATE="History:When was the declaration of independence signed?:1776:0
|
||||||
Math:What is the square root of 4?:2:4
|
Math:What is the square root of 4?:2:4
|
||||||
Science:What is the charge of a proton?:Positive:2
|
Science:What is the charge of a proton?:Positive:2
|
||||||
|
|
@ -86,7 +96,8 @@ 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
|
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"
|
Programming:Best operating system?:Arch, because BTW i run Arch:999"
|
||||||
|
|
||||||
if [ ! -d $DIR ];then # If Directory does NOT exist
|
# Test if .local/share exists and wether to offer setup process
|
||||||
|
if [ ! -d $DIR ];then
|
||||||
echo -e "No ${LRED}.local/share/flash${NC} directory, make it? ${LGREEN}y${NC}/${LRED}n${NC}"
|
echo -e "No ${LRED}.local/share/flash${NC} directory, make it? ${LGREEN}y${NC}/${LRED}n${NC}"
|
||||||
read RESPONSE
|
read RESPONSE
|
||||||
case "$RESPONSE" in
|
case "$RESPONSE" in
|
||||||
|
|
@ -96,20 +107,24 @@ if [ ! -d $DIR ];then # If Directory does NOT exist
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "$DIR"
|
# go to the flashcard decks
|
||||||
|
cd "$DIR"
|
||||||
|
|
||||||
if [ "$(find -maxdepth 999 -iname "*.csv" | wc -l)" = 0 ]; then # If there are no flashcard decks available
|
# If there are no flashcard decks available return user to starting location
|
||||||
|
if [ "$(find -maxdepth 999 -iname "*.csv" | wc -l)" = 0 ]; then
|
||||||
echo -e "$NO_DECKS" && cd "$PWD" && exit
|
echo -e "$NO_DECKS" && cd "$PWD" && exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show pretty FZF preview of decks using BAT
|
# 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')"
|
DECK="$(find -maxdepth $SEARCH_DEPTH -iname '*.csv' | fzf --preview='bat --theme="Solarized (dark)" --style=numbers --color=always {} | head -500')"
|
||||||
if [ -z $DECK ]; then # If Variable String Length is 0
|
|
||||||
exit
|
# If no deck is selected in fzf menu, return user to start location and exit
|
||||||
|
if [ -z $DECK ]; then
|
||||||
|
cd "$PWD" && exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
main(){
|
main(){
|
||||||
IFS=$':'; read -a q <<<$(sort "$DECK" -n --field-separator=: --key=4 | head | shuf -n 1)
|
IFS=$':'; read -a q <<<$(sort "$DECK" -n --field-separator=: --key=4 | head -n "$CARD_POOL_SIZE"| shuf -n 1)
|
||||||
clear
|
clear
|
||||||
echo -e "${WHITEBG} Flash.sh - Flash Cards In Your Terminal ${NC}"
|
echo -e "${WHITEBG} Flash.sh - Flash Cards In Your Terminal ${NC}"
|
||||||
echo -e "${ORANGE}${BOLD}Cards ${BOLD}Reviewed:${NC} $COUNTER"
|
echo -e "${ORANGE}${BOLD}Cards ${BOLD}Reviewed:${NC} $COUNTER"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue