Version reusable Arceus preset and document pokefetch preset library
This commit is contained in:
1 parent
777d01926d
commit
10b22a6ffc
5 files changed
+220
No files matched your search
@@ -119,6 +119,8 @@ Apps that write their own settings (Claude Code, pi, Vesktop, Konsole profiles,
|
||||
|
||||
## Custom Pokémon rules
|
||||
|
||||
Reusable rules live in [`config/pokefetch`](config/pokefetch/README.md), including the Arceus holiday/weather preset and the Lugia day/night example. Add future presets there and enable one from your machine-local settings.
|
||||
|
||||
Simple settings still work in `~/.config/dotfiles/local.zsh`: `POKEMON`, `POKEMON_FORM` and `POKEMON_SHINY_PERCENT`.
|
||||
|
||||
For normal Lugia during the day and Shadow Lugia at night, add:
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Pokefetch presets
|
||||
|
||||
Store reusable Pokémon rules in this folder. Each `.zsh` preset defines `pokefetch_args()` and fills the `reply` array with the complete colorscripts arguments. Keep credentials, cached weather and machine-specific settings outside the repository.
|
||||
|
||||
Enable one preset in `~/.config/dotfiles/local.zsh`:
|
||||
|
||||
```zsh
|
||||
source "$DOTFILES_DIR/config/pokefetch/arceus.zsh"
|
||||
```
|
||||
|
||||
| Preset | Behavior |
|
||||
|---|---|
|
||||
| [arceus.zsh](arceus.zsh) | Arceus, 5% shiny; holidays override Las Cruces weather. [Rule guide](arceus.md). Requires curl, jq and flock for weather refreshes. |
|
||||
| [lugia-daynight.zsh](lugia-daynight.zsh) | Normal Lugia during the day, Shadow Lugia at night. |
|
||||
|
||||
Open a new terminal after changing presets. Source one preset at a time; if several define the hook, the last one wins. Remove the source line to restore the default `POKEMON*` settings on the next terminal start.
|
||||
|
||||
To add a preset, create a clearly named `.zsh` file here, define the hook, document its options and list it in this table. Return success after setting a nonempty `reply` array. Shared helpers should use a distinct prefix to avoid collisions with other shell functions. See the main README for a minimal custom hook example.
|
||||
@@ -0,0 +1,36 @@
|
||||
# Arceus preset
|
||||
|
||||
Enable from `~/.config/dotfiles/local.zsh` with:
|
||||
|
||||
```zsh
|
||||
source "$DOTFILES_DIR/config/pokefetch/arceus.zsh"
|
||||
```
|
||||
|
||||
The preset is versioned here; enabling it remains a machine-local choice. Run `arceus_status` for eligible forms plus weather cache metadata; `pokefetch` prints a new selection. Shiny chance is 5% per invocation, independently of form.
|
||||
|
||||
Holiday date uses America/Denver:
|
||||
|
||||
1. October: Ghost (including Friday the 13th).
|
||||
2. February 14: Fairy.
|
||||
3. March 17: Grass.
|
||||
4. Friday the 13th: `unknown` (renderer spelling).
|
||||
5. Otherwise use Las Cruces weather.
|
||||
|
||||
| Weather | Forms |
|
||||
|---|---|
|
||||
| Dust/sandstorm/haboob | Ground |
|
||||
| Snow/ice/freezing rain | Ice, Steel |
|
||||
| Fog/mist/haze | Dark, Ghost |
|
||||
| Any rain/drizzle/showers/thunderstorm | Water, Electric, Bug |
|
||||
| Windy/breezy or wind >=30 km/h | Flying, Dragon, Psychic |
|
||||
| Sunny/clear/mainly clear | Grass, Fire, Ground |
|
||||
| Partly cloudy/few clouds | Normal (`regular`), Rock |
|
||||
| Cloudy/overcast | Fairy, Fighting, Poison |
|
||||
|
||||
Dust, snow, fog, rain take precedence over wind; wind takes precedence over cloud coverage. Each eligible form has equal selection probability. Refreshing pokefetch can choose a different form.
|
||||
|
||||
NWS airport station KLRU is checked first, then Open-Meteo at 32.3199,-106.7637 when the NWS report lacks a usable description or is stale. Sources: https://www.weather.gov/documentation/services-web-api and https://open-meteo.com/en/docs . No keys required. Weather is cached for 30 minutes, network refresh is detached from terminal startup, retry attempts are throttled to 5 minutes and locked across shells. Last observation may be used up to 6 hours; after that, or before a successful fetch, Normal is the fallback. Holiday overrides need no weather request.
|
||||
|
||||
Manual refresh: `arceus_weather_refresh` (throttled). Cache: `~/.cache/pokefetch-arceus/weather.json`. Checks: `zsh tests/arceus.zsh` from the repo.
|
||||
|
||||
Disable: remove the Arceus source line from `local.zsh`, then open a new terminal. Existing `POKEMON=arceus` and `POKEMON_SHINY_PERCENT=5` remain as the simple fallback.
|
||||
@@ -0,0 +1,127 @@
|
||||
# Arceus preset: holidays + Las Cruces weather, 5% shiny. No credentials required.
|
||||
# Opt in from local.zsh: source "$DOTFILES_DIR/config/pokefetch/arceus.zsh"
|
||||
# Weather: Las Cruces airport observations (NWS), Open-Meteo fallback.
|
||||
# Cached 30 minutes; refreshes in the background. Cache older than 6h -> Normal.
|
||||
# Inspect current choices: arceus_status
|
||||
# Refresh now: arceus_weather_refresh
|
||||
|
||||
arceus_weather_refresh() (
|
||||
emulate -L zsh
|
||||
local dir="${XDG_CACHE_HOME:-$HOME/.cache}/pokefetch-arceus"
|
||||
mkdir -p -m 700 "$dir" || return 1
|
||||
flock -n 9 || return 0
|
||||
local now=$(date +%s) previous=0
|
||||
[[ -r "$dir/attempt" ]] && read -r previous < "$dir/attempt"
|
||||
[[ "$previous" == <-> ]] || previous=0
|
||||
(( now - previous >= 300 )) || return 0
|
||||
print -r -- "$now" > "$dir/attempt"
|
||||
local tmp=$(mktemp "$dir/.weather.XXXXXX")
|
||||
trap 'rm -f "$tmp" "$tmp.raw"' EXIT
|
||||
# NWS descriptions can identify dust/haboobs, which WMO forecast codes omit.
|
||||
if curl -fsS --connect-timeout 2 --max-time 6 \
|
||||
-H 'User-Agent: dotfiles-pokefetch (personal weather display)' \
|
||||
'https://api.weather.gov/stations/KLRU/observations/latest' > "$tmp.raw" &&
|
||||
jq -e --argjson now "$now" '
|
||||
.properties as $p |
|
||||
($p.timestamp | sub("\\+00:00$"; "Z") | fromdateiso8601) as $observed |
|
||||
select(($p.textDescription | type) == "string" and ($p.textDescription | length) > 0) |
|
||||
select($now - $observed >= 0 and $now - $observed < 10800) |
|
||||
{fetched: $now, observed: $observed, source: "NWS KLRU", description: $p.textDescription,
|
||||
wind: ($p.windSpeed.value // 0), code: null}' "$tmp.raw" > "$tmp"; then
|
||||
mv "$tmp" "$dir/weather.json"
|
||||
return 0
|
||||
fi
|
||||
if curl -fsS --connect-timeout 2 --max-time 6 \
|
||||
'https://api.open-meteo.com/v1/forecast?latitude=32.3199&longitude=-106.7637¤t=weather_code,wind_speed_10m&timeformat=unixtime&timezone=America%2FDenver' > "$tmp.raw" &&
|
||||
jq -e --argjson now "$now" '
|
||||
.current as $c | select(($c.weather_code | type) == "number" and ($c.wind_speed_10m | type) == "number") |
|
||||
select(($c.time | type) == "number" and $now - $c.time >= -900 and $now - $c.time < 10800) |
|
||||
{fetched: $now, observed: $c.time, source: "Open-Meteo Las Cruces", description: "",
|
||||
wind: $c.wind_speed_10m, code: $c.weather_code}' "$tmp.raw" > "$tmp"; then
|
||||
mv "$tmp" "$dir/weather.json"
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
) 9>"${XDG_CACHE_HOME:-$HOME/.cache}/pokefetch-arceus.lock"
|
||||
|
||||
# Pure classifier: description, wind speed in km/h, optional WMO code.
|
||||
# Precedence: dust, snow, fog, rain/thunderstorms, wind >=30 km/h, clouds/clear.
|
||||
arceus_weather_choices() {
|
||||
emulate -L zsh
|
||||
local description="${(L)1}" wind="${2:-0}" code="${3:--1}"
|
||||
reply=(regular)
|
||||
case "$description" in
|
||||
*dust*|*haboob*|*sandstorm*) reply=(ground); return ;;
|
||||
*snow*|*sleet*|*ice*|*freezing*) reply=(ice steel); return ;;
|
||||
*fog*|*mist*|*haze*) reply=(dark ghost); return ;;
|
||||
*rain*|*drizzle*|*shower*|*thunder*) reply=(water electric bug); return ;;
|
||||
esac
|
||||
case "$code" in
|
||||
56|57|66|67|71|73|75|77|85|86) reply=(ice steel); return ;;
|
||||
45|48) reply=(dark ghost); return ;;
|
||||
51|53|55|61|63|65|80|81|82|95|96|99) reply=(water electric bug); return ;;
|
||||
esac
|
||||
if [[ "$description" == *wind* || "$description" == *breezy* ]] || (( wind >= 30 )); then
|
||||
reply=(flying dragon psychic)
|
||||
return
|
||||
fi
|
||||
case "$description" in
|
||||
*partly*|*few\ clouds*) reply=(regular rock); return ;;
|
||||
*cloud*|*overcast*) reply=(fairy fighting poison); return ;;
|
||||
*clear*|*sunny*|fair) reply=(grass fire ground); return ;;
|
||||
esac
|
||||
case "$code" in
|
||||
0|1) reply=(grass fire ground) ;;
|
||||
2) reply=(regular rock) ;;
|
||||
3) reply=(fairy fighting poison) ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Optional MM-DD and ISO weekday arguments are for testing holiday rules.
|
||||
arceus_choices() {
|
||||
emulate -L zsh
|
||||
local month_day="${1:-$(TZ=America/Denver date +%m-%d)}"
|
||||
local weekday="${2:-$(TZ=America/Denver date +%u)}"
|
||||
reply=(regular)
|
||||
case "$month_day" in
|
||||
10-*) reply=(ghost); return ;;
|
||||
02-14) reply=(fairy); return ;;
|
||||
03-17) reply=(grass); return ;;
|
||||
*-13) if [[ "$weekday" == 5 ]]; then reply=(unknown); return; fi ;;
|
||||
esac
|
||||
local dir="${XDG_CACHE_HOME:-$HOME/.cache}/pokefetch-arceus" now=$(date +%s)
|
||||
local -a weather
|
||||
if [[ -r "$dir/weather.json" ]]; then
|
||||
weather=("${(@f)$(jq -er --argjson now "$now" '
|
||||
select(.observed > ($now - 21600)) |
|
||||
.description, (.wind | tostring), (.code // -1 | tostring), (.fetched | tostring)
|
||||
' "$dir/weather.json" 2>/dev/null)}")
|
||||
fi
|
||||
if (( ${#weather} == 4 )); then
|
||||
arceus_weather_choices "$weather[1]" "$weather[2]" "$weather[3]"
|
||||
(( now - weather[4] < 1800 )) && return 0
|
||||
fi
|
||||
# Detach refresh: terminal startup never waits on the weather service.
|
||||
( arceus_weather_refresh >/dev/null 2>&1 ) &!
|
||||
return 0
|
||||
}
|
||||
|
||||
pokefetch_args() {
|
||||
emulate -L zsh
|
||||
local -a choices
|
||||
arceus_choices
|
||||
choices=("${reply[@]}")
|
||||
local form="$choices[$(( RANDOM % ${#choices} + 1 ))]"
|
||||
reply=(--no-title --name arceus --form "$form")
|
||||
if (( RANDOM % 100 < 5 )); then reply+=(--shiny); fi
|
||||
return 0
|
||||
}
|
||||
|
||||
arceus_status() {
|
||||
emulate -L zsh
|
||||
local -a reply
|
||||
arceus_choices
|
||||
print -r -- "Arceus forms: ${(j:, :)reply}; shiny chance: 5%"
|
||||
local cache="${XDG_CACHE_HOME:-$HOME/.cache}/pokefetch-arceus/weather.json"
|
||||
[[ ! -r "$cache" ]] || jq '{source, description, code, wind_kmh: .wind, observed, fetched}' "$cache"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env zsh
|
||||
set -eu
|
||||
cd "${0:A:h}/.."
|
||||
source config/pokefetch/arceus.zsh
|
||||
local -a reply
|
||||
assert_choices() {
|
||||
local expected="$1"; shift
|
||||
arceus_choices "$@"
|
||||
[[ "${(j:,:)reply}" == "$expected" ]] || { print -u2 "Unexpected holiday: ${(j:,:)reply}"; exit 1; }
|
||||
}
|
||||
assert_weather() {
|
||||
local expected="$1"; shift
|
||||
arceus_weather_choices "$@"
|
||||
[[ "${(j:,:)reply}" == "$expected" ]] || { print -u2 "Unexpected weather: ${(j:,:)reply}"; exit 1; }
|
||||
}
|
||||
assert_choices ghost 10-13 5
|
||||
assert_choices fairy 02-14 7
|
||||
assert_choices grass 03-17 3
|
||||
assert_choices unknown 11-13 5
|
||||
assert_weather ground 'Dust Storm' 70 -1
|
||||
assert_weather ground 'Haboob' 70 -1
|
||||
assert_weather ice,steel 'Snow and Windy' 45 75
|
||||
assert_weather dark,ghost 'Fog' 4 45
|
||||
assert_weather water,electric,bug 'Rain' 42 63
|
||||
assert_weather flying,dragon,psychic 'Clear' 35 0
|
||||
assert_weather grass,fire,ground 'Clear' 10 0
|
||||
assert_weather regular,rock 'Partly Cloudy' 10 2
|
||||
assert_weather fairy,fighting,poison 'Mostly Cloudy' 10 3
|
||||
assert_weather water,electric,bug '' 11 63
|
||||
assert_weather grass,fire,ground '' 5 1
|
||||
arceus_choices() { reply=(unknown); }
|
||||
for i in {1..200}; do
|
||||
pokefetch_args
|
||||
[[ "${reply[1,5]}" == '--no-title --name arceus --form unknown' ]]
|
||||
[[ ${#reply} == 5 || ( ${#reply} == 6 && "$reply[6]" == --shiny ) ]]
|
||||
done
|
||||
print 'Arceus holiday, weather, and args checks passed'
|
||||
Reference in new issue
Block a user