added --new functionality with keybnding
This commit is contained in:
parent
c7f5082671
commit
8824959715
@ -33,36 +33,35 @@ BEGIN {
|
||||
ENDFILE {
|
||||
if (NR == FNR)
|
||||
{
|
||||
# Sanitize input
|
||||
cmd = "date +\"%R\""
|
||||
cmd | getline now
|
||||
close(cmd)
|
||||
# if time is set to 00:00 or right now, assume it's a date
|
||||
# and not a datetime entry.
|
||||
# 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 "\" +\"%R\"";
|
||||
cmd = "date -d \"" from "\" +\"%N\"";
|
||||
cmd | getline t
|
||||
close(cmd)
|
||||
if (t == "00:00" || t == now) {
|
||||
from_type = "DATE"
|
||||
cmd = "date -d \"" from "\" +\"%Y%m%d\"";
|
||||
} else {
|
||||
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 "\" +\"%R\"";
|
||||
cmd = "date -d \"" to "\" +\"%N\"";
|
||||
cmd | getline t
|
||||
close(cmd)
|
||||
if (t == "00:00" || t == now) {
|
||||
to_type = "DATE"
|
||||
cmd = "date -d \"" to "\" +\"%Y%m%d\"";
|
||||
} else {
|
||||
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)
|
||||
|
47
src/main.sh
47
src/main.sh
@ -105,6 +105,13 @@ EOF
|
||||
EOF
|
||||
)
|
||||
export AWK_UPDATE
|
||||
|
||||
AWK_NEW=$(
|
||||
cat <<'EOF'
|
||||
@@include src/awk/new.awk
|
||||
EOF
|
||||
)
|
||||
export AWK_NEW
|
||||
### END OF AWK SCRIPTS
|
||||
|
||||
## Colors
|
||||
@ -302,10 +309,33 @@ if [ -z "${WEEKLY_DATA_FILE:-}" ]; then
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--new" ]; then
|
||||
# todo: implement
|
||||
env >/dev/tty
|
||||
echo "$*" >/dev/tty
|
||||
read -r tmp
|
||||
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"
|
||||
fi
|
||||
rm "$filetmp"
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--preview" ]; then
|
||||
@ -358,8 +388,10 @@ if [ "${1:-}" = "--day" ]; then
|
||||
end=$(echo "$line" | cut -d '|' -f 3)
|
||||
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
|
||||
if [ "$key" = "ctrl-n" ]; then
|
||||
# TODO: Go on add entry for hour
|
||||
echo "Add entry for hour $hour"
|
||||
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"
|
||||
@ -410,8 +442,7 @@ sign=$(echo "$line" | cut -d '|' -f 1)
|
||||
startdate=$(echo "$line" | cut -d '|' -f 2)
|
||||
if [ "$key" = "ctrl-n" ]; then
|
||||
# Add new
|
||||
echo "NOT IMPLEMENTED: Add wrt $line"
|
||||
exit
|
||||
exec $0 --new "$startdate $DAY_START:00"
|
||||
fi
|
||||
if [ -z "$key" ] && [ -z "$line" ]; then
|
||||
rm "$WEEKLY_DATA_FILE" "$APPROX_DATA_FILE"
|
||||
|
Loading…
Reference in New Issue
Block a user