X-Git-Url: https://software.frrobert.com/lace/blobdiff_plain/d018d21991d5ad1dfaab712dd447a813f313fb0c..HEAD:/lace diff --git a/lace b/lace old mode 100644 new mode 100755 index 951a0f8..2b7ad41 --- a/lace +++ b/lace @@ -4,6 +4,11 @@ # https://raw.githubusercontent.com/frrobert2/lace/main/lace # Shows both how many days ago and date # Modified to work with Debian running Sed 3.7 +# connectto is a timeout variable in seconds +# it is the time lace will wait to connect to a site before it stops the connection +# default is 30 seconds you can change it what you want +connectto=30 +set -o pipefail if [ -z "$XDG_CONFIG_HOME" ];then config_place="$HOME/.config/lace" else @@ -16,8 +21,15 @@ red="[31m" blue="[34m" nc="[m" esc=$(echo -e "\033") + if [[ "$1" == "strict" ]] || [[ "$1" == "--strict" ]] || [[ "$1" == "-strict" ]] || [[ "$1" == "-s" ]];then + red="### " + blue="### " + nc="" + esc="" + fi tmpfile=$(mktemp /tmp/lace.XXXXXX) tmpfile2=$(mktemp /tmp/lace.XXXXXX) +tmpfile3=$(mktemp /tmp/lace.XXXXXX) function reldate() { # stolen from https://unix.stackexchange.com/a/451216 local SEC_PER_MINUTE=$((60)) @@ -78,16 +90,32 @@ function timeline() { url="$url/" fi domain=$(sed 's/\/.*$//' <<< "$domain") - fav=$(openssl s_client -crlf -quiet -connect "$domain:1965" <<<"gemini://$domain/favicon.txt" 2>/dev/null | sed -e '1d') - if [ ! -z "$fav" ];then - user="$fav $user" + timeout $connectto openssl s_client -crlf -quiet -connect "$domain:1965" <<<"$url" 2>/dev/null > $tmpfile3 + timeoutstatus=${PIPESTATUS[0]} + if [ $timeoutstatus -ne 124 ];then + local newuser=$(cat $tmpfile3 | grep -m 1 author: | awk -F ":" '{print $2}' ) + local newavatar=$(cat $tmpfile3 | grep -m 1 avatar: | awk -F ":" '{print $2}' ) + if [[ $newuser != "" ]] + then + newuser=$(echo "$newuser" | xargs) + newavatar=$(echo "$newavatar" | xargs) + user="$newavatar $newuser" + else + fav=$(timeout $connectto openssl s_client -crlf -quiet -connect "$domain:1965" <<<"gemini://$domain/favicon.txt" 2>/dev/null | sed -e '1d') +if [ ! -z "$fav" ];then + user="$fav $user" + fi + fi - openssl s_client -crlf -quiet -connect "$domain:1965" <<<"$url" 2>/dev/null | sed -e '1d' | sed -n '/##/,$p' | sed -e "s/^\(## .*\)$/\1\n${esc}$red$user${esc}$nc ($domain)/g" >> $tmpfile + + cat $tmpfile3 | sed -e '1d' | sed -n '/##/,$p' | sed -e "s/^\(## .*\)$/\1\n${esc}$red$user${esc}$nc ($domain)/g" >> $tmpfile [[ ! -z $(sed -n '$p' $tmpfile) ]] && echo "" >> $tmpfile + fi done <"$subsfile" - cat $tmpfile | sed -r ':r;/(^|\n)$/!{$!{N;br}};s/\n/\v/g' | sed -rn '/^## .*/p' | sed -e 's/\v/\n/g' | sed -e "s/^## \(.*\)/date -d '\1' +%s/e" | sed -r ':r;/(^|\n)$/!{$!{N;br}};s/\n/\v/g' | sort -r | sed -e 's/\v/\n/g' > $tmpfile + cat $tmpfile | sed -r ':r;/(^|\n)$/!{$!{N;br}};s/\n/\v/g' | sed -rn '/^## .*/p' | sed -e 's/\v/\n/g' | sed -e "s/^## \(.*\)/date -d '\1' +%s/e" | sed -r ':r;/(^|\n)$/!{$!{N;br}};s/\n/\v/g' | sort -r | sed -e 's/\v/\n/g' > $tmpfile3 +cp $tmpfile3 $tmpfile # removed segment of code | sed "s/^\([0-9]\+\)$/{reldate \1 $now_unix;}/e" | sed "s/^\([0-9]* [a-z]* ago\)$/${esc}$blue\1${esc}$nc/g" while read line; do @@ -104,9 +132,9 @@ function timeline() { if [[ "$1" == "nope" ]];then - cat $tmpfile && rm -f $tmpfile $tmpfile2 + cat $tmpfile && rm -f $tmpfile $tmpfile2 $tmpfile3 else - less -RisW $tmpfile && rm -f $tmpfile $tmpfile2 + less -RisW $tmpfile && rm -f $tmpfile $tmpfile2 $tmpfile3 fi } @@ -126,7 +154,7 @@ elif [[ "$1" == "unsub" ]];then elif [[ "$1" == "subs" ]];then awk '{print $2" ("$1")"}' $subsfile elif [[ "$1" == "update" ]];then - curl https://gitlab.com/uoou/dotfiles/-/raw/master/stow/bin/home/drew/.local/bin/lace > "${BASH_SOURCE[0]}" + curl https://gitlab.com/frrobert2/lace/-/raw/dev/lace > "${BASH_SOURCE[0]}" else now_unix="$(date +'%s')" if [[ "$1" == "nope" ]];then