✨ feat(form): let callers preselect a fallback timezone

- ✨ an offline install has no geo guess, so the timezone list opened on Africa/Abidjan; a caller-supplied zone now stands in for the missing guess
- ✅ a successful geo guess still outranks the fallback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SdXqTwm63rRMwotZ1xqLC8
This commit is contained in:
Kros DaiandClaude Opus 5.5 committed 2026-10-06 22:14:56 -04:00
1 parent 3e00a48c00
commit d53b24cfc7
2 files changed
+18 -2

No files matched your search

+4 -1
View File
@@ -167,10 +167,13 @@ omarchy_prompt_hostname() {
} }
# A fresh machine often hasn't joined a network yet, so the geo guess fails # A fresh machine often hasn't joined a network yet, so the geo guess fails
# often; guard it or a `set -e` caller dies before the filter fallback. # often; guard it or a `set -e` caller dies before the filter fallback. Callers
# may pass the zone to preselect when there is no guess (a region's default),
# so an offline install does not open on the top of an alphabetical list.
omarchy_prompt_timezone() { omarchy_prompt_timezone() {
local guess status local guess status
guess=$(tzupdate -p 2>/dev/null) || guess="" guess=$(tzupdate -p 2>/dev/null) || guess=""
[[ -n $guess ]] || guess="${1:-}"
if [[ -n $guess ]]; then if [[ -n $guess ]]; then
timezone=$(timedatectl list-timezones | gum choose --height 10 --selected "$guess" --header "Timezone") && status=0 || status=$? timezone=$(timedatectl list-timezones | gum choose --height 10 --selected "$guess" --header "Timezone") && status=0 || status=$?
+14 -1
View File
@@ -59,7 +59,7 @@ fi
trap 'if [[ ${FUNCNAME[0]:-} == "$PROMPT_FN" ]]; then printf "returned\n" >>"$MARKER"; fi' RETURN trap 'if [[ ${FUNCNAME[0]:-} == "$PROMPT_FN" ]]; then printf "returned\n" >>"$MARKER"; fi' RETURN
"$PROMPT_FN" "$PROMPT_FN" ${PROMPT_ARG:+"$PROMPT_ARG"}
printf 'keyboard=%s\n' "${keyboard:-}" printf 'keyboard=%s\n' "${keyboard:-}"
printf 'keyboard_label=%s\n' "${keyboard_label:-}" printf 'keyboard_label=%s\n' "${keyboard_label:-}"
@@ -225,6 +225,19 @@ assert_status 0 "timezone prompt survives a failed geo guess"
[[ $(head -n 1 "$GUM_ARGS") == filter* ]] || fail "timezone prompt filters when there is no geo guess" [[ $(head -n 1 "$GUM_ARGS") == filter* ]] || fail "timezone prompt filters when there is no geo guess"
pass "timezone prompt falls back to filtering when the geo guess fails" pass "timezone prompt falls back to filtering when the geo guess fails"
# A region's default stands in for the missing guess, so an offline China
# install opens on Asia/Shanghai instead of the top of the list
PROMPT_ARG=Asia/Shanghai run_prompt omarchy_prompt_timezone "0:Asia/Shanghai"
assert_status 0 "timezone prompt accepts the caller's fallback"
[[ $(field timezone) == "Asia/Shanghai" ]] || fail "timezone prompt keeps the preselected fallback"
grep -qF -- '--selected Asia/Shanghai' "$GUM_ARGS" || fail "timezone prompt preselects the caller's fallback"
[[ $(head -n 1 "$GUM_ARGS") == choose* ]] || fail "timezone prompt chooses from the list when it has a fallback"
pass "timezone prompt preselects the caller's fallback when the geo guess fails"
TZ_GUESS=Europe/Copenhagen PROMPT_ARG=Asia/Shanghai run_prompt omarchy_prompt_timezone "0:Europe/Copenhagen"
grep -qF -- '--selected Europe/Copenhagen' "$GUM_ARGS" || fail "a geo guess outranks the caller's fallback"
pass "timezone prompt prefers the geo guess over the caller's fallback"
run_prompt omarchy_prompt_timezone "0:" run_prompt omarchy_prompt_timezone "0:"
assert_status 0 "timezone prompt accepts an empty selection" assert_status 0 "timezone prompt accepts an empty selection"
[[ $(field timezone) == "UTC" ]] || fail "timezone prompt falls back to UTC" [[ $(field timezone) == "UTC" ]] || fail "timezone prompt falls back to UTC"