better cats!

This commit is contained in:
Jakub Kropáček 2025-07-09 08:49:49 +02:00
parent b09a2d5612
commit 132d5f58a4
Signed by: JustScreaMy
GPG key ID: 4EC6A2C45D75FC86

View file

@ -1,6 +1,10 @@
{ {
writeShellScriptBin, writeShellScriptBin,
imv,
curl,
imagemagick,
}: }:
writeShellScriptBin "whst" '' writeShellScriptBin "whst" ''
print_help () { print_help () {
cat << EOF cat << EOF
@ -53,15 +57,32 @@ writeShellScriptBin "whst" ''
url="https://http.cat/$status_code" url="https://http.cat/$status_code"
xdg-open "$url" >/dev/null 2>&1 tmpfile="$(mktemp --suffix=.jpg)"
ret=$? if ! ${curl}/bin/curl -fsSL "$url" -o "$tmpfile"; then
echo "Error: Failed to fetch image for status code $status_code" >&2
if (( ret != 0 )); then rm -f "$tmpfile"
echo "Failed to open browser automatically. Here's the URL instead:"
echo "$url"
exit 1 exit 1
fi fi
dims="$(${imagemagick}/bin/identify -format '%w %h' "$tmpfile" 2>/dev/null)"
if [ -z "$dims" ]; then
echo "Error: Failed to determine image size." >&2
rm -f "$tmpfile"
exit 1
fi
# Split into width and height using shell
set -- $dims
width="$1"
height="$2"
if ! ${imv}/bin/imv -W "$width" -H "$height" "$tmpfile"; then
echo "Error: Failed to display image with imv." >&2
rm -f "$tmpfile"
exit 1
fi
rm -f "$tmpfile"
exit 0 exit 0
'' ''