dot

packages and services management
Log | Files | Refs | README

commit fcd0efa42f116e5ed4ee5fcfed825fd966a00aa7
parent 49995f3cc58e3045f462862a2b30de75ffbbf9a9
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun, 11 Mar 2018 20:23:29 +0100

would you believe that?

Diffstat:
Mbin/agenda | 97+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 53 insertions(+), 44 deletions(-)

diff --git a/bin/agenda b/bin/agenda @@ -87,28 +87,31 @@ function sort(array, beg, end) sort(array, a, end); # sort higher half } -function view(line, nb) +function view(line, nb, off) { sort(line, 1, nb); for (i = 1; i < nb; i++) { sub("([^\t]*\t){" length(SORT) + 1 "}", "", line[i]); - if (line[i] ~ /^B:/) { + print(line[i]); + cat = line[substr(line[i], 1, 1)]; + + if (cat ~ /^[BESCLD]:/) { + if (line[1] == "") + line[cat] = substr(line[i], 3); + else + line[cat] = line[cat] " " substr(line[i], 3); + } else if (cat == "B") { line["B"] = line["E"] = line["S"] = ""; line["C"] = line["L"] = line["D"] = ""; - } else if (line[i] ~ /^[BESCLD]:/) { - if (line[$1] == "") - line[$1] = substr($0, 3); - else - line[$1] = line[$1] " " substr($0, 3); - } else if (line[i] ~ /:$/) { - display(line, i); + } else if (cat == "") { + display(last, line, off); } } } -function display(line, i, off) { +function display(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); b_mth = substr(beg, 1, 7); @@ -117,8 +120,8 @@ function display(line, i, off) { b_h_m = substr(beg, 12); e_h_m = substr(end, 12); printf("%s\n%2s %2s %s\n%2s %2s [%s] %s\n", - (b_mth != last_mth) ? ("\n[" b_mth "]\n") : "", - (b_day != last_day) ? (b_day) : (""), b_h_m, line["S"], + (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)) != "") { @@ -127,22 +130,15 @@ function display(line, i, off) { str = substr(str, length(l) + 1); sub("^ *", "", str); } - last_mth = b_mth; - last_day = b_day; -} - -function usage() -{ - print("usage: agenda -a <name> YYYY/MM/DD HH:MM [YYYY/MM/DD] HH:MM"); - print(" agenda -i <file.ics> <name> [+-]HH"); - print(" agenda [<name> [BESCL]]"); - exit(1); + last["mth"] = b_mth; + last["day"] = b_day; } function add(argc, argv) { file = AGENDA "/" argv[2]; date = argv[3] "T" argv[4]; + if (argc == 4) date2 = argv[3] "T" argv[4]; else if (argc == 5) @@ -159,6 +155,29 @@ function add(argc, argv) exit(0); } +function list() +{ + while ("find '" AGENDA "' -type f -o -type l" | getline file) { + while (getline < file) { + if (sub("^B:", "")) + min = ($0 < min || min == 0) ? $0 : min; + } + name = file; + sub(".*/", "", name); + printf("%s - %-10s %s\n", + to_date("%d/%02d/%02d", min + 3600), name, file); + } + exit(0); +} + +function usage() +{ + print("usage: agenda -a <name> YYYY/MM/DD HH:MM [YYYY/MM/DD] HH:MM"); + print(" agenda -i <file.ics> <name> [+-]HH"); + print(" agenda [<name> [BESCL]]"); + exit(1); +} + BEGIN { AGENDA = ENVIRON["AGENDA"] ? ENVIRON["AGENDA"] : @@ -170,23 +189,24 @@ BEGIN { close("date +%z"); OFF = substr(OFF, 1, 3); - if (ARGV[1] == "-i") { - IMPORT = 1; - FS = "[:;]"; - file = ARGV[2]; - } else if (ARGV[1] == "-i") { - add(ARGC, ARGV); + if (ARGC == 1) { + list(); } else if (system("test -f '" AGENDA "/" ARGV[1] "'") == 0) { VIEW = 1; FS = ":"; SORT = ARGV[2] ? ARGV[2] : "BECLS"; - file = AGENDA "/" ARGV[1] + ARGV[1] = AGENDA "/" ARGV[1] + } else if (ARGV[1] == "-a") { + add(ARGC, ARGV); + } else if (ARGV[1] == "-i") { + IMPORT = 1; + FS = "[:;]"; + ARGV[1] = ARGV[2]; } else { usage(); } - ARGV[1] = file; - ARGC = 1; + ARGC = 2; } IMPORT { @@ -235,18 +255,7 @@ VIEW && /^:$/ { line[i] = sprintf("%s%s", prefix, line[i]); } -LIST && sub("^B:", "") { - minimum = ($0 < minimum || minimum == 0) ? $0 : minimum; -} - END { - if (VIEW) { - view(line, nb); - } else if (IMPORT) { - } else if (LIST) { - name = FILENAME; - sub(".*/", "", name); - printf("%s - %-10s %s\n", - to_date("%d/%02d/%02d", minimum + 3600), name, FILENAME); - } + if (VIEW) + view(line, nb, OFF); }