39 lines
1.1 KiB
Awk
39 lines
1.1 KiB
Awk
## src/awk/weekview.awk
|
||
## Print view of all appointments of the current week.
|
||
## Generates view from
|
||
## printf "%s\t%s\t%s\t%s\n" "$i" "$s" "$e" "$description"
|
||
##
|
||
## @assign startofweek: Date of first day in the week
|
||
|
||
# Functions
|
||
|
||
# Compose line that will display a day in the week.
|
||
#
|
||
# @input desc: String with a description of the event
|
||
# @return: Single-line string
|
||
function c(desc) {
|
||
return CYAN desc OFF " " RED "/" OFF
|
||
}
|
||
|
||
# AWK program
|
||
|
||
BEGIN {
|
||
FS = "\t"
|
||
OFS = "\t"
|
||
GREEN = "\033[1;32m"
|
||
RED = "\033[1;31m"
|
||
CYAN = "\033[1;36m"
|
||
OFF = "\033[m"
|
||
}
|
||
$2 == "00:00" && $3 == "00:00" { dayline = dayline " " c($4); next }
|
||
$2 == "00:00" { dayline = dayline " → " $3 " " c($4); next }
|
||
$3 == "00:00" { dayline = dayline " " $2 " → " c($4); next }
|
||
NF == 4 { dayline = dayline " " $2 " – " $3 " " c($4); next }
|
||
NF == 1 && dayline { print "+", startofweek " +" $1-1 " days", "", dayline }
|
||
NF == 1 {
|
||
cmd = "date -d '" startofweek " +" $1 " days' +\"%a %e %b %Y\""
|
||
cmd | getline dayline
|
||
close(cmd)
|
||
dayline = GREEN dayline ": " OFF
|
||
}
|