added --new functionality with keybnding

This commit is contained in:
Ämin Baumeler 2025-06-10 14:29:55 +02:00
parent c7f5082671
commit 8824959715
2 changed files with 54 additions and 24 deletions

View File

@ -33,36 +33,35 @@ BEGIN {
ENDFILE { ENDFILE {
if (NR == FNR) if (NR == FNR)
{ {
# Sanitize input # If nanoseconds are not 0, then we assume user enterd "tomorrow" or
cmd = "date +\"%R\"" # something the like, and we make this a date entry, as opposed to a
cmd | getline now # date-time entry.
close(cmd)
# if time is set to 00:00 or right now, assume it's a date
# and not a datetime entry.
from = from ? from : "now" from = from ? from : "now"
cmd = "date -d \"" from "\" +\"%R\""; cmd = "date -d \"" from "\" +\"%N\"";
cmd | getline t cmd | getline t
close(cmd) close(cmd)
if (t == "00:00" || t == now) { t = t + 0
from_type = "DATE" if (t == 0) {
cmd = "date -d \"" from "\" +\"%Y%m%d\"";
} else {
from_type = "DATE-TIME" from_type = "DATE-TIME"
cmd = "date -d \"" from "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d" 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 cmd | getline from
close(cmd) close(cmd)
# #
to = to ? to : "now" to = to ? to : "now"
cmd = "date -d \"" to "\" +\"%R\""; cmd = "date -d \"" to "\" +\"%N\"";
cmd | getline t cmd | getline t
close(cmd) close(cmd)
if (t == "00:00" || t == now) { t = t + 0
to_type = "DATE" if (t == 0) {
cmd = "date -d \"" to "\" +\"%Y%m%d\"";
} else {
to_type = "DATE-TIME" to_type = "DATE-TIME"
cmd = "date -d \"" to "\" +\"@%s\" | xargs date -u +\"%Y%m%dT%H%M00Z\" -d" 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 cmd | getline to
close(cmd) close(cmd)

View File

@ -105,6 +105,13 @@ EOF
EOF EOF
) )
export AWK_UPDATE export AWK_UPDATE
AWK_NEW=$(
cat <<'EOF'
@@include src/awk/new.awk
EOF
)
export AWK_NEW
### END OF AWK SCRIPTS ### END OF AWK SCRIPTS
## Colors ## Colors
@ -302,10 +309,33 @@ if [ -z "${WEEKLY_DATA_FILE:-}" ]; then
fi fi
if [ "${1:-}" = "--new" ]; then if [ "${1:-}" = "--new" ]; then
# todo: implement collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
env >/dev/tty fpath=""
echo "$*" >/dev/tty while [ -f "$fpath" ] || [ -z "$fpath" ]; do
read -r tmp 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"
fi
rm "$filetmp"
fi fi
if [ "${1:-}" = "--preview" ]; then if [ "${1:-}" = "--preview" ]; then
@ -358,8 +388,10 @@ if [ "${1:-}" = "--day" ]; then
end=$(echo "$line" | cut -d '|' -f 3) end=$(echo "$line" | cut -d '|' -f 3)
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g") fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
if [ "$key" = "ctrl-n" ]; then if [ "$key" = "ctrl-n" ]; then
# TODO: Go on add entry for hour if echo "$hour" | grep ":"; then
echo "Add entry for hour $hour" hour="$DAY_START"
fi
exec $0 --new "$DISPLAY_DATE $hour:00"
elif [ -n "$fpath" ]; then elif [ -n "$fpath" ]; then
fpath="$ROOT/$fpath" fpath="$ROOT/$fpath"
__edit "$start" "$end" "$fpath" __edit "$start" "$end" "$fpath"
@ -410,8 +442,7 @@ sign=$(echo "$line" | cut -d '|' -f 1)
startdate=$(echo "$line" | cut -d '|' -f 2) startdate=$(echo "$line" | cut -d '|' -f 2)
if [ "$key" = "ctrl-n" ]; then if [ "$key" = "ctrl-n" ]; then
# Add new # Add new
echo "NOT IMPLEMENTED: Add wrt $line" exec $0 --new "$startdate $DAY_START:00"
exit
fi fi
if [ -z "$key" ] && [ -z "$line" ]; then if [ -z "$key" ] && [ -z "$line" ]; then
rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE" rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE"