From 777d01926d1d27dcc31a358e285aa00eed401d38 Mon Sep 17 00:00:00 2001 From: Ziad Arafat Date: Fri, 13 Nov 2026 13:47:05 -0700 Subject: [PATCH] Add custom pokefetch argument hook and day-night Lugia example --- README.md | 39 +++++++++++++++++ config/pokefetch/lugia-daynight.zsh | 12 ++++++ home/files/pokefetch.zsh | 67 +++++++++++++++++++++-------- tests/pokefetch.zsh | 51 ++++++++++++++++++++++ 4 files changed, 151 insertions(+), 18 deletions(-) create mode 100644 config/pokefetch/lugia-daynight.zsh create mode 100644 tests/pokefetch.zsh diff --git a/README.md b/README.md index b634e2f..68e9251 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,45 @@ Apps that write their own settings (Claude Code, pi, Vesktop, Konsole profiles, - **Defguard VPN** (home lab, `vpn.godemperordoge.org`): the desktop client is repackaged from the official `.deb` in `pkgs/defguard-client.nix`, so it runs natively on SteamOS (no WebKitGTK 4.1 there). `dot system` installs its root service (`config/defguard/defguard-service.service`, group `defguard`, a `resolvconf` → `resolvectl` shim where needed). Setup tokens are single-use and expire in 24 h, so Bitwarden holds a Defguard **API token** instead: create one in Defguard (your profile → *API tokens*) once, `dot secrets set DEFGUARD_API_TOKEN`, then on each new machine run `dot defguard` from home or over the VPN. It mints a fresh token and writes `~/.local/share/net.defguard/provisioning.json`, and the app sets itself up on its next start; you only sign in with Doge Home Lab. - **Sounds:** `dot sounds` extracts Portal 2 sounds from your local Steam install (game assets stay out of git) into `~/.local/share/sounds/portal2`. Mapping: `config/sounds/portal2.json`. +## Custom Pokémon rules + +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: + +```zsh +source "$DOTFILES_DIR/config/pokefetch/lugia-daynight.zsh" +``` + +The example uses local time: day starts at 07:00 and night at 19:00. Optionally set `POKEFETCH_DAY_START=8` and `POKEFETCH_NIGHT_START=20` in `local.zsh`. It checks the time each time `pokefetch` runs; an already printed sprite stays as it is. + +For full control, define your own function in `local.zsh` instead: + +```zsh +pokefetch_args() { + reply=(--no-title --name lugia) + if pokefetch_is_night; then + reply+=(--form shadow) + fi + # Optional: choose shininess, size, another Pokémon, or --random here. + # (( RANDOM % 100 < 10 )) && reply+=(--shiny) + # reply+=(--big) + return 0 +} +``` + +Set `reply` to a Zsh array with one element per argument. The hook replaces **all** generated arguments, including Pokémon, form, title and shiny settings; `POKEMON*` defaults are ignored while it is defined. It runs directly as a function, so ordinary shell logic works without `eval` or parsing printed text. Return success with a nonempty array. Hook errors or colorscript errors fall back to plain fastfetch with a diagnostic. + +Open a new terminal after `dot switch`, or reload and preview: + +```zsh +source "$DOTFILES_DIR/home/files/pokefetch.zsh" +source ~/.config/dotfiles/local.zsh +pokefetch +``` + +Use `pokemon-go-colorscripts --help` for options and `--list` for Pokémon names. To restore the default behavior in the current shell, run `unfunction pokefetch_args` and remove the hook/source line from `local.zsh`. `POKEFETCH=0` still disables pokefetch altogether. + ## Selkies / Fedora containers Bootstrap exports a missing `USER` from `id -un` and enables Nix flakes even when Nix is already installed. Container detection supports Podman, Docker and the `container` environment variable. Containers skip Flatpaks, distrobox setup, and host VPN daemon setup. diff --git a/config/pokefetch/lugia-daynight.zsh b/config/pokefetch/lugia-daynight.zsh new file mode 100644 index 0000000..7fb5bd6 --- /dev/null +++ b/config/pokefetch/lugia-daynight.zsh @@ -0,0 +1,12 @@ +# Source this from ~/.config/dotfiles/local.zsh: +# source "$DOTFILES_DIR/config/pokefetch/lugia-daynight.zsh" +# Local time: normal Lugia 07:00–18:59, Shadow Lugia 19:00–06:59. +# Optional overrides: POKEFETCH_DAY_START=7 POKEFETCH_NIGHT_START=19 +pokefetch_args() { + reply=(--no-title --name lugia) + if pokefetch_is_night; then + reply+=(--form shadow) + fi + # Add any colorscripts options here, e.g. reply+=(--big). + return 0 +} diff --git a/home/files/pokefetch.zsh b/home/files/pokefetch.zsh index 1d964e9..6c153a4 100644 --- a/home/files/pokefetch.zsh +++ b/home/files/pokefetch.zsh @@ -4,30 +4,61 @@ # POKEMON_FORM=fan # explicit form; Rotom otherwise picks one per distro # POKEMON_SHINY_PERCENT=10 # 0-100 # POKEFETCH=0 # disable +# Or define pokefetch_args() { reply=(--no-title -n lugia); } +# The hook owns every argument and overrides the POKEMON* variables. +# Local-clock day/night helper, also usable by custom argument hooks. +# Optional hour argument makes rules easy to preview: pokefetch_is_night 23. +pokefetch_is_night() { + emulate -L zsh + local hour="${1:-$(date +%H)}" + [[ "$hour" == <0-23> ]] || return 2 + (( 10#$hour < ${POKEFETCH_DAY_START:-7} || 10#$hour >= ${POKEFETCH_NIGHT_START:-19} )) +} + pokefetch() { + emulate -L zsh [[ "${POKEFETCH:-1}" == 0 ]] && return command -v fastfetch >/dev/null || return - local mon="${POKEMON:-rotom}" form="${POKEMON_FORM:-}" os_id=unknown - [[ -r /etc/os-release ]] && os_id=$(. /etc/os-release && echo "$ID") - - if [[ -z "$form" && "$mon" == rotom ]]; then - case "$os_id" in - steamos) form="" ;; # regular Rotom on the Deck - fedora) form=fan ;; - debian|ubuntu) form=wash ;; - almalinux|rhel|rocky) form=frost ;; - arch|cachyos) form=heat ;; - *) form=mow ;; - esac + if ! command -v pokemon-go-colorscripts >/dev/null; then + fastfetch + return fi - local -a args=(--no-title -n "$mon") - [[ -n "$form" ]] && args+=(-f "$form") - (( RANDOM % 100 < ${POKEMON_SHINY_PERCENT:-10} )) && args+=(-s) - - if command -v pokemon-go-colorscripts >/dev/null; then - fastfetch --data "$(pokemon-go-colorscripts "${args[@]}" 2>/dev/null)" + local -a args reply + if (( $+functions[pokefetch_args] )); then + # Zsh dynamic scoping lets the user's hook fill this local array directly. + if ! pokefetch_args || (( ${#reply} == 0 )); then + print -u2 -- 'pokefetch: pokefetch_args must set reply=(...) and return success' + fastfetch + return + fi + args=("${reply[@]}") else + local mon="${POKEMON:-rotom}" form="${POKEMON_FORM:-}" os_id=unknown + [[ -r /etc/os-release ]] && os_id=$(. /etc/os-release && echo "$ID") + + if [[ -z "$form" && "$mon" == rotom ]]; then + case "$os_id" in + steamos) form="" ;; # regular Rotom on the Deck + fedora) form=fan ;; + debian|ubuntu) form=wash ;; + almalinux|rhel|rocky) form=frost ;; + arch|cachyos) form=heat ;; + *) form=mow ;; + esac + fi + + args=(--no-title -n "$mon") + [[ -n "$form" ]] && args+=(-f "$form") + (( RANDOM % 100 < ${POKEMON_SHINY_PERCENT:-10} )) && args+=(-s) + + fi + + local sprite + if sprite=$(pokemon-go-colorscripts "${args[@]}") && [[ -n "$sprite" ]]; then + fastfetch --data "$sprite" + else + print -u2 -- 'pokefetch: colorscripts failed; check your Pokémon name and form' fastfetch fi } diff --git a/tests/pokefetch.zsh b/tests/pokefetch.zsh new file mode 100644 index 0000000..e1af2b3 --- /dev/null +++ b/tests/pokefetch.zsh @@ -0,0 +1,51 @@ +#!/usr/bin/env zsh +set -eu +cd "${0:A:h}/.." +source home/files/pokefetch.zsh || true +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT +fastfetch() { printf '%s' "$*" > "$scratch/fastfetch"; } +pokemon-go-colorscripts() { printf '%s\n' "$@" > "$scratch/args"; print sprite; } +assert_args() { + local expected="$(printf '%s\n' "$@")" + [[ "$(<"$scratch/args")" == "$expected" ]] || { print -u2 'Unexpected colorscript args'; exit 1; } +} +POKEMON=pikachu POKEMON_FORM= POKEMON_SHINY_PERCENT=0 +pokefetch +assert_args --no-title -n pikachu +POKEMON=rotom POKEMON_FORM=fan POKEMON_SHINY_PERCENT=100 +pokefetch +assert_args --no-title -n rotom -f fan -s +# Arbitrary options and argument boundaries survive without shell evaluation. +pokefetch_args() { reply=(--name 'a value with spaces' --big --shiny); } +pokefetch +assert_args --name 'a value with spaces' --big --shiny +for hour in 00 06 19 23; do pokefetch_is_night "$hour"; done +for hour in 07 12 18; do ! pokefetch_is_night "$hour"; done +POKEFETCH_DAY_START=8 POKEFETCH_NIGHT_START=20 +pokefetch_is_night 07 +! pokefetch_is_night 19 +unset POKEFETCH_DAY_START POKEFETCH_NIGHT_START +source config/pokefetch/lugia-daynight.zsh +date() { print 12; } +pokefetch +assert_args --no-title --name lugia +date() { print 23; } +pokefetch +assert_args --no-title --name lugia --form shadow +pokefetch_args() { reply=(); } +pokefetch 2> "$scratch/error" +[[ ! -s "$scratch/fastfetch" ]] +rg -q 'must set reply' "$scratch/error" +pokefetch_args() { reply=(--random); return 1; } +pokefetch 2> "$scratch/error" +[[ ! -s "$scratch/fastfetch" ]] +pokefetch_args() { reply=(--random); } +pokemon-go-colorscripts() { return 1; } +pokefetch 2> "$scratch/error" +rg -q 'colorscripts failed' "$scratch/error" +rm "$scratch/fastfetch" +POKEFETCH=0 +pokefetch || true +[[ ! -e "$scratch/fastfetch" ]] +print 'Pokefetch checks passed'