canonical datetime and some todos
This commit is contained in:
parent
7e9ab45492
commit
7ea35e539e
69
src/main.sh
69
src/main.sh
@ -236,6 +236,47 @@ __list() {
|
||||
# LC_ALL=c xargs -I {} date -d "{}" +"%a %e %b %Y"
|
||||
}
|
||||
|
||||
__canonical_datetime() {
|
||||
s="$1"
|
||||
shift
|
||||
t=$(date -d "@$s" +"%R")
|
||||
dfmt="$*%e %b %Y"
|
||||
if [ "$t" != "00:00" ]; then
|
||||
dfmt="$dfmt %Y %R %Z"
|
||||
fi
|
||||
date -d "@$s" +"$dfmt"
|
||||
}
|
||||
|
||||
__edit() {
|
||||
start=$(__canonical_datetime "$1")
|
||||
end=$(__canonical_datetime "$2")
|
||||
fpath="$3"
|
||||
# Use $start $end and $fpath
|
||||
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
|
||||
# TODO: finish implementation
|
||||
echo "going to update..."
|
||||
read -r tmp
|
||||
#file_new="$filetmp.ics"
|
||||
#awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
|
||||
#mv "$file_new" "$file"
|
||||
fi
|
||||
rm "$filetmp"
|
||||
}
|
||||
|
||||
if [ -z "${APPROX_DATA_FILE:-}" ]; then
|
||||
APPROX_DATA_FILE=$(mktemp)
|
||||
__load_approx_data >"$APPROX_DATA_FILE"
|
||||
@ -247,6 +288,13 @@ if [ -z "${WEEKLY_DATA_FILE:-}" ]; then
|
||||
export WEEKLY_DATA_FILE
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--new" ]; then
|
||||
# todo: implement
|
||||
env >/dev/tty
|
||||
echo "$*" >/dev/tty
|
||||
read -r tmp
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--preview" ]; then
|
||||
hour=$(echo "$2" | cut -d '|' -f 1)
|
||||
start=$(echo "$2" | cut -d '|' -f 2)
|
||||
@ -254,18 +302,8 @@ if [ "${1:-}" = "--preview" ]; then
|
||||
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")
|
||||
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 ""
|
||||
@ -293,7 +331,9 @@ if [ "${1:-}" = "--day" ]; then
|
||||
--with-nth='{5}' \
|
||||
--accept-nth='1,2,3,4' \
|
||||
--preview="$0 --preview {}" \
|
||||
--bind="backspace:first+accept"
|
||||
--bind="backspace:first+accept" \
|
||||
--bind="ctrl-n:become($0 --new ${FZF_NTH:-})" \
|
||||
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)"
|
||||
)
|
||||
hour=$(echo "$selection" | cut -d '|' -f 1)
|
||||
start=$(echo "$selection" | cut -d '|' -f 2)
|
||||
@ -302,8 +342,9 @@ if [ "${1:-}" = "--day" ]; then
|
||||
if [ -n "$fpath" ]; then
|
||||
fpath="$ROOT/$fpath"
|
||||
# TODO: Go on edit file
|
||||
__edit "$start" "$end" "$fpath"
|
||||
elif [ -n "$hour" ]; then
|
||||
# TODO Go on add entry for hour
|
||||
# TODO: Go on add entry for hour
|
||||
echo "Add entry for hour $hour"
|
||||
fi # Else: continue
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user