Files
J621/extras/fish_greeting/install.fish
T
JakeBreath aee29de34a Port the fish_greeting shell greeting to the new API
The original script (J621-Django/extras/fish_greeting system) downloaded
image bytes from /random/?rating=X and read the X-File-* headers. The new
API answers with JSON and a signed link, so the greeting now:

- asks /api/random/?fastfetch=1&rating=<mode> for JSON;
- parses url/j_id/filename/md5 with jq, python3, or a grep/sed fallback;
- downloads the signed link and keeps the original display path (fastfetch
  kitty/kitty-icat logos, gifsicle preprocessing for GIFs, recursion guard,
  logging with rotation, greeting_mode 0/1/2 = NSFW/SFW/Questionable);
- is configured through ~/.config/j621Greeting/config.fish or universal
  variables (J621_BASE, J621_WEB, J621_TOKEN, J621_FASTFETCH_CONFIG) instead
  of a hardcoded host, and prints the /detail/<J-ID> link on J621_WEB;
- reports the API's own 404 message when a rating has no images, and keeps
  curl quiet so failures do not spill into the greeting.

extras/fish_greeting/ contains the function, an install.fish (copies it into
the fish functions dir, creates the config once, checks dependencies) and a
README with the old-vs-new table and troubleshooting. The existing
gm-switch helper and .desktop launchers keep working (same mode file).

Tested with fish 4.9.3: syntax check on every file, guest and token runs
against the dev API (unsigned vs signed URLs), the empty-rating and
unreachable-API paths, and the grep/sed fallback with jq and python3
unavailable.
2026-09-18 13:14:41 -05:00

53 lines
1.6 KiB
Fish

#!/usr/bin/env fish
# Install the J621 fish greeting:
# * copies fish_greeting.fish into ~/.config/fish/functions/
# * creates ~/.config/j621Greeting/config.fish from the example (once)
# * checks the tools it needs
#
# Usage: fish install.fish
set -l here (path resolve (dirname (status --current-filename)))
set -l functions_dir ~/.config/fish/functions
set -l config_dir ~/.config/j621Greeting
set -l problems 0
mkdir -p $functions_dir
cp "$here/fish_greeting.fish" "$functions_dir/fish_greeting.fish"
echo "Installed $functions_dir/fish_greeting.fish"
mkdir -p $config_dir
if test -f "$config_dir/config.fish"
echo "Keeping existing $config_dir/config.fish"
else
cp "$here/config.example.fish" "$config_dir/config.fish"
echo "Created $config_dir/config.fish — edit J621_BASE (and J621_TOKEN) there"
end
for tool in curl fastfetch file
if not command -v $tool >/dev/null 2>&1
set problems 1
echo "Missing required tool: $tool"
end
end
if not command -v curl >/dev/null 2>&1; and not command -v wget >/dev/null 2>&1
set problems 1
echo "Missing required tool: curl (or wget)"
end
for tool in gifsicle jq python3
if not command -v $tool >/dev/null 2>&1
echo "Optional tool not found: $tool (the greeting still works)"
end
end
if test $problems -eq 0
echo
echo "Done. Test it now with: fish_greeting"
echo "Rating mode lives in ~/.config/fish/greeting_mode (0=NSFW, 1=SFW, 2=Questionable)."
echo "The old gm-switch tool / .desktop launchers keep working — same file."
else
echo
echo "Install the missing tools, then run: fish_greeting"
end