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"