2 #Forked from https://gitlab.com/uoou/dotfiles/-/tree/master/stow/bin/home/drew/.local/bin/lace
3 # Modified to show date rather than how many days ago by frrobert2
5 if [ -z "$XDG_CONFIG_HOME" ];then
6 config_place="$HOME/.config/lace"
8 config_place="$XDG_CONFIG_HOME/lace"
10 [[ ! -d "$config_place" ]] && mkdir -p $config_place
11 subsfile="$config_place/subs"
17 tmpfile=$(mktemp /tmp/lace.XXXXXX)
21 echo -e "\t$(basename "$0") - read subscriptions\n"
22 echo -e "\t$(basename "$0") nope - read subscriptions without pager\n"
23 echo -e "\t$(basename "$0") subs - list subscriptions\n"
24 echo -e "\t$(basename "$0") sub nickname url - add subscription, e.g.:"
25 echo -e "\t$(basename "$0") sub Drew gemini://friendo.monster/tiny.gmi\n"
26 echo -e "\t$(basename "$0") unsub nickname - remove subscription, e.g.:"
27 echo -e "\t$(basename "$0") unsub Drew\n"
28 echo -e "\t$(basename "$0") update - redownload script to location of current script (might need sudo, depending on location)\n"
34 local user=$(awk '{print $2}' <<< "$f")
35 local url=$(awk '{print $1}' <<< "$f")
36 if [[ "$url" != *://* ]];then
40 domain=$(sed 's/gemini:\/\///' <<< "$url")
42 if [[ "$url" != *.*/*.* ]] && [[ $url != */ ]];then
45 domain=$(sed 's/\/.*$//' <<< "$domain")
46 fav=$(openssl s_client -crlf -quiet -connect "$domain:1965" <<<"gemini://$domain/favicon.txt" 2>/dev/null | sed -e '1d')
47 if [ ! -z "$fav" ];then
50 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
51 [[ ! -z $(sed -n '$p' $tmpfile) ]] && echo "" >> $tmpfile
53 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
55 sed -i "s/\(^[0-9]\{8,\}$\)/date -d @\1/e" $tmpfile
56 if [[ "$1" == "nope" ]];then
57 cat $tmpfile && rm -f $tmpfile
59 less -RisW $tmpfile && rm -f $tmpfile
63 if [[ "$1" == "help" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "-help" ]] || [[ "$1" == "-h" ]];then
65 elif [[ "$1" == "sub" ]];then
66 [[ "$#" -ne 3 ]] && dohelp
67 echo "$3 $2" >> $subsfile && echo "added $2 to subscriptions"
68 elif [[ "$1" == "unsub" ]];then
69 [[ "$#" -ne 2 ]] && dohelp
70 if grep " $2$" $subsfile 1>/dev/null;then
71 sed -i "/ $2$/d" $subsfile &&
72 echo "removed subscription to $2"
74 echo "subscription \"$2\" does not exist"
76 elif [[ "$1" == "subs" ]];then
77 awk '{print $2" ("$1")"}' $subsfile
78 elif [[ "$1" == "update" ]];then
79 curl https://gitlab.com/uoou/dotfiles/-/raw/master/stow/bin/home/drew/.local/bin/lace > "${BASH_SOURCE[0]}"
81 now_unix="$(date +'%s')"
82 if [[ "$1" == "nope" ]];then