fuzzy-pokedex/pokedex

78 lines
2.8 KiB
Plaintext
Raw Normal View History

2023-04-16 11:14:38 -05:00
#!/bin/bash
2023-04-17 00:42:39 -05:00
### Help
2023-04-17 00:50:45 -05:00
help() {
echo -e "\nUse fzf to search Pokemon stats\n"
2023-04-17 00:42:39 -05:00
echo -e "Can optionally search by name"
2023-04-18 00:56:18 -05:00
echo -e "EXAMPLE\n\tpokedex [pokemon name]\n"
2023-04-17 00:42:39 -05:00
echo -e "OPTIONS"
2023-04-18 09:25:16 -05:00
echo -e "\t-q, --quick [pokemon]\n\t\tPrints single pokedex entry to terminal\n\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"
2023-04-17 00:42:39 -05:00
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"
}
2023-04-18 00:15:37 -05:00
### Set pokeData location
2023-04-18 19:30:32 -05:00
POKEDATA="/usr/share/fuzzy-pokedex/pokeData"
2023-04-18 00:15:37 -05:00
2023-04-17 00:42:39 -05:00
### Pokedex viewer using pokemon-colorscripts and fzf
2023-04-18 00:41:04 -05:00
pokedex() {
2023-04-18 00:15:37 -05:00
pokemon-colorscripts -l |
2023-04-17 03:28:49 -05:00
fzf -q "$1" +m -s -i \
2023-04-16 11:14:38 -05:00
--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 \
2023-04-20 11:18:01 -05:00
--preview="echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA/{1}" \
2023-04-17 00:03:49 -05:00
--preview-window=68%:wrap:border-rounded \
2023-04-16 11:14:38 -05:00
--bind=focus:transform-preview-label:'echo [ {1} ] ' \
2023-04-18 00:47:34 -05:00
--bind=ctrl-h:preview:"echo; pokedex -h;" \
2023-04-20 11:29:05 -05:00
--bind=space:preview:"echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA/{1}; espeak-ng -f ./pokeData/{1} -g 2 -p 45 -s 160 -l 150 -ven+m3" \
--bind=ctrl-space:preview:"echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA/{1};" \
2023-04-18 19:30:32 -05:00
--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};" \
2023-04-19 16:16:20 -05:00
--bind=ctrl-n:preview:"echo; pokemon-colorscripts -n {1} --no-title; cat $POKEDATA/{1};" |
2023-04-18 19:30:32 -05:00
parallel pokemon-colorscripts --no-title -n {} "&&" cat "$POKEDATA/{}"
2023-04-17 00:03:49 -05:00
}
2023-04-18 09:25:16 -05:00
### Quick view returns single Pokemon stat instead of opening pokedex
quick_view() {
2023-04-18 19:30:32 -05:00
parallel pokemon-colorscripts --no-title -n {} "&&" cat "$POKEDATA/{}" <<<"$1"
2023-04-18 09:25:16 -05:00
}
2023-04-17 00:42:39 -05:00
### Update Pokemon stats file set
2023-04-17 00:03:49 -05:00
update_pokeData() {
echo -e "\n\t\tWARNING!!!\n\tThis WILL take a long time\n"
2023-04-18 19:30:32 -05:00
pokemon-colorscripts -l | sort | parallel --bar --color --retry-failed -j "${1:-200%}" pokeInfo {} ">" "$POKEDATA/{}" 2>&1
2023-04-17 00:03:49 -05:00
}
if [[ ! "$1" =~ ^- ]]; then
2023-04-18 00:41:04 -05:00
pokedex "$1"
2023-04-17 00:03:49 -05:00
else
for opt in "$@"; do
case $opt in
2023-04-18 09:25:16 -05:00
-q|--quick)
quick_view "$2"
;;
2023-04-17 00:42:39 -05:00
-u|--update)
2023-04-17 11:44:24 -05:00
update_pokeData "$2"
2023-04-17 00:03:49 -05:00
;;
-h|--help)
2023-04-17 00:50:45 -05:00
help
2023-04-17 00:03:49 -05:00
;;
-*)
echo "Invalid Usage"
2023-04-17 00:52:38 -05:00
help
2023-04-17 00:03:49 -05:00
;;
esac
done
fi