dot

packages and services management
Log | Files | Refs | README

commit a90afa8545290200a9f45c88b68b2dbeef8ae4cb
parent da50f5c8dbdd3d278bd7f29e6c2b14a8164f563f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 20 Nov 2017 01:43:56 +0100

Mostly working implementation of twtxt

Diffstat:
Mbin/twtsh | 41++++++++++++++++++++++++-----------------
Atwtxt | 2++
2 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/bin/twtsh b/bin/twtsh @@ -2,9 +2,9 @@ # twtxt client in a single small POSIX shell script TWT_NICK=josuah -TWT_FILE=$HOME/twtxt.txt -TWT_CONF=$HOME -TWT_CACHE=$HOME/twtxt +TWT_FILE=$HOME/var/srv/josuah.net/twtxt.txt +TWT_CONF=$HOME/etc/twtxt +TWT_CACHE=$HOME/var/cache/twtxt err() { @@ -70,8 +70,8 @@ function rfc3339(str) { }' awk_line="$awk_date"' +BEGIN { "date +%z" | getline off; } /^20/ { - "date +%Z" | getline off sec = rfc3339($1) + off * 3600; printf("%s", to_date("%04d/%02d/%02d %02d:%02d:%02d", sec)); sub("[^\t]*\t", "", $0); @@ -81,12 +81,19 @@ awk_line="$awk_date"' awk_show=' { - sub("[^ ]+ [^ ]+ [^ ]+ ", "$0" - while (length() > 72) + printf("%s - %s %s\n", $3, $1, $2); + sub("[^ ]+ [^ ]+ [^ ]+ +", "", $0); + for (text = $0; length(text) > 72; sub(" *", "", text)) { + line = substr(text, 1, 72); + sub(" +[^ ]*$", "", line); + text = substr(text, length(line) + 1); + printf(" %s\n", line); + } + printf(" %s\n\n", text); }' -mkdir -p "$TWT_CONF" "$TWT_CACHE" -touch "$TWT_CONF/following" +mkdir -p "$TWT_CACHE" +touch "$TWT_CONF" case "$1" in (tweet) @@ -99,41 +106,41 @@ case "$1" in usr=$(printf %s "$usr" | sed 's/./[&]/g') url=$(printf %s "$url" | sed 's/[&/\]/\\&/g') msg=$(printf %s "$msg" | sed "s/@$usr/@<$new $url>/") - done < "$TWT_CONF/following" + done < "$TWT_CONF" printf '%s\t%s\n' "$(date +'%Y-%m-%dT%T%z' | sed 's/..$/:&/')" "$msg" | tr '\n' ' ' >> "$TWT_FILE" ;; (view) [ $# -ne 2 ] && exec "$0" [ -f "$TWT_CACHE/$2" ] || err "$2 feed not found. update and try again" - awk "$awk_line" "$TWT_CACHE/$2" | sort | awk "$awk_show" + awk "$awk_line" "$TWT_CACHE/$2" | sort -r | awk "$awk_show" | $PAGER ;; (timeline) [ $# -ne 1 ] && exec "$0" touch "$TWT_CACHE"/* || err 'no feed found. update and try again' - awk "$awk_line" "$TWT_CACHE"/* | sort | awk "$awk_show" + awk "$awk_line" "$TWT_CACHE"/* | sort -r | awk "$awk_show" | $PAGER ;; (update) while read -r usr url do curl -#L "$url" > "$TWT_CACHE/$usr" || rm "$TWT_CACHE/$usr" & - done < "$TWT_CONF/following" + done < "$TWT_CONF" wait ;; (follow) [ $# -ne 3 ] && exec "$0" - sed 's/[ ].*//' "$TWT_CONF/following" | grep -Fqx "$2" && + sed 's/[ ].*//' "$TWT_CONF" | grep -Fqx "$2" && err "already following the user $2" - printf '%s\t%s\n' "$2" "$3" >> "$TWT_CONF/following" - sort -u "$TWT_CONF/following" -o "$TWT_CONF/following" + printf '%s\t%s\n' "$2" "$3" >> "$TWT_CONF" + sort -u "$TWT_CONF" -o "$TWT_CONF" ;; (unfollow) [ $# -ne 2 ] && exec "$0" - tr '\t' ' ' | sed 's/ .*//' "$TWT_CONF/following" | grep -Fx "$2" || + tr '\t' ' ' | sed 's/ .*//' "$TWT_CONF" | grep -Fx "$2" || err "not folling $2" ;; (following) [ $# -ne 1 ] && exec "$0" - tr '\t' ' ' < "$TWT_CONF/following" | + tr '\t' ' ' < "$TWT_CONF" | sed -r -e 's/ / /' -e 's/(.{10}[^ ]*) */ \1 @ /' ;; (*) diff --git a/twtxt b/twtxt @@ -0,0 +1,2 @@ +technomancy https://technomancy.us/twtxt.txt +twtxt https://buckket.org/twtxt_news.txt