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,7 +1,10 @@
#!/bin/sh #!/bin/sh
tmpfile="$(mktemp)" tmpfile="$(mktemp)"
imgurl="https://nekos.life/api/v2/img/neko"
height="$(($(stty size | awk '{print $1}') - 5))"
while :; do
case "$1" in case "$1" in
"--nsfw"|"nsfw"|"-n"|"n") "--nsfw"|"nsfw"|"-n"|"n")
[ "$DEBUG" = "true" ] && echo "Getting a nsfw image" [ "$DEBUG" = "true" ] && echo "Getting a nsfw image"
@ -11,14 +14,24 @@ case "$1" in
[ "$DEBUG" = "true" ] && echo "Getting a sfw image" [ "$DEBUG" = "true" ] && echo "Getting a sfw image"
imgurl="https://nekos.life/api/v2/img/neko" imgurl="https://nekos.life/api/v2/img/neko"
;; ;;
"--w3m"|"w3m"|"--img"|"img"|"-i"|"i")
[ "$DEBUG" = "true" ] && echo "Using w3m image backend for neofetch"
use_w3m="true"
;;
"--height"|"-h")
height="$2"
[ "$DEBUG" = "true" ] && echo "Using height $height"
shift
;;
*) *)
[ "$DEBUG" = "true" ] && echo "Could not interpret as either sfw or nsfw. Defaulting to sfw." if [ -z "$1" ]; then
imgurl="https://nekos.life/api/v2/img/neko" break
fi
[ "$DEBUG" = "true" ] && echo "Could not interpret parameter '$1'."
;; ;;
esac esac
shift
echo "$2" | grep -qE '^[0-9]+$' && height="$2" || height="$(($(stty size | awk '{print $1}') - 5))" done
[ "$DEBUG" = "true" ] && echo "Using height $height"
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"