diff --git a/src/awk/dayview.awk b/src/awk/dayview.awk index 5b582b4..cb0ab04 100644 --- a/src/awk/dayview.awk +++ b/src/awk/dayview.awk @@ -1,14 +1,16 @@ +# 11:00|13:00|1748422800|1748430000|fpath|desc... +# 00:00|00:00|1748296800|1748383200|fpath|desc... function allday() { - return ITALIC FAINT " (allday) " OFF $4 + return ITALIC FAINT " (allday) " OFF $6 } function endstoday() { - return CYAN " -- " $2 OFF ": " $4 + return CYAN " -- " $2 OFF ": " $6 } function slice() { if ($2 == "00:00") - return CYAN $1 " -- " OFF ": " $4 + return CYAN $1 " -- " OFF ": " $6 else - return CYAN $1 OFF " -- " CYAN $2 OFF ": " $4 + return CYAN $1 OFF " -- " CYAN $2 OFF ": " $6 } BEGIN { FS = "|"; @@ -21,8 +23,8 @@ BEGIN { OFF = "\033[m"; OFS = "|" } -/^[0-9]+$/ && hour { print hour, FAINT hour ":00 ----------------------" OFF } +/^[0-9]+$/ && hour { print hour, "", "", "", FAINT hour ":00 ----------------------" OFF } /^[0-9]+$/ { hour = $1 < 10 ? "0"$1 : $1; next } -$1 == hour":00" { print $3, slice(); unset hour; next } -$1 == "00:00" && $2 == "00:00" { print $3, allday(); next } -$1 == "00:00" { print $3, endstoday();next } +$1 == hour":00" { print $1, $3, $4, $5, slice(); unset hour; next } +$1 == "00:00" && $2 == "00:00" { print $1, $3, $4, $5, allday(); next } +$1 == "00:00" { print $1, $3, $4, $5, endstoday();next } diff --git a/src/awk/preview.awk b/src/awk/preview.awk new file mode 100644 index 0000000..a12f89c --- /dev/null +++ b/src/awk/preview.awk @@ -0,0 +1,18 @@ +# print content of field `field` +BEGIN { FS = ":"; regex = "^" field; } +/^BEGIN:VEVENT$/ { inside = 1 } +/^END:VEVENT/ && inside { exit } +$0 ~ field { content = $0; next; } +/^ / && content { content = content substr($0, 2); next; } +/^[^ ]/ && content { exit } +END { + if (!type) { 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; +} diff --git a/src/main.sh b/src/main.sh index bfe7cd5..788e84c 100755 --- a/src/main.sh +++ b/src/main.sh @@ -83,6 +83,13 @@ EOF AWK_DAYVIEW=$( cat <<'EOF' @@include src/awk/dayview.awk +EOF + ) + export AWK_DAYVIEW + + AWK_PREVIEW=$( + cat <<'EOF' +@@include src/awk/preview.awk EOF ) export AWK_DAYVIEW @@ -129,38 +136,38 @@ __show_day() { shift endtime="$1" shift - fpath="$1" + 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 + 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") + 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" +"%H:%M") + e=$(date -d "@$endtime" +"%R") elif [ "$endtime" -ge "$dayend" ] && [ "$starttime" -lt "$dayend" ]; then e="00:00" else continue fi - echo "$s|$e|$fpath|$description" + echo "$s|$e|$starttime|$endtime|$fpath|$description" done) fi GREEN="\033[1;32m" OFF="\033[m" - echo "|🗓️ $GREEN $(date -d "$DISPLAY_DATE" +"%a %e %b %Y")$OFF" + echo "||||🗓️ $GREEN $(date -d "$DISPLAY_DATE" +"%a %e %b %Y")$OFF" echo "" ( echo "$sef" - seq 8 18 | sort -n - ) | awk "$AWK_DAYVIEW" + seq 8 18 + ) | sort -n | awk "$AWK_DAYVIEW" } __list() { @@ -233,6 +240,32 @@ if [ -z "${WEEKLY_DATA_FILE:-}" ]; then export WEEKLY_DATA_FILE 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" + timestart=$(date -d "@$start" +"%R") + timeend=$(date -d "@$end" +"%R") + dfmt="%a %e %b %Y" + if [ "$timestart" != "00:00" ]; then + dfmt="$dfmt %Y %R %Z" + fi + start=$(date -d "@$start" +"$dfmt") + dfmt="%a %e %b %Y" + if [ "$timeend" != "00:00" ]; then + dfmt="$dfmt %Y %R %Z" + fi + end=$(date -d "@$end" +"$dfmt") + echo "START @ $start, END @ $end" + fi + #awk -v field="DESCRIPTION" "$AWK_PREVIEW" "$fpath" | + # $CAT + exit +fi + if [ "${1:-}" = "--day" ]; then DISPLAY_DATE="$2" echo "Jumping to day $DISPLAY_DATE!" @@ -244,13 +277,22 @@ if [ "${1:-}" = "--day" ]; then --no-sort \ --no-input \ --delimiter='|' \ - --with-nth='{2}' \ - --accept-nth='{1}' \ + --with-nth='{5}' \ + --accept-nth='1,2,3,4' \ + --preview="$0 --preview {}" \ --bind="backspace:first+accept" ) - if [ -n "$selection" ]; then - fpath="$ROOT/$selection" - fi + hour=$(echo "$selection" | cut -d '|' -f 1) + start=$(echo "$selection" | cut -d '|' -f 2) + end=$(echo "$selection" | cut -d '|' -f 3) + fpath=$(echo "$selection" | cut -d '|' -f 4 | sed "s/ /|/g") + if [ -n "$fpath" ]; then + fpath="$ROOT/$fpath" + # TODO: Go on edit file + elif [ -n "$hour" ]; then + # TODO Go on add entry for hour + echo "Add entry for hour $hour" + fi # Else: continue fi if [ "${1:-}" = "--date" ]; then