Make script POSIX compliant

This commit is contained in:
BBaoVanC 2020-12-26 15:36:09 -06:00
parent 1bf621efc7
commit c6e1f07bbe
No known key found for this signature in database
GPG key ID: 18089E4E3CCF1D3A

View file

@ -1,32 +1,22 @@
#!/bin/sh #!/bin/sh
if [ ! command -v jp2a &> /dev/null ]; then required="neofetch jp2a jq"
echo "jp2a not found!"
exit 1
fi
if [ ! command -v neofetch &> /dev/null ]; then for req in $required; do
echo "neofetch not found!" ! command -v "$req" > /dev/null 2>&1 && echo "$req not found!" && exit 1
exit 1 done
fi
if [ ! command -v jq &> /dev/null ]; then
echo "jq not found!"
exit 1
fi
[[ ! -d "/tmp/nekofetch" ]] && mkdir /tmp/nekofetch tmpfile="$(mktemp -p /tmp nekofetchXXXXXXXX)"
if [[ "$1" = "--nsfw" ]]; then if [ "$1" = "--nsfw" ]; then
url=$(curl "https://nekos.life/api/v2/img/cum_jpg" | jq -r ".url") url=$(curl -fsSL "https://nekos.life/api/v2/img/cum_jpg" | jq -r ".url")
curl -fsSLo "/tmp/nekofetch/neko.jpg" "$url"
jp2a /tmp/nekofetch/neko.jpg > /tmp/nekofetch/neko
neofetch --source /tmp/nekofetch/neko
else else
url=$(curl "https://nekos.life/api/v2/img/neko" | jq -r ".url") url=$(curl -fsSL "https://nekos.life/api/v2/img/neko" | jq -r ".url")
curl -fsSLo "/tmp/nekofetch/neko.jpg" "$url"
jp2a /tmp/nekofetch/neko.jpg > /tmp/nekofetch/neko
neofetch --source /tmp/nekofetch/neko
fi fi
curl -fsSLo "$tmpfile.jpg" "$url"
jp2a "$tmpfile.jpg" > "$tmpfile"
neofetch --source "$tmpfile"
rm "$tmpfile" "$tmpfile.jpg"