Merge pull request #28 from jsnal/master
Add the ability to change the FZF previewer.
This commit is contained in:
commit
9b8abbe476
19
flash
19
flash
|
|
@ -26,6 +26,7 @@
|
||||||
# USER CUSTOMIZABLE VARIABLES
|
# USER CUSTOMIZABLE VARIABLES
|
||||||
CARD_POOL_SIZE=10 # How large the pool size is for shuf to draw from
|
CARD_POOL_SIZE=10 # How large the pool size is for shuf to draw from
|
||||||
SEARCH_DEPTH=999 # How many levels to recursively search for .csv's in .local/share/flash
|
SEARCH_DEPTH=999 # How many levels to recursively search for .csv's in .local/share/flash
|
||||||
|
PREVIEWER='bat' # What fzf previewer to use when searching through decks
|
||||||
|
|
||||||
# ANSI FOREGROUND ESCAPE COLORS
|
# ANSI FOREGROUND ESCAPE COLORS
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
|
|
@ -150,7 +151,7 @@ if [ ! -e "$REVIEW_LOG" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
print_usage() {
|
print_usage() {
|
||||||
echo -e "\n${LCYAN}fla.sh --- Flash card system by Bryan Jenks${NC} ${LBLUE}<BryanJenks@protonmail.com>${NC}\n\n${YELLOW}${BOLD}Usage:${NC}\n\t${GREEN}flash -h:${NC} Print this help text\n\t${GREEN}flash -i:${NC} Print Information about the flashcard system\n\t${GREEN}flash -v:${NC} Print version Number\n\n"
|
echo -e "\n${LCYAN}fla.sh --- Flash card system by Bryan Jenks${NC} ${LBLUE}<BryanJenks@protonmail.com>${NC}\n\n${YELLOW}${BOLD}Usage:${NC}\n\t${GREEN}flash -h:${NC} Print this help text\n\t${GREEN}flash -i:${NC} Print Information about the flashcard system\n\t${GREEN}flash -v:${NC} Print version Number\n\t${GREEN}flash -p [BINARY]:${NC} Change the previewer when selecting decks. Default: bat\n\t\tSupported: bat, cat\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
print_info() {
|
print_info() {
|
||||||
|
|
@ -196,18 +197,28 @@ ${LCYAN}The Scoring System:${NC}\n
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts 'hiv' flag; do
|
while getopts 'hivp:' flag; do
|
||||||
case "${flag}" in
|
case "${flag}" in
|
||||||
h) print_usage && exit ;;
|
h) print_usage && exit ;;
|
||||||
i) print_info && exit ;;
|
i) print_info && exit ;;
|
||||||
v) echo -e "\n${YELLOW}fla.sh Current Version:${NC} ${RED}1.1${NC}\n" && exit ;;
|
v) echo -e "\n${YELLOW}fla.sh Current Version:${NC} ${RED}1.1${NC}\n" && exit ;;
|
||||||
|
p) if [[ $(command -v "$OPTARG" 2>&1) ]]; then PREVIEWER=$OPTARG; else echo "Unable to find previewer $OPTARG. Exiting..." && exit 1; fi ;;
|
||||||
*) print_usage && exit 1 ;;
|
*) print_usage && exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# Show pretty FZF preview of decks using BAT
|
# Set some parameters for preview command used by FZF
|
||||||
DECK="$(find . -maxdepth "$SEARCH_DEPTH" -iname "*.csv" | fzf --preview='bat --theme="Solarized (dark)" --style=numbers --color=always {} | head -500')"
|
while [ -z "$PREVIEWER_PARAMTERS" ]; do
|
||||||
|
case "$PREVIEWER" in
|
||||||
|
bat) PREVIEWER_PARAMTERS="--theme='Solarized (dark)' --style=numbers --color=always" ;;
|
||||||
|
cat) PREVIEWER_PARAMTERS="--number" ;;
|
||||||
|
*) echo -e "$PREVIEWER is not a valid previewer. Use 'bat' or 'cat'. Falling back on default...\n" && read -r -s -p 'Press [Enter] to continue...' && PREVIEWER='bat' ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Show pretty FZF preview of decks using $PREVIEWER. Default: BAT
|
||||||
|
DECK="$(find . -maxdepth "$SEARCH_DEPTH" -iname "*.csv" | fzf --preview="$PREVIEWER $PREVIEWER_PARAMTERS {} | head -500")"
|
||||||
|
|
||||||
# If no deck is selected in fzf menu
|
# If no deck is selected in fzf menu
|
||||||
# return user to start location
|
# return user to start location
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue