Compare commits

...

23 Commits

Author SHA1 Message Date
7a22f73d36 added new new 2025-06-10 14:54:48 +02:00
a32507a7fb improved manouvering 2025-06-10 14:54:36 +02:00
12bde0fa39 better loading 2025-06-10 14:51:43 +02:00
5d8b913d78 delete functionality 2025-06-10 14:37:07 +02:00
8824959715 added --new functionality with keybnding 2025-06-10 14:29:55 +02:00
c7f5082671 added expect 2025-06-10 13:56:27 +02:00
cf19b724ea better keys 2025-06-10 13:30:41 +02:00
6e2df59c93 imporved fzf dayview info 2025-06-10 13:28:11 +02:00
f85e766a5a better fzf 2025-06-10 13:26:01 +02:00
af5356f07b configurable start and end of day 2025-06-10 13:13:43 +02:00
54b10ad726 clead awk script a bit 2025-06-10 13:08:45 +02:00
5586619abf fix day view 2025-06-10 13:06:00 +02:00
801108c70c update functionality 2025-06-09 22:13:22 +02:00
7ea35e539e canonical datetime and some todos 2025-06-09 21:07:58 +02:00
7e9ab45492 layout 2025-06-06 15:59:50 +02:00
3961234b12 fixes 2025-06-06 15:48:47 +02:00
b5682bf435 preview 2025-06-06 10:54:38 +02:00
1fd35de475 some initial previewk lots ofs fixes 2025-06-06 10:44:21 +02:00
19c65d7ce1 improved dayview 2025-06-05 23:02:35 +02:00
e5134fd0a0 improved 2025-06-05 23:02:25 +02:00
558f8330ca switch to day view 2025-06-05 22:56:03 +02:00
08adcd2f98 hook for day view 2025-06-05 20:11:27 +02:00
aaf3c56565 cleand and with-nth 2025-06-05 20:05:58 +02:00
9 changed files with 604 additions and 58 deletions

47
src/awk/dayview.awk Normal file
View File

@ -0,0 +1,47 @@
# 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)
}

18
src/awk/get.awk Normal file
View File

@ -0,0 +1,18 @@
# 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;
}

View File

@ -48,7 +48,7 @@ function title(start, summary) {
depth = split(FILENAME, path, "/");
collection = depth > 1 ? path[depth-1] : "";
collection = collection in collection2label ? collection2label[collection] : collection;
return FAINT "~ " collection " " gensub(/^[^0-9]*([0-9]{4})([0-9]{2}).*$/, "\\1-\\2", "1", start) " " summary " ;" start OFF
return FAINT "~ " collection " " gensub(/^[^0-9]*([0-9]{4})([0-9]{2}).*$/, "\\1-\\2", "1", start) " " summary OFF
}
BEGIN {
@ -69,7 +69,7 @@ BEGIN {
OFF = "\033[m";
}
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) }
/^DTEND/ && inside { end = parse( dt) }
/^DURATION/ && inside { end = parse_duration( dt, dta, i, n, a, seps); dur = 1 }

View File

@ -11,7 +11,7 @@ NR == FNR {
if (from[FNR] > to[FNR])
print "FNR", FNR, ":", from[FNR],"-",to[FNR], " ",$0;
for(i=from[FNR]; i<=to[FNR]; i++) {
week[i] = week[i] ? week[i] ";" $4 : $4
week[i] = week[i] " " $5
}
}
END { for (i in week) print i, week[i]; }
END { for (i in week) print i week[i]; }

99
src/awk/new.awk Normal file
View File

@ -0,0 +1,99 @@
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"
}

View File

