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
if command -v "fzf" >/dev/null; then
FZF="fzf"
FZF="fzf --black"
else
err "Did not find the command-line fuzzy finder fzf."
exit 1
@ -320,10 +320,7 @@ __refresh_data() {
export WEEKLY_DATA_FILE
}
if [ -z "${APPROX_DATA_FILE:-}" ]; then
__refresh_data
fi
## Start
if [ "${1:-}" = "--help" ]; then
echo "Usage: $0 [OPTION]"
echo ""
@ -347,7 +344,7 @@ if [ "${1:-}" = "--new" ]; then
uuid=$($UUIDGEN)
fpath="$ROOT/$collection/$uuid.ics"
done
startsec=$(date -d "$2" +"%s")
startsec=$(date -d "${2:-today 8:00}" +"%s")
endsec=$((startsec + 3600))
start=$(__canonical_datetime_hm "$startsec")
end=$(__canonical_datetime_hm "$endsec")
@ -371,6 +368,58 @@ if [ "${1:-}" = "--new" ]; then
rm "$filetmp"
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
hour=$(echo "$2" | cut -d '|' -f 1)
start=$(echo "$2" | cut -d '|' -f 2)
@ -462,67 +511,26 @@ if [ "${1:-}" = "--delete" ]; then
exec $0 --day "$DISPLAY_DATE"
fi
if [ "${1:-}" = "--day" ]; then
DISPLAY_DATE="$2"
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
if [ "${1:-}" = "--all" ]; then
cat "$APPROX_DATA_FILE"
exit
fi
if [ "${1:-}" = "--date" ]; then
DISPLAY_DATE="$2"
fi
DISPLAY_DATE=${DISPLAY_DATE:-today}
DISPLAY_DATE=$(date -d "$DISPLAY_DATE" +"%D")
if [ "${1:-}" = "--list" ]; then
__list
exit
fi
DISPLAY_POS=$((8 - $(date -d "$DISPLAY_DATE" +"%u")))
DISPLAY_DATE_PREV=$(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_NEXT_MONTH=$(date -d "$DISPLAY_DATE +1 month" +"%D")
selection=$(
(
cat "$APPROX_DATA_FILE"
yes " " | head -n 50
__list
) |
__list |
$FZF \
--tac \
--no-sort \
@ -538,6 +546,8 @@ selection=$(
--preview-window=up,7,border-bottom \
--preview="$0 --preview-week {}" \
--expect="ctrl-n" \
--bind="change:reload($0 --all)+hide-preview" \
--bind="backward-eof:reload($0 --list)+show-preview" \
--bind="load:pos($DISPLAY_POS)" \
--bind="ctrl-u:become($0 --date '$DISPLAY_DATE_PREV')" \
--bind="ctrl-d:become($0 --date '$DISPLAY_DATE_NEXT')" \