feat:change tz from within application

This commit is contained in:
2025-06-13 14:07:44 +02:00
parent 6d8520a016
commit 0ffa57373a

View File

@@ -10,6 +10,8 @@ if [ "${1:-}" = "--help" ]; then
echo "You may specify at most one option." echo "You may specify at most one option."
echo " --help Show this help and exit" echo " --help Show this help and exit"
echo " --today Show today's appointments" echo " --today Show today's appointments"
echo " --yesterday Show yesterday's appointments"
echo " --tomorrow Show tomorrow's appointments"
echo " --goto Interactively enter date to jump to" echo " --goto Interactively enter date to jump to"
echo " --new [date/date-time] Create new entry" echo " --new [date/date-time] Create new entry"
echo " --day [date] Show appointments of specified day" echo " --day [date] Show appointments of specified day"
@@ -376,6 +378,10 @@ fi
### SYNC_CMD (optional): Synchronization command ### SYNC_CMD (optional): Synchronization command
### DAY_START (optional): Hour of start of the day (defaults to 8) ### DAY_START (optional): Hour of start of the day (defaults to 8)
### DAY_END (optional): Hour of end of the day (defaults to 18) ### DAY_END (optional): Hour of end of the day (defaults to 18)
### EDITOR (optional): Your favorite editor, is usually already exported
### TZ (optional): Your favorite timezone, usually system's choice
### LC_TIME (optional): Your favorite locale for date and time
### ZI_DIR (optional): Location of tzdata, defaults to /usr/share/zoneinfo
### ###
CONFIGFILE="$HOME/.config/fzf-vcal/config" CONFIGFILE="$HOME/.config/fzf-vcal/config"
@@ -392,6 +398,11 @@ fi
SYNC_CMD=${SYNC_CMD:-exit} SYNC_CMD=${SYNC_CMD:-exit}
DAY_START=${DAY_START:-8} DAY_START=${DAY_START:-8}
DAY_END=${DAY_END:-18} DAY_END=${DAY_END:-18}
ZI_DIR=${ZI_DIR:-/usr/share/zoneinfo/posix}
if [ ! -d "$ZI_DIR" ]; then
err "Could not determine time-zone information"
exit 1
fi
### ###
### Check and load required tools ### Check and load required tools
@@ -497,9 +508,9 @@ EOF
### ###
#GREEN="\033[1;32m" #GREEN="\033[1;32m"
#RED="\033[1;31m" #RED="\033[1;31m"
#WHITE="\033[1;97m" WHITE="\033[1;97m"
CYAN="\033[1;36m" CYAN="\033[1;36m"
#ITALIC="\033[3m" ITALIC="\033[3m"
#FAINT="\033[2m" #FAINT="\033[2m"
OFF="\033[m" OFF="\033[m"
@@ -725,7 +736,7 @@ __refresh_data
### Exports ### Exports
# The preview calls run in subprocesses. These require the following variables: # The preview calls run in subprocesses. These require the following variables:
export ROOT CAT AWK_GET AWK_CAL CYAN OFF export ROOT CAT AWK_GET AWK_CAL CYAN WHITE ITALIC OFF
# The reload commands also run in subprocesses, and use in addition # The reload commands also run in subprocesses, and use in addition
export COLLECTION_LABELS DAY_START DAY_END AWK_DAYVIEW AWK_WEEKVIEW AWK_PARSE export COLLECTION_LABELS DAY_START DAY_END AWK_DAYVIEW AWK_WEEKVIEW AWK_PARSE
# as well as the following variables that will be dynamically specified. So, we # as well as the following variables that will be dynamically specified. So, we
@@ -735,30 +746,50 @@ export COLLECTION_LABELS DAY_START DAY_END AWK_DAYVIEW AWK_WEEKVIEW AWK_PARSE
# Re-export dynamical variables to subshells. # Re-export dynamical variables to subshells.
__export() { __export() {
export DISPLAY_DATE WEEKLY_DATA_FILE APPROX_DATA_FILE export DISPLAY_DATE WEEKLY_DATA_FILE APPROX_DATA_FILE
if [ -n "${TZ:-}" ]; then
export TZ
fi
} }
### ###
### Main loop with the command-line argument ### Main loop with the command-line argument
### --today ### --today
### --yesterday
### --tomorrow
### --goto ### --goto
### --new <optional date/date-time argument> ### --new <optional date/date-time argument>
### --day <optional date/date-time argument> ### --day <optional date/date-time argument>
### --week <optional date/date-time argument> ### --week <optional date/date-time argument>
### --set-tz
### ###
### The command-line argument defaults to "--week today". ### The command-line argument defaults to "--week today".
while true; do while true; do
export DISPLAY_DATE WEEKLY_DATA_FILE APPROX_DATA_FILE export DISPLAY_DATE WEEKLY_DATA_FILE APPROX_DATA_FILE
if [ -z "${1:-}" ]; then
case "${1:-}" in
--today | --yesterday | --tomorrow | --goto | --new | --day | --week | --set-tz) ;;
*)
DISPLAY_DATE="today" DISPLAY_DATE="today"
set -- "--week" "$DISPLAY_DATE" set -- "--week" "$DISPLAY_DATE"
fi ;;
esac
if [ "$1" = "--today" ]; then if [ "$1" = "--today" ]; then
DISPLAY_DATE="today" DISPLAY_DATE="today"
set -- "--day" "$DISPLAY_DATE" set -- "--day" "$DISPLAY_DATE"
fi fi
if [ "$1" = "--yesterday" ]; then
DISPLAY_DATE="yesterday"
set -- "--day" "$DISPLAY_DATE"
fi
if [ "$1" = "--tomorrow" ]; then
DISPLAY_DATE="tomorrow"
set -- "--day" "$DISPLAY_DATE"
fi
if [ "$1" = "--goto" ]; then if [ "$1" = "--goto" ]; then
DISPLAY_DATE="" DISPLAY_DATE=""
while [ -z "${DISPLAY_DATE:-}" ]; do while [ -z "${DISPLAY_DATE:-}" ]; do
@@ -771,6 +802,16 @@ while true; do
set -- "--day" "$DISPLAY_DATE" set -- "--day" "$DISPLAY_DATE"
fi fi
if [ "$1" = "--set-tz" ]; then
new_tz=$(find "$ZI_DIR" -type f | sed "s|^$ZI_DIR/*||" | $FZF)
if [ -n "$new_tz" ]; then
TZ="$new_tz"
__refresh_data
__export
fi
shift
fi
if [ "${1:-}" = "--new" ]; then if [ "${1:-}" = "--new" ]; then
__new "${2:-}" __new "${2:-}"
if [ -n "$start" ]; then if [ -n "$start" ]; then
@@ -797,13 +838,21 @@ while true; do
--border='double' \ --border='double' \
--color=label:bold:green \ --color=label:bold:green \
--border-label-pos=3 \ --border-label-pos=3 \
--list-border="top" \
--list-label-pos=3 \
--cycle \ --cycle \
--delimiter='|' \ --delimiter='|' \
--with-nth='{6}' \ --with-nth='{6}' \
--accept-nth='1,2,3,4,5' \ --accept-nth='1,2,3,4,5' \
--preview="$0 --preview-event {}" \ --preview="$0 --preview-event {}" \
--expect="ctrl-n,ctrl-alt-d,esc,backspace,q" \ --expect="ctrl-n,ctrl-alt-d,ctrl-t,esc,backspace,q" \
--bind="load:pos(1)+transform(echo change-border-label:🗓️ \$(date -d {1} +\"%A %e %B %Y\"))+transform(echo {} | grep \|\| || echo show-preview)" \ --bind="load:pos(1)+transform(
echo change-border-label:🗓️ \$(date -d {1} +\"%A %e %B %Y\")
)+transform(
[ -n \"\${TZ:-}\" ] && echo \"change-list-label:\$WHITE\$ITALIC(\$TZ)\$OFF\"
)+transform(
echo {} | grep \|\| || echo show-preview
)" \
--bind="start:hide-preview" \ --bind="start:hide-preview" \
--bind="ctrl-r:reload:$0 --reload-day {1}" \ --bind="ctrl-r:reload:$0 --reload-day {1}" \
--bind="ctrl-j:down+hide-preview+transform:echo {} | grep \|\| || echo show-preview" \ --bind="ctrl-j:down+hide-preview+transform:echo {} | grep \|\| || echo show-preview" \
@@ -834,6 +883,8 @@ while true; do
__delete "$fpath" __delete "$fpath"
__refresh_data __refresh_data
set -- "--day" "$DISPLAY_DATE" set -- "--day" "$DISPLAY_DATE"
elif [ "$key" = "ctrl-t" ]; then
set -- "--set-tz" "--day" "$DISPLAY_DATE"
elif [ -z "$key" ] && [ -n "$fpath" ]; then elif [ -z "$key" ] && [ -n "$fpath" ]; then
__edit "$start" "$end" "$fpath" __edit "$start" "$end" "$fpath"
set -- "--day" "$DISPLAY_DATE" set -- "--day" "$DISPLAY_DATE"
@@ -859,10 +910,10 @@ while true; do
--gap 1 \ --gap 1 \
--no-scrollbar \ --no-scrollbar \
--info=right \ --info=right \
--info-command="printf \"$(date +"%R %Z")\"" \ --info-command="printf \"$(date +"%R %Z")\"; [ -n \"\${TZ:-}\" ] && printf \" (\$TZ)\"" \
--preview-window=up,7,border-bottom \ --preview-window=up,7,border-bottom \
--preview="$0 --preview-week {}" \ --preview="$0 --preview-week {}" \
--expect="ctrl-n,ctrl-g" \ --expect="ctrl-n,ctrl-g,ctrl-t" \
--bind="ctrl-j:transform:([ {1} = \"+\" ] && [ \$FZF_POS -le 1 ]) && --bind="ctrl-j:transform:([ {1} = \"+\" ] && [ \$FZF_POS -le 1 ]) &&
echo unbind\(load\)+reload:$0 --reload-week {2} '+1 day'|| echo unbind\(load\)+reload:$0 --reload-week {2} '+1 day'||
echo down" \ echo down" \
@@ -886,16 +937,17 @@ while true; do
line="" line=""
fi fi
sign=$(echo "$line" | cut -d '|' -f 1) sign=$(echo "$line" | cut -d '|' -f 1)
startdate=$(echo "$line" | cut -d '|' -f 2) DISPLAY_DATE=$(echo "$line" | cut -d '|' -f 2)
if [ "$key" = "ctrl-n" ]; then if [ "$key" = "ctrl-n" ]; then
if [ "$sign" = "~" ]; then if [ "$sign" = "~" ]; then
startdate="" DISPLAY_DATE=""
fi fi
set -- "--new" "${startdate:-today} $DAY_START:00" set -- "--new" "${DISPLAY_DATE:-today} $DAY_START:00"
elif [ "$key" = "ctrl-g" ]; then elif [ "$key" = "ctrl-g" ]; then
set -- "--goto" set -- "--goto"
elif [ "$key" = "ctrl-t" ]; then
set -- "--set-tz" "$*"
else else
DISPLAY_DATE="$startdate"
if [ "$sign" = "~" ]; then if [ "$sign" = "~" ]; then
set -- "--week" "$DISPLAY_DATE" set -- "--week" "$DISPLAY_DATE"
else else