Proper arguments support and support w3m backend

This commit is contained in:
Naomi Calabretta 2021-03-29 00:48:25 +02:00
parent 9382314f82
commit 57a29f12b4

View file

@ -1,24 +1,37 @@
#!/bin/sh #!/bin/sh
tmpfile="$(mktemp)" tmpfile="$(mktemp)"
imgurl="https://nekos.life/api/v2/img/neko"
height="$(($(stty size | awk '{print $1}') - 5))"
case "$1" in while :; do
"--nsfw"|"nsfw"|"-n"|"n") case "$1" in
[ "$DEBUG" = "true" ] && echo "Getting a nsfw image" "--nsfw"|"nsfw"|"-n"|"n")
imgurl="https://nekos.life/api/v2/img/cum_jpg" [ "$DEBUG" = "true" ] && echo "Getting a nsfw image"
;; imgurl="https://nekos.life/api/v2/img/cum_jpg"
"--sfw"|"sfw"|"-s"|"s") ;;
[ "$DEBUG" = "true" ] && echo "Getting a sfw image" "--sfw"|"sfw"|"-s"|"s")
imgurl="https://nekos.life/api/v2/img/neko" [ "$DEBUG" = "true" ] && echo "Getting a sfw image"
;; imgurl="https://nekos.life/api/v2/img/neko"
*) ;;
[ "$DEBUG" = "true" ] && echo "Could not interpret as either sfw or nsfw. Defaulting to sfw." "--w3m"|"w3m"|"--img"|"img"|"-i"|"i")
imgurl="https://nekos.life/api/v2/img/neko" [ "$DEBUG" = "true" ] && echo "Using w3m image backend for neofetch"
;; use_w3m="true"
esac ;;
"--height"|"-h")
echo "$2" | grep -qE '^[0-9]+$' && height="$2" || height="$(($(stty size | awk '{print $1}') - 5))" height="$2"
[ "$DEBUG" = "true" ] && echo "Using height $height" [ "$DEBUG" = "true" ] && echo "Using height $height"
shift
;;
*)
if [ -z "$1" ]; then
break
fi
[ "$DEBUG" = "true" ] && echo "Could not interpret parameter '$1'."
;;
esac
shift
done
url=$(curl -fsSL "$imgurl" | jq -r ".url") url=$(curl -fsSL "$imgurl" | jq -r ".url")
@ -31,6 +44,8 @@ if [ "$TERM" = "xterm-kitty" ]; then
fi fi
elif [ "$LC_TERMINAL" = "iTerm2" ]; then elif [ "$LC_TERMINAL" = "iTerm2" ]; then
neofetch --iterm2 "$tmpfile.jpg" neofetch --iterm2 "$tmpfile.jpg"
elif [ "$use_w3m" = "true" ]; then
neofetch --w3m "$tmpfile.jpg"
else else
jp2a --height="$height" "$tmpfile.jpg" > "$tmpfile" jp2a --height="$height" "$tmpfile.jpg" > "$tmpfile"
neofetch --source "$tmpfile" neofetch --source "$tmpfile"