fuzzy-pokedex/pokedex

71 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
### Help
help() {
echo -e "\nUse fzf to search Pokemon stats\n"
echo -e "Can optionally search by name"
echo -e "EXAMPLE\n\tpokedex [pokemon name]\n"
echo -e "OPTIONS"
echo -e "\t-u, --update [N/+N/-N/N%]\n\t\tScrape web for updated Pokemon stats\n\t\tWARNING: update function is resource heavy\n\t\tSee Parallel job control (-j) for options\n\t\tDefault is 200%\n\t-h, --help\n\t\tPrint this help screen"
echo -e "KEYBINDS"
echo -e "\tctrl-n\tShows small sprite version\n\tctrl-b\tShows large sprite version\n\tctrl-s\tShows shiny sprite version\n\tctrl-h\tShows this help screen in preview window\n"
}
### Set pokeData location
POKEDATA="/usr/share/fuzzy-pokedex/pokeData/"
### Pokedex viewer using pokemon-colorscripts and fzf
pokedex() {
pokemon-colorscripts -l |
fzf -q "$1" +m -s -i \
--cycle \
--reverse \
--prompt=' ' \
--pointer='󰐝 ' \
--border=rounded \
--border-label="╢ Fuzzy-Pokedex ╟" \
--margin=4% \
--padding=4% \
--header="Choose Pokemon to view info" \
--info=inline:' 󰨉 ' \
--color='fg+:15,fg:42,preview-fg:15,label:9,preview-label:15,hl+:134,hl:123,query:134,gutter:0,border:9,prompt:15,pointer:15,marker:15' \
--tiebreak=begin,chunk,length \
--preview="echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA{1}" \
--preview-window=68%:wrap:border-rounded \
--bind=focus:transform-preview-label:'echo [ {1} ] ' \
--bind=ctrl-h:preview:"echo; pokedex -h;" \
--bind=ctrl-b:preview:"echo; pokemon-colorscripts -b -n {1} --no-title; cat $POKEDATA{1};" \
--bind=ctrl-s:preview:"echo; pokemon-colorscripts -s -n {1} --no-title; cat $POKEDATA{1};" \
--bind=ctrl-n:preview:"echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA{1};" |
parallel pokemon-colorscripts --no-title -n {} "&&" cat "$POKEDATA"{}
}
### Update Pokemon stats file set
update_pokeData() {
echo -e "\n\t\tWARNING!!!\n\tThis WILL take a long time\n"
if [[ -n "$1" ]]; then
pokemon-colorscripts -l | sort | parallel --bar --color --retry-failed -j "$1" pokeInfo {} ">" "$POKEDATA"{}
else
pokemon-colorscripts -l | sort | parallel --bar --color --retry-failed -j 200% pokeInfo {} ">" "$POKEDATA"{}
fi
}
if [[ ! "$1" =~ ^- ]]; then
pokedex "$1"
else
for opt in "$@"; do
case $opt in
-u|--update)
update_pokeData "$2"
;;
-h|--help)
help
;;
-*)
echo "Invalid Usage"
help
;;
esac
done
fi