@ -38,8 +38,10 @@ function print_data(start, dur, end, summary, cmd, collection) {
gsub("\\\\;", ";", summary);
gsub("\\\\\\\\", "\\", summary);
depth = split(FILENAME, path, "/");
fpath = path[depth-1] "/" path[depth]
collection = depth > 1 ? path[depth-1] : "";
collection = collection in collection2label ? collection2label[collection] : collection;
collection = collection2label[path[depth-1]]
end = dur ? start " " end : end
cmd = "date -d '" start "' +\"%s\""
cmd | getline start
@ -47,7 +49,7 @@ function print_data(start, dur, end, summary, cmd, collection) {
cmd = "date -d '" end "' +\"%s\""
cmd | getline end
close(cmd)
print start, end, collection, summary
print start, end, fpath, collection, summary
}
BEGIN {
@ -58,13 +60,6 @@ BEGIN {
split(mapping[map], m, "=");
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 }
/^DTSTART/ && inside { start = parse( dt) }

101
src/awk/update.awk Normal file
View File

@ -0,0 +1,101 @@
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 }

View File

@ -8,12 +8,13 @@ BEGIN {
CYAN = "\033[1;36m";
FAINT = "\033[2m";
OFF = "\033[m";
OFS = "|"
}
/^[0-7] 00:00 -- 00:00/ { dayline = dayline " " 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} -- [0-9]{2}:[0-9]{2}/ { dayline = dayline " " $2 " - " $4 " " c(); next }
/^[0-7]$/ && dayline { print dayline " ;" startofweek " +" $0 " days"; }
/^[0-7]$/ && dayline { print "+", startofweek " +" $0-1 " days", "", dayline; }
/^[0-7]$/ {
cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\"";
cmd | getline dayline;

View File

@ -25,6 +25,11 @@ if [ -z "${FZF_VCAL_USE_EXPORTED:-}" ]; then
export SYNC_CMD
export COLLECTION_LABELS
DAY_START=${DAY_START:-8}
DAY_END=${DAY_END:-18}
export DAY_START
export DAY_END
# Tools
if command -v "fzf" >/dev/null; then
FZF="fzf"
@ -73,22 +78,52 @@ EOF
)
export AWK_PARSE
AWK_WEEKS=$(
cat <<'EOF'
@@include src/awk/weeks.awk
EOF
)
export AWK_WEEKS
AWK_WEEKVIEW=$(
cat <<'EOF'
@@include src/awk/weekview.awk
EOF
)
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
FZF_VJOUR_USE_EXPORTED="yes"
export FZF_VJOUR_USE_EXPORTED
## Colors
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
__load_approx_data() {
@ -100,23 +135,71 @@ __load_approx_data() {
}
__load_weeks() {
dates=$(awk -F'|' '{ print $1; print $2 }' "$APPROX_DATA_FILE")
dates=$(awk -F'|' '{ print $2; print $3 }' "$APPROX_DATA_FILE")
file_dates=$(mktemp)
echo "$dates" | date --file="/dev/stdin" +"%s" >"$file_dates"
awk "$AWK_MERGE" "$file_dates" "$APPROX_DATA_FILE"
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() {
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)
files=$(grep "^$weeknr " "$WEEKLY_DATA_FILE" | cut -d " " -f 2-)
dayofweek=$(date -d "$DISPLAY_DATE" +"%u")
delta=$((1 - dayofweek))
startofweek=$(date -d "$DISPLAY_DATE -$delta days" +"%D")
# loop over files
sef=$({
IFS=';'
set -- $files
for file in "$@"; do
file="$ROOT/$file"
@ -132,6 +215,8 @@ __list() {
shift
endtime="$1"
shift
#fpath="$1"
shift
description="$*"
for i in $(seq 0 7); do
daystart=$(date -d "$startofweek +$i days 00:00:00" +"%s")
@ -165,59 +250,259 @@ __list() {
# LC_ALL=c xargs -I {} date -d "{}" +"%a %e %b %Y"
}
if [ -z "${APPROX_DATA_FILE:-}" ]; then
echo "GOING TO LOAD"
__canonical_datetime_hm() {
s="$1"
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)
__load_approx_data >"$APPROX_DATA_FILE"
export APPROX_DATA_FILE
fi
if [ -z "${WEEKLY_DATA_FILE:-}" ]; then
echo "GOING TO LOAD WD"
WEEKLY_DATA_FILE=$(mktemp)
__load_weeks >"$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
DISPLAY_DATE="today"
if [ "${1:-}" = "--date" ]; then
DISPLAY_DATE="$2"
echo "Jumping to date $2!"
fi
DISPLAY_DATE=${DISPLAY_DATE:-today}
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_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=$( (
cut -d '|' -f 3 "$APPROX_DATA_FILE"
yes " " | head -n 50
__list
) |
$FZF \
--tac \
--no-sort \
--no-hscroll \
--ellipsis='' \
--ansi \
--no-clear \
--bind="ctrl-p:become($0 --date '$DISPLAY_DATE_PREV')" \
--bind="ctrl-n:become($0 --date '$DISPLAY_DATE_NEXT')" \
--bind="ctrl-l:become($0)")
selection=$(
(
cat "$APPROX_DATA_FILE"
yes " " | head -n 50
__list
) |
$FZF \
--tac \
--no-sort \
--no-hscroll \
--ellipsis='' \
--delimiter='|' \
--with-nth='{4}' \
--accept-nth=1,2 \
--no-info \
--ansi \
--no-clear \
--no-scrollbar \
--expect="ctrl-n" \
--bind="load:pos($DISPLAY_POS)" \
--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)"
)
if [ -z "$selection" ]; then
key=$(echo "$selection" | head -1)
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"
return 0
fi
case "$selection" in
"~"*)
start=$(echo "$selection" | rev | cut -d';' -f 1 | rev)
exec $0 --date "$start"
;;
*)
day=$(echo "$selection" | rev | cut -d';' -f 1 | rev)
exec $0 --day "$day"
;;
esac
if [ "$sign" = "~" ]; then
exec $0 --date "$startdate"
else
exec $0 --day "$startdate"
fi
echo "Going to end..."
echo "$selection"
echo "STOPPING NOW"