better cats!
This commit is contained in:
parent
b09a2d5612
commit
132d5f58a4
1 changed files with 27 additions and 6 deletions
|
@ -1,6 +1,10 @@
|
|||
{
|
||||
writeShellScriptBin,
|
||||
imv,
|
||||
curl,
|
||||
imagemagick,
|
||||
}:
|
||||
|
||||
writeShellScriptBin "whst" ''
|
||||
print_help () {
|
||||
cat << EOF
|
||||
|
@ -53,15 +57,32 @@ writeShellScriptBin "whst" ''
|
|||
|
||||
url="https://http.cat/$status_code"
|
||||
|
||||
xdg-open "$url" >/dev/null 2>&1
|
||||
tmpfile="$(mktemp --suffix=.jpg)"
|
||||
|
||||
ret=$?
|
||||
|
||||
if (( ret != 0 )); then
|
||||
echo "Failed to open browser automatically. Here's the URL instead:"
|
||||
echo "$url"
|
||||
if ! ${curl}/bin/curl -fsSL "$url" -o "$tmpfile"; then
|
||||
echo "Error: Failed to fetch image for status code $status_code" >&2
|
||||
rm -f "$tmpfile"
|
||||
exit 1
|
||||
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
|
||||
''
|
||||
|
|
Loading…
Reference in a new issue