diff --git a/src/awk/parse.awk b/src/awk/parse.awk index 28514fb..020d6e5 100644 --- a/src/awk/parse.awk +++ b/src/awk/parse.awk @@ -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) } diff --git a/src/awk/weekview.awk b/src/awk/weekview.awk index b078561..5f82616 100644 --- a/src/awk/weekview.awk +++ b/src/awk/weekview.awk @@ -14,7 +14,7 @@ BEGIN { /^[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 "+", startofweek " +" $0 " days", "", dayline; } +/^[0-7]$/ && dayline { print "+", startofweek " +" $0-1 " days", "", dayline; } /^[0-7]$/ { cmd = "date -d '" startofweek " +" $0 " days' +\"%a %e %b %Y\""; cmd | getline dayline; diff --git a/src/main.sh b/src/main.sh index 5f5c330..3887b62 100755 --- a/src/main.sh +++ b/src/main.sh @@ -79,6 +79,13 @@ EOF EOF ) export AWK_WEEKVIEW + + AWK_DAYVIEW=$( + cat <<'EOF' +@@include src/awk/dayview.awk +EOF + ) + export AWK_DAYVIEW ### END OF AWK SCRIPTS FZF_VJOUR_USE_EXPORTED="yes" export FZF_VJOUR_USE_EXPORTED @@ -100,6 +107,62 @@ __load_weeks() { 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="$1" + 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" +"%H:%M") + 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" +"%H:%M") + elif [ "$endtime" -ge "$dayend" ] && [ "$starttime" -lt "$dayend" ]; then + e="00:00" + else + continue + fi + echo "$s|$e|$fpath|$description" + done) + fi + GREEN="\033[1;32m" + OFF="\033[m" + echo "|🗓️ $GREEN $(date -d "$DISPLAY_DATE" +"%a %e %b %Y")$OFF" + echo "" + ( + echo "$sef" + seq 8 18 | sort -n + ) | awk "$AWK_DAYVIEW" +} + __list() { weeknr=$(date -d "$DISPLAY_DATE" +"%s") weeknr=$(((weeknr - 259200) / 604800)) # shift, because epoch origin is a Thursday @@ -124,6 +187,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") @@ -169,16 +234,26 @@ if [ -z "${WEEKLY_DATA_FILE:-}" ]; then fi if [ "${1:-}" = "--day" ]; then - DISPLAY_DAY="$2" - echo "Jumping to day $DISPLAY_DAY!" - exit + DISPLAY_DATE="$2" + echo "Jumping to day $DISPLAY_DATE!" + selection=$(__show_day | + $FZF \ + --reverse \ + --ansi \ + --no-sort \ + --no-input \ + --delimiter='|' \ + --with-nth='{2}' \ + --accept-nth='{1}') + fpath="$ROOT/$selection" + echo "$fpath" 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_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D") DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D")