general improvements in prog flow

This commit is contained in:
Ämin Baumeler 2025-06-11 09:56:31 +02:00
parent 3a95c1e162
commit 5ebcc4feb6

View File

@ -32,7 +32,7 @@ if [ -z "${FZF_VCAL_USE_EXPORTED:-}" ]; then
# Tools # Tools
if command -v "fzf" >/dev/null; then if command -v "fzf" >/dev/null; then
FZF="fzf" FZF="fzf --black"
else else
err "Did not find the command-line fuzzy finder fzf." err "Did not find the command-line fuzzy finder fzf."
exit 1 exit 1
@ -320,10 +320,7 @@ __refresh_data() {
export WEEKLY_DATA_FILE export WEEKLY_DATA_FILE
} }
if [ -z "${APPROX_DATA_FILE:-}" ]; then ## Start
__refresh_data
fi
if [ "${1:-}" = "--help" ]; then if [ "${1:-}" = "--help" ]; then
echo "Usage: $0 [OPTION]" echo "Usage: $0 [OPTION]"
echo "" echo ""
@ -347,7 +344,7 @@ if [ "${1:-}" = "--new" ]; then
uuid=$($UUIDGEN) uuid=$($UUIDGEN)
fpath="$ROOT/$collection/$uuid.ics" fpath="$ROOT/$collection/$uuid.ics"
done done
startsec=$(date -d "$2" +"%s") startsec=$(date -d "${2:-today 8:00}" +"%s")
endsec=$((startsec + 3600)) endsec=$((startsec + 3600))
start=$(__canonical_datetime_hm "$startsec") start=$(__canonical_datetime_hm "$startsec")
end=$(__canonical_datetime_hm "$endsec") end=$(__canonical_datetime_hm "$endsec")
@ -371,6 +368,58 @@ if [ "${1:-}" = "--new" ]; then
rm "$filetmp" rm "$filetmp"
fi fi
if [ -z "${APPROX_DATA_FILE:-}" ]; then
__refresh_data
fi
if [ "${1:-}" = "--day" ]; then
DISPLAY_DATE="${2:-today}"
export DISPLAY_DATE
selection=$(
__show_day |
$FZF \
--reverse \
--ansi \
--no-sort \
--no-input \
--margin='20%' \
--border='double' \
--border-label="🗓️ $(date -d "$DISPLAY_DATE" +"%A %e %B %Y")" \
--color=label:bold:green \
--border-label-pos=3 \
--cycle \
--delimiter='|' \
--with-nth='{5}' \
--accept-nth='1,2,3,4' \
--preview="$0 --preview {}" \
--expect="ctrl-n,esc,backspace,q" \
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)" \
--bind="ctrl-alt-d:become($0 --delete {})"
)
key=$(echo "$selection" | head -1)
line=$(echo "$selection" | tail -1)
if [ "$line" = "$key" ]; then
line=""
fi
hour=$(echo "$line" | cut -d '|' -f 1)
start=$(echo "$line" | cut -d '|' -f 2)
end=$(echo "$line" | cut -d '|' -f 3)
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
if [ "$key" = "ctrl-n" ]; then
if echo "$hour" | grep ":"; then
hour="$DAY_START"
fi
exec $0 --new "$DISPLAY_DATE $hour:00"
elif [ -z "$key" ] && [ -n "$fpath" ]; then
fpath="$ROOT/$fpath"
__edit "$start" "$end" "$fpath"
fi
fi
if [ "${1:-}" = "--date" ]; then
DISPLAY_DATE="$2"
fi
if [ "${1:-}" = "--preview" ]; then if [ "${1:-}" = "--preview" ]; then
hour=$(echo "$2" | cut -d '|' -f 1) hour=$(echo "$2" | cut -d '|' -f 1)
start=$(echo "$2" | cut -d '|' -f 2) start=$(echo "$2" | cut -d '|' -f 2)
@ -462,67 +511,26 @@ if [ "${1:-}" = "--delete" ]; then
exec $0 --day "$DISPLAY_DATE" exec $0 --day "$DISPLAY_DATE"
fi fi
if [ "${1:-}" = "--day" ]; then if [ "${1:-}" = "--all" ]; then
DISPLAY_DATE="$2" cat "$APPROX_DATA_FILE"
export DISPLAY_DATE exit
selection=$(
__show_day |
$FZF \
--reverse \
--ansi \
--no-sort \
--no-input \
--margin='20%' \
--border='double' \
--border-label="🗓️ $(date -d "$DISPLAY_DATE" +"%A %e %B %Y")" \
--color=label:bold:green \
--border-label-pos=3 \
--cycle \
--delimiter='|' \
--with-nth='{5}' \
--accept-nth='1,2,3,4' \
--preview="$0 --preview {}" \
--expect="ctrl-n,esc,backspace,q" \
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)" \
--bind="ctrl-alt-d:become($0 --delete {})"
)
key=$(echo "$selection" | head -1)
line=$(echo "$selection" | tail -1)
if [ "$line" = "$key" ]; then
line=""
fi
hour=$(echo "$line" | cut -d '|' -f 1)
start=$(echo "$line" | cut -d '|' -f 2)
end=$(echo "$line" | cut -d '|' -f 3)
fpath=$(echo "$line" | cut -d '|' -f 4 | sed "s/ /|/g")
if [ "$key" = "ctrl-n" ]; then
if echo "$hour" | grep ":"; then
hour="$DAY_START"
fi
exec $0 --new "$DISPLAY_DATE $hour:00"
elif [ -z "$key" ] && [ -n "$fpath" ]; then
fpath="$ROOT/$fpath"
__edit "$start" "$end" "$fpath"
fi
fi fi
if [ "${1:-}" = "--date" ]; then
DISPLAY_DATE="$2"
fi
DISPLAY_DATE=${DISPLAY_DATE:-today} DISPLAY_DATE=${DISPLAY_DATE:-today}
DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D") DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D")
if [ "${1:-}" = "--list" ]; then
__list
exit
fi
DISPLAY_POS=$((8 - $(date -d "$DISPLAY_DATE" +"%u"))) DISPLAY_POS=$((8 - $(date -d "$DISPLAY_DATE" +"%u")))
DISPLAY_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D") DISPLAY_DATE_PREV=$(date -d "$DISPLAY_DATE -1 week" +"%D")
DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D") DISPLAY_DATE_NEXT=$(date -d "$DISPLAY_DATE +1 week" +"%D")
DISPLAY_DATE_PREV_MONTH=$(date -d "$DISPLAY_DATE -1 month" +"%D") DISPLAY_DATE_PREV_MONTH=$(date -d "$DISPLAY_DATE -1 month" +"%D")
DISPLAY_DATE_NEXT_MONTH=$(date -d "$DISPLAY_DATE +1 month" +"%D") DISPLAY_DATE_NEXT_MONTH=$(date -d "$DISPLAY_DATE +1 month" +"%D")
selection=$( selection=$(
( __list |
cat "$APPROX_DATA_FILE"
yes " " | head -n 50
__list
) |
$FZF \ $FZF \
--tac \ --tac \
--no-sort \ --no-sort \
@ -538,6 +546,8 @@ selection=$(
--preview-window=up,7,border-bottom \ --preview-window=up,7,border-bottom \
--preview="$0 --preview-week {}" \ --preview="$0 --preview-week {}" \
--expect="ctrl-n" \ --expect="ctrl-n" \
--bind="change:reload($0 --all)+hide-preview" \
--bind="backward-eof:reload($0 --list)+show-preview" \
--bind="load:pos($DISPLAY_POS)" \ --bind="load:pos($DISPLAY_POS)" \
--bind="ctrl-u:become($0 --date '$DISPLAY_DATE_PREV')" \ --bind="ctrl-u:become($0 --date '$DISPLAY_DATE_PREV')" \
--bind="ctrl-d:become($0 --date '$DISPLAY_DATE_NEXT')" \ --bind="ctrl-d:become($0 --date '$DISPLAY_DATE_NEXT')" \