-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpokefetch
More file actions
executable file
·86 lines (63 loc) · 2.97 KB
/
pokefetch
File metadata and controls
executable file
·86 lines (63 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# Prepare ------------------------------------------------------------------------------------------
pokemon=${1:-$(shuf -i 1-905 -n 1)}
data_pokemon=$(curl -fsLS "https://pokeapi.co/api/v2/pokemon/${pokemon}")
data_species=$(curl -fsLS "$(echo "${data_pokemon}" | jq --raw-output .species.url)")
id=$(echo "${data_species}" | jq --raw-output .id)
name=$(echo "${data_species}" | jq --raw-output '.names | .[] | select(.language.name == "en").name')
category=$(echo "${data_species}" | jq --raw-output '.genera | .[] | select(.language.name == "en").genus')
title="▐[1;7m No.$(printf '%03d' "${id}") [0m▌ [1m${name} - ${category}[0m"
for type in $(echo "${data_pokemon}" | jq --raw-output '.types | .[].type.name' | tr '[:lower:]' '[:upper:]'); do
case "${type}" in
NORMAL) color=7 ;;
FIRE) color=9 ;;
WATER) color=12 ;;
ELECTRIC) color=11 ;;
GRASS) color=10 ;;
ICE) color=14 ;;
FIGHTING) color=1 ;;
POISON) color=5 ;;
GROUND) color=11 ;;
FLYING) color=6 ;;
PSYCHIC) color=13 ;;
BUG) color=2 ;;
ROCK) color=3 ;;
GHOST) color=4 ;;
DRAGON) color=4 ;;
DARK) color=3 ;;
STEEL) color=8 ;;
FAIRY) color=13 ;;
esac
types="${types} [7;38;5;${color}m ${type} [0m "
done
height=$(awk "BEGIN{ print $(echo "${data_pokemon}" | jq --raw-output .height) / 10 }")
weight=$(awk "BEGIN{ print $(echo "${data_pokemon}" | jq --raw-output .weight) / 10 }")
status=$(gum style --align center --width 44 "${types}" "Height: [1m${height}m[0m Weight: [1m${weight}kg[0m")
info=$(gum join --vertical "${title}" '' "${status}")
entries=$(gum style --border normal --padding '0 1' --width 42 "$(echo "${data_species}" | \
jq --raw-output 'last(.flavor_text_entries | .[] | select(.language.name == "en")).flavor_text' | tr -d "\n")")
pokemon_path=$(echo "${data_pokemon}" | jq --raw-output .name)
art=$(gum style "$(curl -fsLS \
"https://gitlab.com/phoneybadger/pokemon-colorscripts/-/raw/main/colorscripts/small/regular/${pokemon_path}" \
| sed -e 's/$/[0m/g')")
# Display ------------------------------------------------------------------------------------------
terminal_size=$(stty size)
terminal_height=${terminal_size% *}
terminal_width=${terminal_size#* }
prompt_height=${PROMPT_HEIGHT:-1}
print_test() {
no_color=$(printf '%b' "${1}" | sed -e 's/\x1B\[[0-9;]*[JKmsu]//g')
[ "$(printf '%s' "${no_color}" | wc --lines)" -gt $(( terminal_height - prompt_height )) ] && return 1
[ "$(printf '%s' "${no_color}" | wc --max-line-length)" -gt "${terminal_width}" ] && return 1
gum style --align center --width="${terminal_width}" "${1}" ''
printf '%b' "\033[A"
exit 0
}
# Landscape layout
group_info_entries=$(gum join --vertical "${info}" '' "${entries}")
print_test "$(gum join --horizontal --align center "${art}" ' ' "${group_info_entries}")"
# Portrait layout
print_test "$(gum join --vertical --align center "${info}" '' "${art}" "${entries}")"
# Other layout
print_test "${group_info_entries}"
exit 1