dot

packages and services management
Log | Files | Refs | README

commit 1f111ab8ee1d02b711f8a9bfabb02b79bfa91a08
parent c5cf94b8862bbbb0c1233b6669d09b9326158e6a
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 22 Dec 2017 13:12:17 +0100

print body as well

Diffstat:
Mbin/calendar | 96++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 56 insertions(+), 40 deletions(-)

diff --git a/bin/calendar b/bin/calendar @@ -47,30 +47,18 @@ function to_date(fmt, sec) for (min = 0; sec >= 60; min++) sec -= 60; return sprintf(fmt, yrs, mth, day, hrs, min, sec); -} +} ' -function rfc3339(str) { - yrs = substr(str, 1, 4); - mth = substr(str, 6, 2); - day = substr(str, 9, 2); - hrs = substr(str, 12, 2); - min = substr(str, 15, 2); - sec = substr(str, 18, 2); - sub("^[^ ]+\\.[0-9]+", "", str); - off = substr(str, 1, 1) == "Z" ? 0 : substr(str, 1, 3); - return to_sec(yrs, mth, day, hrs, min, sec) - off * 3600; +awk_import=$awk_date'#OFF=[+-]HH +function ical_date(str, off) { + yrs = substr(str, 1, 4); + mth = substr(str, 5, 2); + day = substr(str, 7, 2); + hrs = substr(str, 10, 2); + min = substr(str, 12, 2); + return to_sec(yrs, mth, day, hrs, min, 0) - off * 3600; } -function ical(str) { - yrs = substr(event["DTSTART"], 1, 4); - mth = substr(event["DTSTART"], 5, 2); - day = substr(event["DTSTART"], 7, 2); - hrs = substr(event["DTSTART"], 10, 2); - min = substr(event["DTSTART"], 12, 2); - return to_sec(yrs, mth, day, hrs, min, 0); -}' - -awk_import=$awk_date'#OFF=[+-]HH BEGIN { FS = "[:;]"; } @@ -91,27 +79,26 @@ BEGIN { } /END:VEVENT/ { - gsub("<[a-zA-Z0-9/]*>", "", event["DESCRIPTION"]); + gsub(" *<[a-zA-Z0-9/]*> *", "", event["DESCRIPTION"]); gsub("\\\\n", "\nD:", event["DESCRIPTION"]); - printf("T:%d %d\nS:%s\nC:%s\nL:%s\nD:%s\n:\n", - ical(event["DTSTART"]) - OFF * 3600, - ical(event["DTEND"]) - OFF * 3600, + printf("B:%d\nE:%d\nS:%s\nC:%s\nL:%s\nD:%s\n:\n", + ical_date(event["DTSTART"], OFF), ical_date(event["DTEND"], OFF), event["SUMMARY"], event["CATEGORIES"], event["LOCATION"], event["DESCRIPTION"]); }' -awk_sort='#SORT=[TSCL] +awk_sort='#SORT=[BESCL] BEGIN { FS=":" sort = "sort | cut -f " length(SORT) + 2 "-"; } -/^T:/ { +/^B:/ { nb = 1; - line["T"] = line["S"] = line["C"] = line["L"] = line["D"] = ""; + line["B"] = line["E"] = line["S"] = line["C"] = line["L"] = line["D"] = ""; } -/^[TSCLD]:/ { +/^[BESCLD]:/ { line[nb++] = sprintf("%08d\t%s", NR, $0); line[$1] = substr($0, 3); } @@ -125,13 +112,45 @@ BEGIN { printf("%s%s\n", prefix, line[i]) | sort; }' -awk_show=$awk_date' -/^[TSCLD]:/ { - line[$1] = substr($0, 4); +awk_show=$awk_date'#OFF=[+-]HH +function fold(str) +{ + while ((l = substr(str, 1, 66)) != "") { + sub(" +[^ ]*$", "", l); + str = substr(str, length(l) + 1); + printf(" | %s\n", l); + sub(" *", "", str); + } +} + +BEGIN { + FS = ":" +} + +/^B:/ { + line["B"] = line["E"] = line["S"] = line["C"] = line["L"] = line["D"] = ""; +} + +/^[BESCLD]:/ { + if (line[$1] == "") + line[$1] = substr($0, 3); + else + line[$1] = line[$1] " " substr($0, 3); } /^:$/ { - date = to_date("%04d/%02d/%02d %02d:%02d"); + beg = to_date("%04d/%02d/%02d %02d:%02d", line["B"] + 0); + end = to_date("%04d/%02d/%02d %02d:%02d", line["E"] + 0); + beg_mth = substr(beg, 1, 7); + beg_day = substr(beg, 9, 2); + beg_h_m = substr(beg, 12); + printf("%s\n%2s %s %s\n [%s] %s\n", + (beg_mth != last_mth) ? ("\n\n[" beg_mth "]\n") : "", + (beg_day != last_day) ? (beg_day) : (""), + beg_h_m, line["S"], line["C"], line["L"]); + fold(line["D"]); + last_mth = beg_mth; + last_day = beg_day; }' mkdir -p "$CALENDAR" @@ -141,17 +160,14 @@ case $1 in [ $# -ne 4 ] && exec "$0" awk -v OFF="$4" "$awk_import" "$2" > "$CALENDAR/$3" ;; -(list) - [ $# -ne 1 ] && exec "$0" - ls -C "$CALENDAR" - ;; (show) [ $# -ne 2 ] && [ $# -ne 3 ] && exec "$0" - awk -v SORT="${3:-TCLS}" "$awk_sort" "$CALENDAR/$2" + awk -v SORT="${3:-BECLS}" "$awk_sort" "$CALENDAR/$2" | + awk -v OFF="$(date +%z | cut -c 1-3)" "$awk_show" ;; (*) printf 'usage: calendar import ics_file name [+-]HH\n' - printf ' list\n' - printf ' show name [TSCL]\n' + printf ' calendar show name [BESCL]\n\n' + ls -C "$CALENDAR" ;; esac