dot

packages and services management
Log | Files | Refs | README

commit a8663cf3af891b23941060ced69f5c623dcb10c5
parent 670963e0b5df478b31bc2e21f7a9c67d04558c5c
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 13 Apr 2018 17:45:30 +0200

simpler awk tools

Diffstat:
Mbin/agenda | 60+++++++++++++++++++++++++++++++-----------------------------
Mbin/markup-html | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbin/twt | 53++++++++++++++++++++---------------------------------
Mmblaze/filter | 30+++++++++++++++---------------
Mprofile | 8+++++---
Mtwt | 115-------------------------------------------------------------------------------
6 files changed, 173 insertions(+), 195 deletions(-)

diff --git a/bin/agenda b/bin/agenda @@ -94,68 +94,70 @@ function view(agenda, sort) while (getline < agenda) { if ($0 ~ /^B:/) { prev = nb; - line["B"] = line["E"] = line["S"] = ""; - line["C"] = line["L"] = line["D"] = ""; + entry["B"] = entry["E"] = entry["S"] = ""; + entry["C"] = entry["L"] = entry["D"] = ""; } if ($0 ~ /^[BESCLD]:/) { - line[nb++] = sprintf("%08d\t%s", NR, $0); - line[$1] = substr($0, 3); + entry[nb++] = sprintf("%08d\t%s", NR, $0); + entry[$1] = substr($0, 3); } if ($0 ~ /^:$/) { prefix = ""; - line[nb++] = sprintf("%08d\t:", NR); + entry[nb++] = sprintf("%08d\t:", NR); for (n = length(sort); n > 0; n--) - prefix = line[substr(sort, n, 1)] "\t" prefix; + prefix = entry[substr(sort, n, 1)] "\t" prefix; for (i = prev; i < nb; i++) - line[i] = sprintf("%s%s", prefix, line[i]); + entry[i] = sprintf("%s%s", prefix, entry[i]); } } - view_sort(line, nb, OFF, sort); + view_sort(entry, nb, OFF, sort); } -function view_sort(line, nb, off, sort) +function view_sort(entry, nb, off, sort) { - sort(line, 1, nb); + sort(entry, 1, nb); for (i = 1; i <= nb; i++) { pattern = ""; for (n = length(sort) + 1; n > 0; n--) pattern = pattern "[^\t]*\t"; - sub(pattern, "", line[i]); + sub(pattern, "", entry[i]); - cat = substr(line[i], 1, 1); + cat = substr(entry[i], 1, 1); if (cat ~ /^[BESCLD]$/) { - if (line[1] == "") - line[cat] = substr(line[i], 3); + if (entry[1] == "") + entry[cat] = substr(entry[i], 3); else - line[cat] = line[cat] " " substr(line[i], 3); + entry[cat] = entry[cat] " " substr(entry[i], 3); } else if (cat == "B") { - line["B"] = line["E"] = line["S"] = ""; - line["C"] = line["L"] = line["D"] = ""; + entry["B"] = entry["E"] = entry["S"] = ""; + entry["C"] = entry["L"] = entry["D"] = ""; } else if (cat == ":") { - view_one_line(last, line, off); + view_one_entry(last, entry, off); } } } -function view_one_line(last, line, off) { - beg = to_date("%04d/%02d/%02d %02d:%02d", line["B"] + off * 3600); - end = to_date("%04d/%02d/%02d %02d:%02d", line["E"] + off * 3600); +function view_one_entry(last, entry, off) { + beg = to_date("%04d/%02d/%02d %02d:%02d", entry["B"] + off * 3600); + end = to_date("%04d/%02d/%02d %02d:%02d", entry["E"] + off * 3600); b_mth = substr(beg, 1, 7); b_day = substr(beg, 9, 2); e_day = substr(end, 9, 2); b_h_m = substr(beg, 12); e_h_m = substr(end, 12); - printf("%s\n%2s %2s %s\n%2s %2s [%s] %s\n", + printf("%s\n%2s %2s %s\n%2s %2s ", (b_mth != last["mth"]) ? ("\n[" b_mth "]\n") : (""), - (b_day != last["day"]) ? (b_day) : (""), b_h_m, line["S"], - (b_day != e_day) ? (e_day) : (""), e_h_m, line["C"], line["L"]); - str = line["D"] " "; - while ((l = substr(str, 1, 66)) != "") { - sub(" +[^ ]*$", "", l); - printf(" %s\n", l); - str = substr(str, length(l) + 1); + (b_day != last["day"]) ? (b_day) : (""), b_h_m, entry["S"], + (b_day != e_day) ? (e_day) : (""), e_h_m); + str = entry["C"] " - " entry["L"] " - " entry["D"] " "; + for (first = 0; (line = substr(str, 1, 66)) != ""; first = 1) { + sub(" +[^ ]*$", "", line); + if (first == 1) + printf(" "); + printf("%s\n", line); + str = substr(str, length(line) + 1); sub("^ *", "", str); } last["mth"] = b_mth; diff --git a/bin/markup-html b/bin/markup-html @@ -1 +1,103 @@ #!/usr/bin/awk -f + +function esc(str) +{ + gsub("&", "\\&amp;", str); + gsub("<", "\\&lt;", str); + gsub(">", "\\&gt;", str); + gsub("\"", "\\&quot;", str); + return str; +} + +function fold(block, tag) +{ + len = length(prefix); + gsub("\t", " ", block); + sub("^ *", "", block); + sub(" *$", "", block); + gsub(" +", " ", block); + gsub("[.!?] ", "& ", block); + printf("<%s>%s</%s>\n", tag, esc(block), tag); +} + +function paragraph(block, prefix) +{ + if (block) fold(block, prefix); +} + +function title(block) +{ + print("\n<h1>" esc(block) "</h1>\n"); +} + +function heading(block) +{ + print("\n<h2>" esc(block) "</h2>\n"); +} + +function subheading(str) +{ + print("\n<h3>" esc(str) "</h3>\n"); +} + +/^\t/ { + paragraph(block, "p"); block = ""; + print("<pre>"); + while(match($0, /^\t/)) { + sub(" *$", ""); + sub("^\t", ""); + print; + if (!getline) exit; + } + print("</pre>"); +} + +/^>/ { + paragraph(block, "p"); block = ""; + while(sub(/^> */, "")) { + block = block " " $0; + if (!getline) exit; + } + paragraph(block, "blockquote"); block = ""; +} + +/^\[.*\]:/ { + paragraph(block, "p"); block = ""; + while (match($0, /^\[.*\]: */)) { + sub(" *$", ""); + printf("<a href=\"%s\">%s</a><br/>\n", substr($0, RLENGTH + 1), esc($0)); + if (!getline) exit; + } +} + +/^[ \t]*$/ { + paragraph(block, "p"); block = ""; next; +} + +/^=+$/ { + title(block); block = ""; next; +} + +/^-+$/ { + heading(block); block = ""; next; +} + +sub(/^# +/, "") { + paragraph(block, "p"); block = ""; title(block " " $0); next; +} + +sub(/^## +/, "") { + paragraph(block, "p"); block = ""; heading($0); next; +} + +sub(/^###+ */, "") { + paragraph(block, "p"); block = ""; subheading($0); next; +} + +{ + block = block " " $0; +} + +END { + paragraph(block, "p"); +} diff --git a/bin/twt b/bin/twt @@ -1,11 +1,6 @@ #!/bin/sh # twtxt client in a single small POSIX shell script -NICK='josuah' -TWT_FEED="${TWT_FEED-$HOME/.config/twtxt.txt}" -TWT_CONF="${TWT_CONF-$HOME/.config/twt}" -TWT_PATH="${TWT_PATH-$HOME/.cache/twt}" - view=' function leap(yrs) @@ -105,8 +100,8 @@ END { sort(lines, 1, nb); for (i = 1; i <= nb; i++) { split(lines[i], twt, "\t"); - printf("%-60s %s\n", twt[2], - to_date("%04d/%02d/%02d %02d:%02d:%02d", twt[1])); + printf("%s - %s\n", + to_date("%04d/%02d/%02d %02d:%02d", twt[1]), twt[2]); for (text = twt[3]; length(text) > 74; sub(" *", "", text)) { line = substr(text, 1, 74); sub(" +[^ ]*$", "", line); @@ -123,57 +118,49 @@ err() exit 1 } -mkdir -p "$TWT_PATH" "$(dirname "$TWT_CONF")" -touch "$TWT_CONF" +: ${TWTFEED-?} "${TWTCONF-?}" "${TWTPATH-?}" + +mkdir -p "$TWTPATH" "$(dirname "$TWTCONF")" +touch "$TWTCONF" case "$1" in (tweet) [ "$#" -ne 2 ] && exec "$0" - msg="$(printf %s "$2" | sed 's|[^ ]*://[^ ]*|@<&>|' | tr '\n' ' ')" - while read -r usr url - do - url="$(printf %s "$url" | sed 's/[&/\]/\\&/g')" - new="$(printf %s "$usr" | sed 's/[&/\]/\\&/g')" - usr="$(printf %s "$usr" | sed 's/./[&]/g')" - msg="$(printf %s "$msg" | sed "s/@$usr/@<$new $url>/")" - done < "$TWT_CONF" - printf '%s\t%s\n' "$(date +'%Y-%m-%dT%T%z' | sed 's/..$/:&/')" "$msg" \ - >> "$TWT_FEED" + date +'%Y-%m-%dT%T%z%t' >> "$TWTFEED" + $EDITOR "$TWTFEED" ;; (view) [ "$#" -ne 2 ] && exec "$0" - [ -f "$TWT_PATH/$2" ] || err "$2 feed not found, try update" - awk "$view" "$TWT_PATH/$2" + [ -f "$TWTPATH/$2" ] || err "$2 feed not found, try update" + awk "$view" "$TWTPATH/$2" ;; (timeline) [ "$#" -ne 1 ] && exec "$0" - ls "$TWT_PATH"/* 2> /dev/null 1>&2 || err 'no feed found, twt update' - find "$TWT_PATH" -type f -exec awk "$view" {} + + ls "$TWTPATH"/* 2> /dev/null 1>&2 || err 'no feed found, twt update' + find "$TWTPATH" -type f -exec awk "$view" {} + ;; (update) while read -r usr url do - curl -sLm 10 "$url" > "$TWT_PATH/$usr" || rm "$TWT_PATH/$usr" & - done < "$TWT_CONF" + curl -sLm 10 "$url" > "$TWTPATH/$usr" || rm "$TWTPATH/$usr" & + done < "$TWTCONF" wait ;; (follow) [ "$#" -ne 3 ] && exec "$0" - sed 's/[[:space:]].*//' "$TWT_CONF" | grep -Fqx "$2" && + sed 's/[[:space:]].*//' "$TWTCONF" | grep -Fqx "$2" && err "already following $2" - printf '%s\t%s\n' "$2" "$3" >> "$TWT_CONF" - sort -uo "$TWT_CONF" "$TWT_CONF" + printf '%s\t%s\n' "$2" "$3" >> "$TWTCONF" + sort -uo "$TWTCONF" "$TWTCONF" ;; (unfollow) [ "$#" -ne 2 ] && exec "$0" - sed 's/[[:space:]].*//' "$TWT_CONF" | grep -Fqx "$2" || - err "not following $2" - sed "/^$(printf %s "$2" | sed 's/./[&]/g')[[:space:]]/ d" "$TWT_CONF" | - sort -uo "$TWT_CONF" + grep -Fq "$2" "$TWTCONF" || err "not following $2" + grep -Fv "$2" "$TWTCONF" | sort -uo "$TWTCONF" ;; (following) [ "$#" -ne 1 ] && exec "$0" - sed -r 's/[[:space:]]/ /; s/(.{11}[^ ]*) */\1 @ /' "$TWT_CONF" + sed -r 's/[[:space:]]/ /; s/(.{11}[^ ]*) */\1 @ /' "$TWTCONF" ;; (*) printf 'usage: twt [tweet msg | view user | timeline | update\n' diff --git a/mblaze/filter b/mblaze/filter @@ -9,21 +9,21 @@ breizh-entropy.org "List-Id" "*breizh-entropy.org*" coinbase.com "From" "*coinbase.com*" crous-paris.fr "From" "*crous-paris.fr*" crous-rennes.fr "From" "*crous-rennes.fr*" -dragonflybsd.org/hammer "List-Id" "*hammer.dragonflybsd.org*" -dragonflybsd.org/kernel "List-Id" "*kernel.dragonflybsd.org*" +dragonflybsd.org--hammer "List-Id" "*hammer.dragonflybsd.org*" +dragonflybsd.org--kernel "List-Id" "*kernel.dragonflybsd.org*" dropbox.com "From" "*dropbox.*" ebay.com "From" "*ebay.*" -epitech.eu/bde "From" "*bde.epitech.rennes@gmail.com*" -epitech.eu/intra "From" "*@intra.epitech.eu*" -epitech.eu/marvin "From" "*nao.marvin@epitech.eu*" -epitech.eu/~ "From" "*@epitech.eu*" -epitech.eu/~ "From" "*ionis-group.org*" +epitech.eu--bde "From" "*bde.epitech.rennes@gmail.com*" +epitech.eu--intra "From" "*@intra.epitech.eu*" +epitech.eu--marvin "From" "*nao.marvin@epitech.eu*" +epitech.eu "From" "*@epitech.eu*" +epitech.eu "From" "*ionis-group.org*" etudiant.gouv.fr "From" "*etudiant.gouv.fr*" -fosdem.org/announce "List-Id" "*fosdem.lists.fosdem.org*" -fosdem.org/distributions "List-Id" "*distributions-devroom.lists.fosdem.org*" -fosdem.org/network "List-Id" "*network-devroom.lists.fosdem.org*" -fosdem.org/security "List-Id" "*security-devroom.lists.fosdem.org*" -fosdem.org/~ "From" "*fosdem.org*" +fosdem.org--announce "List-Id" "*fosdem.lists.fosdem.org*" +fosdem.org--distributions "List-Id" "*distributions-devroom.lists.fosdem.org*" +fosdem.org--network "List-Id" "*network-devroom.lists.fosdem.org*" +fosdem.org--security "List-Id" "*security-devroom.lists.fosdem.org*" +fosdem.org "From" "*fosdem.org*" free.fr "From" "*@free-mobile.fr*" freebsd.org "From" "*freebsd.org*" freenode.net "From" "*freenode.net*" @@ -40,9 +40,9 @@ meetup.com "From" "*meetup.com*" netsukuku.freaknet.org "List-Id" "*netsukuku.lists.dyne.org*" nixers.net "From" "*@nixers.net*" noip.com "From" "*@noip.com*" -openbsd.org/advocacy "List-ID" "*advocacy.openbsd.org*" -openbsd.org/announce "List-ID" "*announce.openbsd.org*" -openbsd.org/tech "List-ID" "*tech.openbsd.org*" +openbsd.org--advocacy "List-ID" "*advocacy.openbsd.org*" +openbsd.org--announce "List-ID" "*announce.openbsd.org*" +openbsd.org--tech "List-ID" "*tech.openbsd.org*" paypal.com "From" "*paypal.*" reddit.com "From" "*@reddit.*" reddit.com "From" "*@redditmail.com*" diff --git a/profile b/profile @@ -43,9 +43,11 @@ export LESSHISTFILE="-" export MBLAZE="$HOME/etc/mblaze" -export TWT_CONF="$HOME/etc/twt" -export TWT_PATH="$HOME/var/twt" -export TWT_FEED="$HOME/git/josuah.net/twtxt.txt" +export TWTCONF="$HOME/etc/twt" +export TWTPATH="$HOME/var/twt" +export TWTFEED="$HOME/git/josuah.net/twtxt.txt" + +export AGENDA="$HOME/etc/agenda" export SSH_AUTH_SOCK="/tmp/ssh-agent" diff --git a/twt b/twt @@ -20,118 +20,3 @@ beardog https://chaoswebs.net/twtxt.txt benaiah http://benaiah.me/twtxt.txt benjo https://yhaupenthal.org/twtxt.txt beyond https://enotty.dk/beyond.txt -boxofbats https://www.boxofbats.com/t -brice http://pelmel.org/twtxt.txt -buckket https://buckket.org/twtxt.txt -c0by https://c0by.de/twtxt.txt -caudasol https://enotty.dk/caudasol.txt -cel https://celehner.com/twtxt.txt -clementd http://clementd-files.cellar.services.clever-cloud.com/twtxt.txt -contraultra http://contraultra.me/twtxt.txt -cow2001 https://kaka.farm/twtxt.txt -cuntass https://www.google.co.uk/robots.txt -darthlukan https://www.brianctomlinson.com/static/twtxt.txt -dave http://davebucklin.com/twtxt.txt -david http://htwtxt.plomlompom.com/feeds/david -ddate https://enotty.dk/ddate.txt -directory http://twtxt.reednj.com/twtxt/directory.twtxt.txt -dizzy http://grex.org/~richtraube/twtxt.txt -dmpop http://dmpop.dhcp.io/twtxt.txt -domnirok http://twtxt.webdad.eu/twtxt.txt -dontdieych https://github.com/dontdieych/twtxt/raw/master/twtxt.txt -dracoblue https://dracoblue.net/twtxt.txt -durcheinandr https://durcheinandr.de/twtxt.txt -eazy http://test.plomlompom.com:8000/twtxt/eazy -edsu http://edsu.github.io/twtxt/twtxt.txt -ekch https://enotty.dk/ekch.txt -erlehmann http://daten.dieweltistgarnichtso.net/tmp/docs/twtxt.txt -esc http://escowles.github.io/tw.txt -fiatjaf http://fiatjaf.alhur.es/twtxt.txt -freemor http://freemor.homelinux.net:16019/~freemor/twtxt.txt -glow https://glow.li/twtxt.txt -hacker_news http://twtxt.xyz/t/hn_bot_top1/twtxt.txt -helgrima https://nyarlathotep.dy.fi/twtxt/helgrima.txt -horsemans http://horsemans.co/horsemans.txt -ionincognito http://resistit.net/twtxt/twtxt.txt -jack http://tilde.club/~jbaty/twtxt.txt -jamescampbell https://jamescampbell.us/twtxt.txt -jayay https://gist.githubusercontent.com/jayay/ef64ebda6a4ebdafb05a/raw/twtxt.txt?nocache -jinglemansweep http://louisking.uk/twtxt.txt -joachim https://joachimrobert.keybase.pub/twtxt.txt -joachimesque http://twtxt.xyz/u/joachimesque.txt -joel http://joeldueck.com/twtxt.txt -jomo https://gist.githubusercontent.com/jomo/64d6bd1b95ec0a24612b/raw/twtxt.txt -josuah http://josuah.net/0/twtxt.txt -kas https://enotty.dk/twtxt.txt -kasdk https://enotty.dk/kasdk.txt -kdave https://kdave.github.io/twtxt.txt -kdy https://twtxt.kdy.ch/twtxt.txt -kitchen http://bucket.kitchen.io/twtxt.txt -krt http://krt.marmaro.de/twtxt.txt -kseistrup http://kseistrup.keybase.pub/twtxt.txt -lahvak http://lahvak.github.io/twtxt/twtxt.txt -larry http://lhyn.es/twtxt.txt -leveck https://leveck.us/leveck.txt -ljones http://diary.ljones.id.au -lokimo https://raw.githubusercontent.com/lokimo/twtxt/master/twtxt.txt -luzifer http://twtxt.luzifer.io -mahoff https://core.thedoge.net/~mahoff/twtxt.txt -mdom http://www.domgoergen.com/twtxt.txt -mdosch https://mdosch.de/twtxt.txt -melvincarvalho https://melvin.databox.me/Public/twtxt/twtxt.txt -mian http://miangraham.com/twtxt.txt -mmk2410 https://mmk2410.org/twtxt.txt -moon https://enotty.dk/moon.txt -myles https://twtxt.mylesb.ca -nblade http://nblade.sdf.org/twtxt/twtxt.txt -nristen https://karl.thehomesteadinghippy.com/twtxt.txt -ordnungswidrig http://philipp.meier.name/twtxt.txt -parteigaenger http://vigintitres.eu/twtxt.txt -pete https://petedeas.co.uk/twtxt.txt -peteyboy http://peteyboy.freeshell.org/twtxt.txt -phil http://philmcclure.duckdns.org/twtxt.txt -plom http://test.plomlompom.com/twtxt/plom.txt -quite https://lublin.se/twtxt.txt -raguay http://customct.com/twtxt.txt -rasta http://datenloft.de/rasta/twtxt.txt -raur http://raur.nfshost.com/twtxt.txt -reddit_random http://twtxt.xyz/t/reddit_random/twtxt.txt -reednj http://twtxt.xyz/u/reednj.txt -reednj_tw http://twtxt.reednj.com/t/reednj/twtxt.txt -registry https://registry.twtxt.org/twtxt.txt -robbinaer https://robbinaer.info/twtxt.txt -ruebot http://ruebot.github.io/twtxt/twtxt.txt -samathy http://sbarratt.co.uk/twtxt.txt -sirx http://www.alphabetendswith.xyz/twtxt.txt -skingrapher http://www.skingrapher.com/t/tw.txt -srzkptrsk http://piatrouski.xyz/twtxt.txt -sungo https://sungo.wtf/twtxt.txt -tdemin https://tdemin.github.io/blog.txt -technomancy https://technomancy.us/twtxt.txt -tedder https://tedder.me/twtxt.txt -teddy https://data.trafficking.agency/twtxt.txt -teo https://murat.io/twtxt.txt -terinjokes http://twtxt.terinstock.com/twtxt.txt -tfurrows http://grex.org/~tfurrows/twtxt.txt -tiktok https://enotty.dk/tiktok.txt -tk https://tkd.keybase.pub/twtxt.txt -tomas https://bootlog.org/twtxt.txt -trevor https://destroyed.today/twtxt.txt -tux0r https://rosaelefanten.org/twtxt.txt -tuxtimo https://tuxtimo.me/twtxt.txt -twtxt https://buckket.org/twtxt_news.txt -tx gopher://tx.god.jp/0/twtxtfeed.cgi -umonkey http://land.umonkey.net/twtxt.txt -vinc https://vinc.cc/twtxt.txt -vrmxm https://asifade.in/twtxt.txt -webi http://twtxt.opstack.info/twtxt.txt -wp https://whiteplastic.net/twtxt.txt -xbg http://test.plomlompom.com:8000/twtxt/xbg -xena https://xena.greedo.xeserv.us/files/xena.txt -xn https://xn.pinkhamster.net/twtxt.txt -xpktro https://raw.githubusercontent.com/Xpktro/twtxt/master/twtxt.txt -xvm https://twtxt.xvm.space -yock http://mikeyockey.com/tw.txt -zichy http://htwtxt.plomlompom.com/feeds/zichy -zrolaps http://test.plomlompom.com/twtxt/zrolaps.txt -zurrguybbb http://stream.chunk.io/streams/21d693f0403b9f56809c3cb80702c35a