Compare commits
No commits in common. "7a22f73d368f7d71e861d67e9733d75298c4ac3a" and "6973fb9f04f3c64060e4895ffe5eb134e05be556" have entirely different histories.
7a22f73d36
...
6973fb9f04
@ -1,47 +0,0 @@
|
|||||||
# 11:00|13:00|1748422800|1748430000|fpath|desc...
|
|
||||||
# 00:00|00:00|1748296800|1748383200|fpath|desc...
|
|
||||||
function allday(desc) {
|
|
||||||
return ITALIC FAINT " (allday) " OFF desc
|
|
||||||
}
|
|
||||||
function endstoday(stop, desc) {
|
|
||||||
return CYAN " -- " stop OFF ": " desc
|
|
||||||
}
|
|
||||||
function slice(start, stop, desc) {
|
|
||||||
if (stop == "00:00")
|
|
||||||
return CYAN start " -- " OFF ": " desc
|
|
||||||
else
|
|
||||||
return CYAN start OFF " -- " CYAN stop OFF ": " desc
|
|
||||||
}
|
|
||||||
function hrline(hour) {
|
|
||||||
hour = hour < 10 ? "0"hour : hour
|
|
||||||
print hour, "", "", "", FAINT hour ":00 ----------------------" OFF
|
|
||||||
}
|
|
||||||
function hrlines(start, stop, h, starth, stoph, tmp, i) {
|
|
||||||
starth = substr(start, 1, 2)
|
|
||||||
stoph = substr(stop, 1, 2)
|
|
||||||
tmp = substr(start, 4, 2) == "00" ? 0 : 1
|
|
||||||
for (i=h; i < starth + tmp; i++)
|
|
||||||
hrline(i)
|
|
||||||
tmp = substr(stop, 4, 2) == "00" ? 0 : 1
|
|
||||||
return stoph + tmp
|
|
||||||
}
|
|
||||||
BEGIN {
|
|
||||||
FS = "|"
|
|
||||||
GREEN = "\033[1;32m"
|
|
||||||
RED = "\033[1;31m"
|
|
||||||
WHITE = "\033[1;97m"
|
|
||||||
CYAN = "\033[1;36m"
|
|
||||||
ITALIC = "\033[3m"
|
|
||||||
FAINT = "\033[2m"
|
|
||||||
OFF = "\033[m"
|
|
||||||
OFS = "|"
|
|
||||||
}
|
|
||||||
$1 == "00:00" && $2 == "00:00" { print $1, $3, $4, $5, allday($6); next }
|
|
||||||
$1 == "00:00" { print $1, $3, $4, $5, endstoday($2, $6); next }
|
|
||||||
$1 ~ /^[0-9]{2}:[0-9]{2}$/ {
|
|
||||||
daystart = hrlines($1, $2, daystart, starth, stoph, tmp, i)
|
|
||||||
print $1, $3, $4, $5, slice($1, $2, $6)
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
hrlines(dayend":00", 0, daystart, starth, stoph, tmp, i)
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
# print content of field `field`
|
|
||||||
BEGIN { FS = ":"; regex = "^" field; }
|
|
||||||
/^BEGIN:VEVENT$/ { inside = 1 }
|
|
||||||
/^END:VEVENT$/ { exit }
|
|
||||||
$0 ~ regex { content = $0; next; }
|
|
||||||
/^ / && content { content = content substr($0, 2); next; }
|
|
||||||
/^[^ ]/ && content { exit }
|
|
||||||
END {
|
|
||||||
if (!inside) { exit }
|
|
||||||
# Process content line
|
|
||||||
content = substr(content, index(content, ":") + 1);
|
|
||||||
gsub("\\\\n", "\n", content);
|
|
||||||
gsub("\\\\N", "\n", content);
|
|
||||||
gsub("\\\\,", ",", content);
|
|
||||||
gsub("\\\\;", ";", content);
|
|
||||||
gsub("\\\\\\\\", "\\", content);
|
|
||||||
print content;
|
|
||||||
}
|
|
@ -48,7 +48,7 @@ function title(start, summary) {
|
|||||||
depth = split(FILENAME, path, "/");
|
depth = split(FILENAME, path, "/");
|
||||||
collection = depth > 1 ? path[depth-1] : "";
|
collection = depth > 1 ? path[depth-1] : "";
|
||||||
collection = collection in collection2label ? collection2label[collection] : collection;
|
collection = collection in collection2label ? collection2label[collection] : collection;
|
||||||
return FAINT "~ " collection " " gensub(/^[^0-9]*([0-9]{4})([0-9]{2}).*$/, "\\1-\\2", "1", start) " " summary OFF
|
return FAINT "~ " collection " " gensub(/^[^0-9]*([0-9]{4})([0-9]{2}).*$/, "\\1-\\2", "1", start) " " summary " ;" start OFF
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
@ -69,7 +69,7 @@ BEGIN {
|
|||||||
OFF = "\033[m";
|
OFF = "\033[m";
|
||||||
}
|
}
|
||||||
BEGINFILE { inside = 0; rs = 0; dur = 0; summary = ""; start = "ERROR"; end = "ERROR" }
|
BEGINFILE { inside = 0; rs = 0; dur = 0; summary = ""; start = "ERROR"; end = "ERROR" }
|
||||||
/^END:VEVENT/ { print "~", start, dur ? start " " end : end, title(start, summary), fn(FILENAME, n, a); nextfile }
|
/^END:VEVENT/ { print start, dur ? start " " end : end, title(start, summary), fn(FILENAME, n, a); nextfile }
|
||||||
/^DTSTART/ && inside { start = parse( dt) }
|
/^DTSTART/ && inside { start = parse( dt) }
|
||||||
/^DTEND/ && inside { end = parse( dt) }
|
/^DTEND/ && inside { end = parse( dt) }
|
||||||
/^DURATION/ && inside { end = parse_duration( dt, dta, i, n, a, seps); dur = 1 }
|
/^DURATION/ && inside { end = parse_duration( dt, dta, i, n, a, seps); dur = 1 }
|
||||||
|
@ -11,7 +11,7 @@ NR == FNR {
|
|||||||
if (from[FNR] > to[FNR])
|
if (from[FNR] > to[FNR])
|
||||||
print "FNR", FNR, ":", from[FNR],"-",to[FNR], " ",$0;
|
print "FNR", FNR, ":", from[FNR],"-",to[FNR], " ",$0;
|
||||||
for(i=from[FNR]; i<=to[FNR]; i++) {
|
for(i=from[FNR]; i<=to[FNR]; i++) {
|
||||||
week[i] = week[i] " " $5
|
week[i] = week[i] ? week[i] ";" $4 : $4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END { for (i in week) print i week[i]; }
|
END { for (i in week) print i, week[i]; }
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
function escape(str)
|
|
||||||
{
|
|
||||||
gsub("\\\\", "\\\\", str);
|
|
||||||
gsub(";", "\\\\;", str);
|
|
||||||
gsub(",", "\\\\,", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_fold(nameparam, content, i, s)
|
|
||||||
{
|
|
||||||
i = 74 - length(nameparam);
|
|
||||||
s = substr(content, 1, i);
|
|
||||||
print nameparam s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
while (s)
|
|
||||||
{
|
|
||||||
print " " s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
FS=":";
|
|
||||||
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
|
|
||||||
}
|
|
||||||
desc { desc = desc "\\n" $0; next; }
|
|
||||||
{
|
|
||||||
from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : "";
|
|
||||||
getline
|
|
||||||
to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : "";
|
|
||||||
getline
|
|
||||||
summary = substr($0, 1, 2) == "# " ? substr($0, 3) : ""
|
|
||||||
getline # This line should be empty
|
|
||||||
getline # First line of description
|
|
||||||
desc = $0;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
END {
|
|
||||||
# Sanitize input
|
|
||||||
# If nanoseconds are not 0, then we assume user enterd "tomorrow" or
|
|
||||||
# something the like, and we make this a date entry, as opposed to a
|
|
||||||
# date-time entry.
|
|
||||||
from = from ? from : "now"
|
|
||||||
cmd = "date -d \"" from "\" +\"%N\"";
|
|
||||||
cmd | getline t
|
|
||||||
close(cmd)
|
|
||||||
t = t + 0
|
|
||||||
print "fromnano="t
|
|
||||||
if (t == 0) {
|
|
||||||
print "ok, DATE-TIME type"
|
|
||||||
from_type = "DATE-TIME"
|
|
||||||
cmd = "date -d \"" from "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d"
|
|
||||||
} else {
|
|
||||||
print "ok, DATE type"
|
|
||||||
from_type = "DATE"
|
|
||||||
cmd = "date -d \"" from "\" +\"%Y%m%d\"";
|
|
||||||
}
|
|
||||||
cmd | getline from
|
|
||||||
close(cmd)
|
|
||||||
print "FROM="from
|
|
||||||
#
|
|
||||||
to = to ? to : "now"
|
|
||||||
cmd = "date -d \"" to "\" +\"%N\"";
|
|
||||||
cmd | getline t
|
|
||||||
close(cmd)
|
|
||||||
t = t + 0
|
|
||||||
if (t == 0) {
|
|
||||||
to_type = "DATE-TIME"
|
|
||||||
cmd = "date -d \"" to "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d"
|
|
||||||
} else {
|
|
||||||
to_type = "DATE"
|
|
||||||
cmd = "date -d \"" to "\" +\"%Y%m%d\"";
|
|
||||||
}
|
|
||||||
cmd | getline to
|
|
||||||
close(cmd)
|
|
||||||
escape(summary);
|
|
||||||
escape(desc);
|
|
||||||
|
|
||||||
# print ical
|
|
||||||
print "BEGIN:VCALENDAR";
|
|
||||||
print "VERSION:2.0";
|
|
||||||
print "CALSCALE:GREGORIAN";
|
|
||||||
print "PRODID:-//fab//awk//EN";
|
|
||||||
print "BEGIN:VEVENT"
|
|
||||||
print "DTSTAMP:" zulu;
|
|
||||||
print "UID:" uid;
|
|
||||||
print "CLASS:PRIVATE";
|
|
||||||
print "CREATED:" zulu;
|
|
||||||
print "SEQUENCE:1";
|
|
||||||
print "LAST-MODIFIED:" zulu;
|
|
||||||
print "STATUS:FINAL";
|
|
||||||
print "DTSTART;VALUE=" from_type ":" from
|
|
||||||
print "DTEND;VALUE=" to_type ":" to
|
|
||||||
if (summary) print_fold("SUMMARY:", summary, i, s);
|
|
||||||
if (desc) print_fold("DESCRIPTION:", desc, i, s);
|
|
||||||
print "END:VEVENT"
|
|
||||||
print "END:VCALENDAR"
|
|
||||||
}
|
|
@ -38,10 +38,8 @@ function print_data(start, dur, end, summary, cmd, collection) {
|
|||||||
gsub("\\\\;", ";", summary);
|
gsub("\\\\;", ";", summary);
|
||||||
gsub("\\\\\\\\", "\\", summary);
|
gsub("\\\\\\\\", "\\", summary);
|
||||||
depth = split(FILENAME, path, "/");
|
depth = split(FILENAME, path, "/");
|
||||||
fpath = path[depth-1] "/" path[depth]
|
|
||||||
collection = depth > 1 ? path[depth-1] : "";
|
collection = depth > 1 ? path[depth-1] : "";
|
||||||
collection = collection in collection2label ? collection2label[collection] : collection;
|
collection = collection in collection2label ? collection2label[collection] : collection;
|
||||||
collection = collection2label[path[depth-1]]
|
|
||||||
end = dur ? start " " end : end
|
end = dur ? start " " end : end
|
||||||
cmd = "date -d '" start "' +\"%s\""
|
cmd = "date -d '" start "' +\"%s\""
|
||||||
cmd | getline start
|
cmd | getline start
|
||||||
@ -49,7 +47,7 @@ function print_data(start, dur, end, summary, cmd, collection) {
|
|||||||
cmd = "date -d '" end "' +\"%s\""
|
cmd = "date -d '" end "' +\"%s\""
|
||||||
cmd | getline end
|
cmd | getline end
|
||||||
close(cmd)
|
close(cmd)
|
||||||
print start, end, fpath, collection, summary
|
print start, end, collection, summary
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
@ -60,6 +58,13 @@ BEGIN {
|
|||||||
split(mapping[map], m, "=");
|
split(mapping[map], m, "=");
|
||||||
collection2label[m[1]] = m[2];
|
collection2label[m[1]] = m[2];
|
||||||
}
|
}
|
||||||
|
# Colors
|
||||||
|
GREEN = "\033[1;32m";
|
||||||
|
RED = "\033[1;31m";
|
||||||
|
WHITE = "\033[1;97m";
|
||||||
|
CYAN = "\033[1;36m";
|
||||||
|
FAINT = "\033[2m";
|
||||||
|
OFF = "\033[m";
|
||||||
}
|
}
|
||||||
/^END:VEVENT/ && inside { print_data(start, dur, end, summary, cmd, collection); exit }
|
/^END:VEVENT/ && inside { print_data(start, dur, end, summary, cmd, collection); exit }
|
||||||
/^DTSTART/ && inside { start = parse( dt) }
|
/^DTSTART/ && inside { start = parse( dt) }
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
function getcontent(content_line, prop)
|
|
||||||
{
|
|
||||||
return substr(content_line[prop], index(content_line[prop], ":") + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function escape(str)
|
|
||||||
{
|
|
||||||
gsub("\\\\", "\\\\", str);
|
|
||||||
gsub(";", "\\\\;", str);
|
|
||||||
gsub(",", "\\\\,", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_fold(nameparam, content, i, s)
|
|
||||||
{
|
|
||||||
i = 74 - length(nameparam);
|
|
||||||
s = substr(content, 1, i);
|
|
||||||
print nameparam s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
while (s)
|
|
||||||
{
|
|
||||||
print " " s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
FS=":";
|
|
||||||
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ENDFILE {
|
|
||||||
if (NR == FNR)
|
|
||||||
{
|
|
||||||
# If nanoseconds are not 0, then we assume user enterd "tomorrow" or
|
|
||||||
# something the like, and we make this a date entry, as opposed to a
|
|
||||||
# date-time entry.
|
|
||||||
from = from ? from : "now"
|
|
||||||
cmd = "date -d \"" from "\" +\"%N\"";
|
|
||||||
cmd | getline t
|
|
||||||
close(cmd)
|
|
||||||
t = t + 0
|
|
||||||
if (t == 0) {
|
|
||||||
from_type = "DATE-TIME"
|
|
||||||
cmd = "date -d \"" from "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d"
|
|
||||||
} else {
|
|
||||||
from_type = "DATE"
|
|
||||||
cmd = "date -d \"" from "\" +\"%Y%m%d\"";
|
|
||||||
}
|
|
||||||
cmd | getline from
|
|
||||||
close(cmd)
|
|
||||||
#
|
|
||||||
to = to ? to : "now"
|
|
||||||
cmd = "date -d \"" to "\" +\"%N\"";
|
|
||||||
cmd | getline t
|
|
||||||
close(cmd)
|
|
||||||
t = t + 0
|
|
||||||
if (t == 0) {
|
|
||||||
to_type = "DATE-TIME"
|
|
||||||
cmd = "date -d \"" to "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d"
|
|
||||||
} else {
|
|
||||||
to_type = "DATE"
|
|
||||||
cmd = "date -d \"" to "\" +\"%Y%m%d\"";
|
|
||||||
}
|
|
||||||
cmd | getline to
|
|
||||||
close(cmd)
|
|
||||||
}
|
|
||||||
escape(summary);
|
|
||||||
escape(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
NR == FNR && desc { desc = desc "\\n" $0; next; }
|
|
||||||
NR == FNR {
|
|
||||||
from = substr($0, 1, 6) == "::: |>" ? substr($0, 8) : "";
|
|
||||||
getline
|
|
||||||
to = substr($0, 1, 6) == "::: <|" ? substr($0, 8) : "";
|
|
||||||
getline
|
|
||||||
summary = substr($0, 1, 2) == "# " ? substr($0, 3) : ""
|
|
||||||
getline # This line should be empty
|
|
||||||
getline # First line of description
|
|
||||||
desc = $0;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/^BEGIN:VEVENT$/ { inside = 1; print; next }
|
|
||||||
/^X-ALT-DESC/ && inside { next } # drop this alternative description
|
|
||||||
/^ / && inside { next } # drop this folded line (the only content with folded lines will be updated)
|
|
||||||
/^(DTSTART|DTEND|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && inside { next } # skip for now, we will write updated fields at the end
|
|
||||||
/^SEQUENCE/ && inside { seq = $2; next } # store sequence number and skip
|
|
||||||
/^END:VEVENT$/ {
|
|
||||||
seq = seq ? seq + 1 : 1
|
|
||||||
print "SEQUENCE:" seq
|
|
||||||
print "LAST-MODIFIED:" zulu
|
|
||||||
print "DTSTART;VALUE=" from_type ":" from
|
|
||||||
print "DTEND;VALUE=" to_type ":" to
|
|
||||||
print_fold("SUMMARY:", summary, i, s)
|
|
||||||
print_fold("DESCRIPTION:", desc, i, s)
|
|
||||||
inside = ""
|
|
||||||
}
|
|
||||||
{ print }
|
|
@ -8,13 +8,12 @@ BEGIN {
|
|||||||
CYAN = "\033[1;36m";
|
CYAN = "\033[1;36m";
|
||||||
FAINT = "\033[2m";
|
FAINT = "\033[2m";
|
||||||
OFF = "\033[m";
|
OFF = "\033[m";
|
||||||
OFS = "|"
|
|
||||||
}
|
}
|
||||||
/^[0-7] 00:00 -- 00:00/ { dayline = dayline " " c(); next }
|
/^[0-7] 00:00 -- 00:00/ { dayline = dayline " " c(); next }
|
||||||
/^[0-7] 00:00 -- / { dayline = dayline " <-|" $4 " " c(); next }
|
/^[0-7] 00:00 -- / { dayline = dayline " <-|" $4 " " c(); next }
|
||||||
/^[0-7] [0-9]{2}:[0-9]{2} -- 00:00/ { dayline = dayline " " $2 "|-> " c(); next }
|
/^[0-7] [0-9]{2}:[0-9]{2} -- 00:00/ { dayline = dayline " " $2 "|-> " c(); next }
|
||||||
/^[0-7] [0-9]{2}:[0-9]{2} -- [0-9]{2}:[0-9]{2}/ { dayline = dayline " " $2 " - " $4 " " c(); next }
|
/^[0-7] [0-9]{2}:[0-9]{2} -- [0-9]{2}:[0-9]{2}/ { dayline = dayline " " $2 " - " $4 " " c(); next }
|
||||||
/^[0-7]$/ && dayline { print "+", startofweek " +" $0-1 " days", "", dayline; }
|
/^[0-7]$/ && dayline { print dayline " ;" startofweek " +" $0 " days"; }
|
||||||
/^[0-7]$/ {
|
/^[0-7]$/ {
|
||||||
cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\"";
|
cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\"";
|
||||||
cmd | getline dayline;
|
cmd | getline dayline;
|
||||||
|
355
src/main.sh
355
src/main.sh
@ -25,11 +25,6 @@ if [ -z "${FZF_VCAL_USE_EXPORTED:-}" ]; then
|
|||||||
export SYNC_CMD
|
export SYNC_CMD
|
||||||
export COLLECTION_LABELS
|
export COLLECTION_LABELS
|
||||||
|
|
||||||
DAY_START=${DAY_START:-8}
|
|
||||||
DAY_END=${DAY_END:-18}
|
|
||||||
export DAY_START
|
|
||||||
export DAY_END
|
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
if command -v "fzf" >/dev/null; then
|
if command -v "fzf" >/dev/null; then
|
||||||
FZF="fzf"
|
FZF="fzf"
|
||||||
@ -78,52 +73,22 @@ EOF
|
|||||||
)
|
)
|
||||||
export AWK_PARSE
|
export AWK_PARSE
|
||||||
|
|
||||||
|
AWK_WEEKS=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include src/awk/weeks.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_WEEKS
|
||||||
|
|
||||||
AWK_WEEKVIEW=$(
|
AWK_WEEKVIEW=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/weekview.awk
|
@@include src/awk/weekview.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_WEEKVIEW
|
export AWK_WEEKVIEW
|
||||||
|
|
||||||
AWK_DAYVIEW=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/dayview.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_DAYVIEW
|
|
||||||
|
|
||||||
AWK_GET=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/get.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_GET
|
|
||||||
|
|
||||||
AWK_UPDATE=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/update.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_UPDATE
|
|
||||||
|
|
||||||
AWK_NEW=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/new.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_NEW
|
|
||||||
### END OF AWK SCRIPTS
|
### END OF AWK SCRIPTS
|
||||||
|
FZF_VJOUR_USE_EXPORTED="yes"
|
||||||
## Colors
|
export FZF_VJOUR_USE_EXPORTED
|
||||||
export GREEN="\033[1;32m"
|
|
||||||
export RED="\033[1;31m"
|
|
||||||
export WHITE="\033[1;97m"
|
|
||||||
export CYAN="\033[1;36m"
|
|
||||||
export ITALIC="\033[3m"
|
|
||||||
export FAINT="\033[2m"
|
|
||||||
export OFF="\033[m"
|
|
||||||
|
|
||||||
export FZF_VJOUR_USE_EXPORTED="yes"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__load_approx_data() {
|
__load_approx_data() {
|
||||||
@ -135,71 +100,23 @@ __load_approx_data() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__load_weeks() {
|
__load_weeks() {
|
||||||
dates=$(awk -F'|' '{ print $2; print $3 }' "$APPROX_DATA_FILE")
|
dates=$(awk -F'|' '{ print $1; print $2 }' "$APPROX_DATA_FILE")
|
||||||
file_dates=$(mktemp)
|
file_dates=$(mktemp)
|
||||||
echo "$dates" | date --file="/dev/stdin" +"%s" >"$file_dates"
|
echo "$dates" | date --file="/dev/stdin" +"%s" >"$file_dates"
|
||||||
awk "$AWK_MERGE" "$file_dates" "$APPROX_DATA_FILE"
|
awk "$AWK_MERGE" "$file_dates" "$APPROX_DATA_FILE"
|
||||||
rm "$file_dates"
|
rm "$file_dates"
|
||||||
}
|
}
|
||||||
|
|
||||||
__show_day() {
|
|
||||||
weeknr=$(date -d "$DISPLAY_DATE" +"%s")
|
|
||||||
weeknr=$(((weeknr - 259200) / 604800)) # shift, because epoch origin is a Thursday
|
|
||||||
files=$(grep "^$weeknr " "$WEEKLY_DATA_FILE" | cut -d " " -f 2-)
|
|
||||||
# Find relevant files in list of week files
|
|
||||||
sef=$({
|
|
||||||
set -- $files
|
|
||||||
for file in "$@"; do
|
|
||||||
file="$ROOT/$file"
|
|
||||||
awk \
|
|
||||||
-v collection_labels="$COLLECTION_LABELS" \
|
|
||||||
"$AWK_PARSE" "$file"
|
|
||||||
done
|
|
||||||
})
|
|
||||||
if [ -n "$sef" ]; then
|
|
||||||
today=$(date -d "$DISPLAY_DATE" +"%D")
|
|
||||||
sef=$(echo "$sef" | while IFS= read -r line; do
|
|
||||||
set -- $line
|
|
||||||
starttime="$1"
|
|
||||||
shift
|
|
||||||
endtime="$1"
|
|
||||||
shift
|
|
||||||
fpath="$(echo "$1" | sed 's/|/ /g')" # we will use | as delimiter (need to convert back!)
|
|
||||||
shift
|
|
||||||
description="$(echo "$*" | sed 's/|/:/g')" # we will use | as delimiter
|
|
||||||
#
|
|
||||||
daystart=$(date -d "$today 00:00:00" +"%s")
|
|
||||||
dayend=$(date -d "$today 23:59:59" +"%s")
|
|
||||||
line=""
|
|
||||||
if [ "$starttime" -gt "$daystart" ] && [ "$starttime" -lt "$dayend" ]; then
|
|
||||||
s=$(date -d "@$starttime" +"%R")
|
|
||||||
elif [ "$starttime" -le "$daystart" ] && [ "$endtime" -gt "$daystart" ]; then
|
|
||||||
s="00:00"
|
|
||||||
else
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [ "$endtime" -gt "$daystart" ] && [ "$endtime" -lt "$dayend" ]; then
|
|
||||||
e=$(date -d "@$endtime" +"%R")
|
|
||||||
elif [ "$endtime" -ge "$dayend" ] && [ "$starttime" -lt "$dayend" ]; then
|
|
||||||
e="00:00"
|
|
||||||
else
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
echo "$s|$e|$starttime|$endtime|$fpath|$description"
|
|
||||||
done)
|
|
||||||
fi
|
|
||||||
echo "$sef" | sort -n | awk -v daystart="$DAY_START" -v dayend="$DAY_END" "$AWK_DAYVIEW"
|
|
||||||
}
|
|
||||||
|
|
||||||
__list() {
|
__list() {
|
||||||
weeknr=$(date -d "$DISPLAY_DATE" +"%s")
|
weeknr=$(date -d "$DISPLAY_DATE" +"%s")
|
||||||
weeknr=$(((weeknr - 259200) / 604800)) # shift, because epoch origin is a Thursday
|
weeknr=$(((weeknr - 259200) / 604800)) # shift, because epoch origin is a Thursday
|
||||||
files=$(grep "^$weeknr " "$WEEKLY_DATA_FILE" | cut -d " " -f 2-)
|
files=$(grep "^$weeknr " "$WEEKLY_DATA_FILE" | cut -d " " -f 2)
|
||||||
dayofweek=$(date -d "$DISPLAY_DATE" +"%u")
|
dayofweek=$(date -d "$DISPLAY_DATE" +"%u")
|
||||||
delta=$((1 - dayofweek))
|
delta=$((1 - dayofweek))
|
||||||
startofweek=$(date -d "$DISPLAY_DATE -$delta days" +"%D")
|
startofweek=$(date -d "$DISPLAY_DATE -$delta days" +"%D")
|
||||||
# loop over files
|
# loop over files
|
||||||
sef=$({
|
sef=$({
|
||||||
|
IFS=';'
|
||||||
set -- $files
|
set -- $files
|
||||||
for file in "$@"; do
|
for file in "$@"; do
|
||||||
file="$ROOT/$file"
|
file="$ROOT/$file"
|
||||||
@ -215,8 +132,6 @@ __list() {
|
|||||||
shift
|
shift
|
||||||
endtime="$1"
|
endtime="$1"
|
||||||
shift
|
shift
|
||||||
#fpath="$1"
|
|
||||||
shift
|
|
||||||
description="$*"
|
description="$*"
|
||||||
for i in $(seq 0 7); do
|
for i in $(seq 0 7); do
|
||||||
daystart=$(date -d "$startofweek +$i days 00:00:00" +"%s")
|
daystart=$(date -d "$startofweek +$i days 00:00:00" +"%s")
|
||||||
@ -250,217 +165,30 @@ __list() {
|
|||||||
# LC_ALL=c xargs -I {} date -d "{}" +"%a %e %b %Y"
|
# LC_ALL=c xargs -I {} date -d "{}" +"%a %e %b %Y"
|
||||||
}
|
}
|
||||||
|
|
||||||
__canonical_datetime_hm() {
|
if [ -z "${APPROX_DATA_FILE:-}" ]; then
|
||||||
s="$1"
|
echo "GOING TO LOAD"
|
||||||
t=$(date -d "@$s" +"%R")
|
|
||||||
dfmt="%F"
|
|
||||||
if [ "$t" != "00:00" ]; then
|
|
||||||
dfmt="$dfmt %R"
|
|
||||||
fi
|
|
||||||
date -d "@$s" +"$dfmt"
|
|
||||||
}
|
|
||||||
|
|
||||||
__canonical_datetime() {
|
|
||||||
s="$1"
|
|
||||||
shift
|
|
||||||
t=$(date -d "@$s" +"%R")
|
|
||||||
dfmt="$*%e %b %Y"
|
|
||||||
if [ "$t" != "00:00" ]; then
|
|
||||||
dfmt="$dfmt %R %Z"
|
|
||||||
fi
|
|
||||||
date -d "@$s" +"$dfmt"
|
|
||||||
}
|
|
||||||
|
|
||||||
__edit() {
|
|
||||||
start=$(__canonical_datetime_hm "$1")
|
|
||||||
end=$(__canonical_datetime_hm "$2")
|
|
||||||
fpath="$3"
|
|
||||||
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$fpath")
|
|
||||||
description=$(awk -v field="DESCRIPTION" "$AWK_GET" "$fpath")
|
|
||||||
filetmp=$(mktemp --suffix='.md')
|
|
||||||
(
|
|
||||||
echo "::: |> $start"
|
|
||||||
echo "::: <| $end"
|
|
||||||
echo "# $summary"
|
|
||||||
echo ""
|
|
||||||
echo "$description"
|
|
||||||
) >"$filetmp"
|
|
||||||
checksum=$(cksum "$filetmp")
|
|
||||||
$EDITOR "$filetmp" >/dev/tty
|
|
||||||
|
|
||||||
# Update only if changes are detected
|
|
||||||
if [ "$checksum" != "$(cksum "$filetmp")" ]; then
|
|
||||||
filenew="$filetmp.ics"
|
|
||||||
awk "$AWK_UPDATE" "$filetmp" "$fpath" >"$filenew"
|
|
||||||
mv "$filenew" "$fpath"
|
|
||||||
__refresh_data
|
|
||||||
fi
|
|
||||||
rm "$filetmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
__refresh_data() {
|
|
||||||
if [ -n "${APPROX_DATA_FILE:-}" ]; then
|
|
||||||
rm "$APPROX_DATA_FILE"
|
|
||||||
fi
|
|
||||||
if [ -n "${WEEKLY_DATA_FILE:-}" ]; then
|
|
||||||
rm "$WEEKLY_DATA_FILE"
|
|
||||||
fi
|
|
||||||
APPROX_DATA_FILE=$(mktemp)
|
APPROX_DATA_FILE=$(mktemp)
|
||||||
__load_approx_data >"$APPROX_DATA_FILE"
|
__load_approx_data >"$APPROX_DATA_FILE"
|
||||||
export APPROX_DATA_FILE
|
export APPROX_DATA_FILE
|
||||||
|
fi
|
||||||
|
if [ -z "${WEEKLY_DATA_FILE:-}" ]; then
|
||||||
|
echo "GOING TO LOAD WD"
|
||||||
WEEKLY_DATA_FILE=$(mktemp)
|
WEEKLY_DATA_FILE=$(mktemp)
|
||||||
__load_weeks >"$WEEKLY_DATA_FILE"
|
__load_weeks >"$WEEKLY_DATA_FILE"
|
||||||
export WEEKLY_DATA_FILE
|
export WEEKLY_DATA_FILE
|
||||||
}
|
|
||||||
|
|
||||||
if [ -z "${APPROX_DATA_FILE:-}" ]; then
|
|
||||||
__refresh_data
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--help" ]; then
|
|
||||||
echo "Usage: $0 [OPTION]"
|
|
||||||
echo ""
|
|
||||||
echo "You may specify at most one option."
|
|
||||||
echo " --help Show this help and exit"
|
|
||||||
echo " --new Create new entry"
|
|
||||||
echo " --today Show today's appointments"
|
|
||||||
echo " --day <day> Show appointments of specified day"
|
|
||||||
echo " --date <date> Show week of specified date"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--today" ]; then
|
|
||||||
exec $0 --day "today"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--new" ]; then
|
|
||||||
collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
|
||||||
fpath=""
|
|
||||||
while [ -f "$fpath" ] || [ -z "$fpath" ]; do
|
|
||||||
uuid=$($UUIDGEN)
|
|
||||||
fpath="$ROOT/$collection/$uuid.ics"
|
|
||||||
done
|
|
||||||
startsec=$(date -d "$2" +"%s")
|
|
||||||
endsec=$((startsec + 3600))
|
|
||||||
start=$(__canonical_datetime_hm "$startsec")
|
|
||||||
end=$(__canonical_datetime_hm "$endsec")
|
|
||||||
filetmp=$(mktemp --suffix='.md')
|
|
||||||
(
|
|
||||||
echo "::: |> $start"
|
|
||||||
echo "::: <| $end"
|
|
||||||
echo "# <!-- write summary here -->"
|
|
||||||
echo ""
|
|
||||||
) >"$filetmp"
|
|
||||||
checksum=$(cksum "$filetmp")
|
|
||||||
$EDITOR "$filetmp" >/dev/tty
|
|
||||||
|
|
||||||
# Update only if changes are detected
|
|
||||||
if [ "$checksum" != "$(cksum "$filetmp")" ]; then
|
|
||||||
filenew="$filetmp.ics"
|
|
||||||
awk -v uid="$uuid" "$AWK_NEW" "$filetmp" >"$filenew"
|
|
||||||
mv "$filenew" "$fpath"
|
|
||||||
__refresh_data
|
|
||||||
fi
|
|
||||||
rm "$filetmp"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--preview" ]; then
|
|
||||||
hour=$(echo "$2" | cut -d '|' -f 1)
|
|
||||||
start=$(echo "$2" | cut -d '|' -f 2)
|
|
||||||
end=$(echo "$2" | cut -d '|' -f 3)
|
|
||||||
fpath=$(echo "$2" | cut -d '|' -f 4 | sed "s/ /|/g")
|
|
||||||
if [ -n "$hour" ] && [ -n "$fpath" ]; then
|
|
||||||
fpath="$ROOT/$fpath"
|
|
||||||
start=$(__canonical_datetime "$start" "%a ")
|
|
||||||
end=$(__canonical_datetime "$end" "%a ")
|
|
||||||
echo "${GREEN}From: ${OFF}${CYAN}$start${OFF}"
|
|
||||||
echo "${GREEN}To: ${OFF}${CYAN}$end${OFF}"
|
|
||||||
echo ""
|
|
||||||
awk -v field="DESCRIPTION" "$AWK_GET" "$fpath" | $CAT
|
|
||||||
fi
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--delete" ]; then
|
|
||||||
fpath=$(echo "$2" | cut -d '|' -f 4 | sed "s/ /|/g")
|
|
||||||
if [ -n "$fpath" ]; then
|
|
||||||
fpath="$ROOT/$fpath"
|
|
||||||
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$fpath")
|
|
||||||
while true; do
|
|
||||||
printf "Do you want to delete the entry with the title \"%s\"? (yes/no): " "$summary" >/dev/tty
|
|
||||||
read -r yn
|
|
||||||
case $yn in
|
|
||||||
"yes")
|
|
||||||
rm -v "$fpath"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
"no")
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Please answer \"yes\" or \"no\"." >/dev/tty
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
__refresh_data
|
|
||||||
exec $0 --day "$DISPLAY_DATE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${1:-}" = "--day" ]; then
|
|
||||||
DISPLAY_DATE="$2"
|
|
||||||
export DISPLAY_DATE
|
|
||||||
selection=$(
|
|
||||||
__show_day |
|
|
||||||
$FZF \
|
|
||||||
--reverse \
|
|
||||||
--ansi \
|
|
||||||
--no-sort \
|
|
||||||
--no-input \
|
|
||||||
--margin='20%' \
|
|
||||||
--border='double' \
|
|
||||||
--border-label="🗓️ $(date -d "$DISPLAY_DATE" +"%A %e %B %Y")" \
|
|
||||||
--color=label:bold:green \
|
|
||||||
--border-label-pos=3 \
|
|
||||||
--delimiter='|' \
|
|
||||||
--with-nth='{5}' \
|
|
||||||
--accept-nth='1,2,3,4' \
|
|
||||||
--preview="$0 --preview {}" \
|
|
||||||
--expect="ctrl-n,esc,backspace" \
|
|
||||||
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)" \
|
|
||||||
--bind="ctrl-alt-d:become($0 --delete {})"
|
|
||||||
)
|
|
||||||
key=$(echo "$selection" | head -1)
|
|
||||||
line=$(echo "$selection" | tail -1)
|
|
||||||
hour=$(echo "$line" | cut -d '|' -f 1)
|
|
||||||
start=$(echo "$line" | cut -d '|' -f 2)
|
|
||||||
end=$(echo "$line" | cut -d '|' -f 3)
|
|
||||||
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
|
|
||||||
if [ "$key" = "ctrl-n" ]; then
|
|
||||||
if echo "$hour" | grep ":"; then
|
|
||||||
hour="$DAY_START"
|
|
||||||
fi
|
|
||||||
exec $0 --new "$DISPLAY_DATE $hour:00"
|
|
||||||
elif [ -n "$fpath" ]; then
|
|
||||||
fpath="$ROOT/$fpath"
|
|
||||||
__edit "$start" "$end" "$fpath"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
DISPLAY_DATE="today"
|
||||||
if [ "${1:-}" = "--date" ]; then
|
if [ "${1:-}" = "--date" ]; then
|
||||||
DISPLAY_DATE="$2"
|
DISPLAY_DATE="$2"
|
||||||
|
echo "Jumping to date $2!"
|
||||||
fi
|
fi
|
||||||
DISPLAY_DATE=${DISPLAY_DATE:-today}
|
|
||||||
DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D")
|
DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D")
|
||||||
DISPLAY_POS=$((8 - $(date -d "$DISPLAY_DATE" +"%u")))
|
|
||||||
DISPLAY_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D")
|
DISPLAY_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D")
|
||||||
DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D")
|
DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D")
|
||||||
DISPLAY_DATE_PREV_MONTH=$(date -d "$DISPLAY_DATE -1 month" +"%D")
|
|
||||||
DISPLAY_DATE_NEXT_MONTH=$(date -d "$DISPLAY_DATE +1 month" +"%D")
|
|
||||||
|
|
||||||
selection=$(
|
selection=$( (
|
||||||
(
|
cut -d '|' -f 3 "$APPROX_DATA_FILE"
|
||||||
cat "$APPROX_DATA_FILE"
|
|
||||||
yes " " | head -n 50
|
yes " " | head -n 50
|
||||||
__list
|
__list
|
||||||
) |
|
) |
|
||||||
@ -469,40 +197,27 @@ selection=$(
|
|||||||
--no-sort \
|
--no-sort \
|
||||||
--no-hscroll \
|
--no-hscroll \
|
||||||
--ellipsis='' \
|
--ellipsis='' \
|
||||||
--delimiter='|' \
|
|
||||||
--with-nth='{4}' \
|
|
||||||
--accept-nth=1,2 \
|
|
||||||
--no-info \
|
|
||||||
--ansi \
|
--ansi \
|
||||||
--no-clear \
|
--no-clear \
|
||||||
--no-scrollbar \
|
--bind="ctrl-p:become($0 --date '$DISPLAY_DATE_PREV')" \
|
||||||
--expect="ctrl-n" \
|
--bind="ctrl-n:become($0 --date '$DISPLAY_DATE_NEXT')" \
|
||||||
--bind="load:pos($DISPLAY_POS)" \
|
--bind="ctrl-l:become($0)")
|
||||||
--bind="ctrl-u:become($0 --date '$DISPLAY_DATE_PREV')" \
|
|
||||||
--bind="ctrl-d:become($0 --date '$DISPLAY_DATE_NEXT')" \
|
|
||||||
--bind="ctrl-alt-u:become($0 --date '$DISPLAY_DATE_PREV_MONTH')" \
|
|
||||||
--bind="ctrl-alt-d:become($0 --date '$DISPLAY_DATE_NEXT_MONTH')" \
|
|
||||||
--bind="ctrl-l:become($0)"
|
|
||||||
)
|
|
||||||
|
|
||||||
key=$(echo "$selection" | head -1)
|
if [ -z "$selection" ]; then
|
||||||
line=$(echo "$selection" | tail -1)
|
|
||||||
sign=$(echo "$line" | cut -d '|' -f 1)
|
|
||||||
startdate=$(echo "$line" | cut -d '|' -f 2)
|
|
||||||
if [ "$key" = "ctrl-n" ]; then
|
|
||||||
# Add new
|
|
||||||
exec $0 --new "$startdate $DAY_START:00"
|
|
||||||
fi
|
|
||||||
if [ -z "$key" ] && [ -z "$line" ]; then
|
|
||||||
rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE"
|
rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$sign" = "~" ]; then
|
case "$selection" in
|
||||||
exec $0 --date "$startdate"
|
"~"*)
|
||||||
else
|
start=$(echo "$selection" | rev | cut -d';' -f 1 | rev)
|
||||||
exec $0 --day "$startdate"
|
exec $0 --date "$start"
|
||||||
fi
|
;;
|
||||||
|
*)
|
||||||
|
day=$(echo "$selection" | rev | cut -d';' -f 1 | rev)
|
||||||
|
exec $0 --day "$day"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
echo "Going to end..."
|
echo "Going to end..."
|
||||||
echo "$selection"
|
echo "$selection"
|
||||||
echo "STOPPING NOW"
|
echo "STOPPING NOW"
|
||||||
|
Loading…
Reference in New Issue
Block a user