dot

packages and services management
Log | Files | Refs | README

commit 8a620db48832190dda990b856dc0675476bb36ba
parent 20fb069256eef520e4aaba7d80fbab06fad43d79
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 22 Dec 2017 11:12:30 +0100

sorting per category

Diffstat:
Mbin/calendar | 46++++++++++++++++++++++++++++++++++------------
1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/bin/calendar b/bin/calendar @@ -72,7 +72,7 @@ function ical(str) { }' awk_import=$awk_date' -#-v off=[+-]HH +#-v OFF=[+-]HH BEGIN { FS = "[:;]"; @@ -96,36 +96,58 @@ BEGIN { /END:VEVENT/ { gsub("<[a-zA-Z0-9/]*>", "", event["DESCRIPTION"]); gsub("\\\\n", "\n:D:", event["DESCRIPTION"]); - printf("%d %d\n:S:%s\n:C:%s\n:L:%s\n:D:%s\n:\n", - ical(event["DTSTART"]), ical(event["DTEND"]), + printf(":T:%d %d\n:S:%s\n:C:%s\n:L:%s\n:D:%s\n:\n", + ical(event["DTSTART"]) + OFF * 3600, + ical(event["DTEND"]) + OFF * 3600, event["SUMMARY"], event["CATEGORIES"], event["LOCATION"], event["DESCRIPTION"]); }' -awk_show=' -/^[0-9]+ [0-9]+$/ { - +awk_sort=' +# -v SORT=[0SCL] + +BEGIN { + FS=":" + sort = "sort | cut -f " length(SORT) + 2 "-"; +} + +/^:T:/ { + nb = 1; + line["T"] = line["S"] = line["C"] = line["L"] = line["D"] = ""; } -' + +/^:[TSCLD]:/ { + line[nb++] = sprintf("%08d\t%s", NR, $0); + line[$2] = substr($0, 4); +} + +/^:$/ { + line[nb++] = sprintf("%08d\t%s", NR, $0); + prefix = ""; + for (i = length(SORT); i > 0; i--) + prefix = line[substr(SORT, i, 1)] "\t" prefix; + for (i = 1; i < nb; i++) + printf("%s%s\n", prefix, line[i]) | sort; +}' mkdir -p "$CALENDAR" case $1 in (import) [ $# -ne 4 ] && exec "$0" - awk -v off="$4" "$awk_import" "$2" > "$CALENDAR/$3" + awk -v OFF="$4" "$awk_import" "$2" > "$CALENDAR/$3" ;; (list) [ $# -ne 1 ] && exec "$0" ls -C "$CALENDAR" ;; (show) - [ $# -ne 2 ] && exec "$0" - awk "$awk_show" "$CALENDAR/$2" + [ $# -ne 2 ] && [ $# -ne 3 ] && exec "$0" + awk -v SORT="${3:-TCLS}" "$awk_sort" "$CALENDAR/$2" ;; (*) printf 'usage: calendar import ics_file name [+-]HH\n' - printf ' calendar list\n' - printf ' calendar show name\n' + printf ' list\n' + printf ' show name [TSCL]\n' ;; esac