From d53b24cfc75e6208fb60334af5cf5a1559e184df Mon Sep 17 00:00:00 2001 From: Kros Dai Date: Tue, 6 Oct 2026 16:33:24 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(form):=20let=20callers=20prese?= =?UTF-8?q?lect=20a=20fallback=20timezone?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - :sparkles: 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 - :white_check_mark: a successful geo guess still outranks the fallback Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SdXqTwm63rRMwotZ1xqLC8 --- install/provisioning/setup-form.sh | 5 ++++- test/shell.d/setup-form-test.sh | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/install/provisioning/setup-form.sh b/install/provisioning/setup-form.sh index f4265d1d..c39330cd 100644 --- a/install/provisioning/setup-form.sh +++ b/install/provisioning/setup-form.sh @@ -167,10 +167,13 @@ omarchy_prompt_hostname() { } # 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() { local guess status guess=$(tzupdate -p 2>/dev/null) || guess="" + [[ -n $guess ]] || guess="${1:-}" if [[ -n $guess ]]; then timezone=$(timedatectl list-timezones | gum choose --height 10 --selected "$guess" --header "Timezone") && status=0 || status=$? diff --git a/test/shell.d/setup-form-test.sh b/test/shell.d/setup-form-test.sh index 2b9878eb..0fc23dc6 100755 --- a/test/shell.d/setup-form-test.sh +++ b/test/shell.d/setup-form-test.sh @@ -59,7 +59,7 @@ fi 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_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" 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:" assert_status 0 "timezone prompt accepts an empty selection" [[ $(field timezone) == "UTC" ]] || fail "timezone prompt falls back to UTC"