feat: category filter

This commit is contained in:
2025-07-04 12:56:58 +02:00
parent 78d0983464
commit f663c200d2
6 changed files with 65 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
# Retrieve content from iCalendar file
# Retrieve content from iCalendar files
#
# Mandatory variable: `field`.
# Name of field to retrieve.
@@ -8,34 +8,42 @@
# comma-separated values, and empty values are dropped.
# If `format` is set to "date", then the content is interpreted as
# a date the output is in the form YYYY-MM-DD.
#
# Optional variable: `oneline`.
# If `oneline` is set, then the all newlines will be replaced by white spaces
@include "lib/awk/icalendar.awk"
# print content of field `field`
BEGIN { FS = ":"; ORS = ""; regex = "^" field; }
BEGIN { FS = ":"; regex = "^" field; }
BEGINFILE { type = ""; line = ""; }
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
/^END:/ && $2 == type { exit }
$0 ~ field { line = $0; next; }
/^END:/ && $2 == type { nextfile }
$0 ~ regex { line = $0; next; }
/^ / && line { line = line substr($0, 2); next; }
/^[^ ]/ && line { exit }
END {
if (!type) { exit }
# Process line
content = getcontent(line)
switch (format) {
case "csv" :
split(content, a, ",")
for (i in a) {
if (a[i])
res = res "," a[i]
}
print substr(res, 2)
break
case "date" :
if (content)
print substr(parse_dt("", content), 1, 10)
break
default :
print content
break
/^[^ ]/ && line { nextfile }
ENDFILE {
if (type) {
# Process line
content = getcontent(line)
if (oneline)
content = singleline(content)
switch (format) {
case "csv" :
split(content, a, ",")
res = ""
for (i in a) {
if (a[i])
res = res "," a[i]
}
print substr(res, 2)
break
case "date" :
if (content)
print substr(parse_dt("", content), 1, 10)
break
default :
print content
break
}
}
}

View File

@@ -39,9 +39,10 @@ NR == FNR && !el { print "Unrecognized header on line "NR": " $
NR == FNR { desc = "D" escape($0); next; }
due && type == "VJOURNAL" { print "Notes and journal entries do not have due dates." > "/dev/stderr"; exit 1; }
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2; print; next; }
/^X-ALT-DESC/ && type { next; } # drop this alternative description
/^ / && type { next; } # drop this folded line (the only content with folded lines will be updated)
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { next; } # skip for now, we will write updated fields at the end
/^ / && drop { next; } # drop this folded line
/^X-ALT-DESC/ && type { drop = 1; next; } # drop this alternative description
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { drop = 1; next; } # skip for now, we will write updated fields at the end
{ drop = 0 } # keep everything else
/^SEQUENCE/ && type { seq = $2; next; } # store sequence number and skip
/^END:/ && type == $2 {
seq = seq ? seq + 1 : 1;