From 57a29f12b48182254d8931c90a1058112fcd9383 Mon Sep 17 00:00:00 2001 From: Naomi Calabretta Date: Mon, 29 Mar 2021 00:48:25 +0200 Subject: [PATCH 1/2] Proper arguments support and support w3m backend --- nekofetch | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/nekofetch b/nekofetch index 72e875d..df502d1 100755 --- a/nekofetch +++ b/nekofetch @@ -1,24 +1,37 @@ #!/bin/sh tmpfile="$(mktemp)" +imgurl="https://nekos.life/api/v2/img/neko" +height="$(($(stty size | awk '{print $1}') - 5))" -case "$1" in - "--nsfw"|"nsfw"|"-n"|"n") - [ "$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" - imgurl="https://nekos.life/api/v2/img/neko" - ;; - *) - [ "$DEBUG" = "true" ] && echo "Could not interpret as either sfw or nsfw. Defaulting to sfw." - imgurl="https://nekos.life/api/v2/img/neko" - ;; -esac - -echo "$2" | grep -qE '^[0-9]+$' && height="$2" || height="$(($(stty size | awk '{print $1}') - 5))" -[ "$DEBUG" = "true" ] && echo "Using height $height" +while :; do + case "$1" in + "--nsfw"|"nsfw"|"-n"|"n") + [ "$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" + 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 + ;; + *) + if [ -z "$1" ]; then + break + fi + [ "$DEBUG" = "true" ] && echo "Could not interpret parameter '$1'." + ;; + esac + shift +done url=$(curl -fsSL "$imgurl" | jq -r ".url") @@ -31,6 +44,8 @@ if [ "$TERM" = "xterm-kitty" ]; then fi elif [ "$LC_TERMINAL" = "iTerm2" ]; then neofetch --iterm2 "$tmpfile.jpg" +elif [ "$use_w3m" = "true" ]; then + neofetch --w3m "$tmpfile.jpg" else jp2a --height="$height" "$tmpfile.jpg" > "$tmpfile" neofetch --source "$tmpfile" From f461cbb3a290c554c17e4b448aa0649cc2bc7bf3 Mon Sep 17 00:00:00 2001 From: Naomi Calabretta Date: Mon, 29 Mar 2021 12:56:08 +0200 Subject: [PATCH 2/2] Warn if an argument is passed more than once also respect the first passed argument of its kind only --- nekofetch | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/nekofetch b/nekofetch index df502d1..5b6ce85 100755 --- a/nekofetch +++ b/nekofetch @@ -1,38 +1,62 @@ #!/bin/sh tmpfile="$(mktemp)" -imgurl="https://nekos.life/api/v2/img/neko" -height="$(($(stty size | awk '{print $1}') - 5))" +imgtype="" +use_height="" while :; do case "$1" in "--nsfw"|"nsfw"|"-n"|"n") - [ "$DEBUG" = "true" ] && echo "Getting a nsfw image" - imgurl="https://nekos.life/api/v2/img/cum_jpg" + if [ "$imgtype" = "" ]; then + [ "$DEBUG" = "true" ] && echo "Getting a nsfw image" + imgtype="nsfw" + else + echo "$imgtype images were already chosen! Please only specify either sfw or nsfw!" + fi ;; "--sfw"|"sfw"|"-s"|"s") - [ "$DEBUG" = "true" ] && echo "Getting a sfw image" - imgurl="https://nekos.life/api/v2/img/neko" + if [ "$imgtype" = "" ]; then + [ "$DEBUG" = "true" ] && echo "Getting a sfw image" + imgtype="sfw" + else + echo "$imgtype images were already chosen! Please only specify either sfw or nsfw!" + fi ;; "--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" + if [ "$use_height" = "" ]; then + use_height="$2" + [ "$DEBUG" = "true" ] && echo "Using height $height" + else + echo "You can only specify the height argument once!" + fi shift ;; *) if [ -z "$1" ]; then break fi - [ "$DEBUG" = "true" ] && echo "Could not interpret parameter '$1'." + echo "Could not interpret parameter '$1'." ;; esac shift done +if [ "$imgtype" = "nsfw" ]; then + imgurl="https://nekos.life/api/v2/img/cum_jpg" +else + imgurl="https://nekos.life/api/v2/img/neko" +fi + +if [ "$use_height" != "" ]; then + height="$use_height" +else + height="$(($(stty size | awk '{print $1}') - 5))" +fi + url=$(curl -fsSL "$imgurl" | jq -r ".url") curl -fsSLo "$tmpfile.jpg" "$url"