Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/omarchy-menu-timezone
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

set -e

timezone=$(timedatectl list-timezones | omarchy-menu-select "Set timezone" -- --width 520 --maxheight 520) || exit 1
# `timedatectl list-timezones` builds its list from tzdata.zi, which carries the
# backward-compatibility links alongside the zones they point at, so the picker
# offered Asia/Ashkhabad right under Asia/Ashgabat. zone.tab is one row per
# country per zone and holds none of those obsolete aliases; UTC is not in it.
timezones=$({ echo UTC; awk '!/^#/ && NF { print $3 }' /usr/share/zoneinfo/zone.tab; } | sort)

timezone=$(omarchy-menu-select "Set timezone" -- --width 520 --maxheight 520 <<<"$timezones") || exit 1
sudo timedatectl set-timezone "$timezone"
omarchy-shell -q omarchy.clock refresh
omarchy-notification-send "Timezone is now set to $timezone"
12 changes: 10 additions & 2 deletions install/provisioning/setup-form.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,24 @@ omarchy_prompt_hostname() {
done
}

# `timedatectl list-timezones` builds its list from tzdata.zi, which carries the
# backward-compatibility links alongside the zones they point at, so the picker
# offered Asia/Ashkhabad right under Asia/Ashgabat. zone.tab is one row per
# country per zone and holds none of those obsolete aliases; UTC is not in it.
omarchy_timezones() {
{ echo UTC; awk '!/^#/ && NF { print $3 }' /usr/share/zoneinfo/zone.tab; } | sort
}

# 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.
omarchy_prompt_timezone() {
local guess status
guess=$(tzupdate -p 2>/dev/null) || guess=""

if [[ -n $guess ]]; then
timezone=$(timedatectl list-timezones | gum choose --height 10 --selected "$guess" --header "Timezone") && status=0 || status=$?
timezone=$(omarchy_timezones | gum choose --height 10 --selected "$guess" --header "Timezone") && status=0 || status=$?
else
timezone=$(timedatectl list-timezones | gum filter --height 10 --header "Timezone") && status=0 || status=$?
timezone=$(omarchy_timezones | gum filter --height 10 --header "Timezone") && status=0 || status=$?
fi
((status == 0)) || return $status

Expand Down
2 changes: 2 additions & 0 deletions test/shell.d/setup-form-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ assert_status 0 "timezone prompt accepts the geo guess"
[[ $(field timezone) == "Europe/Copenhagen" ]] || fail "timezone prompt keeps the chosen timezone"
grep -qF -- '--selected Europe/Copenhagen' "$GUM_ARGS" || fail "timezone prompt preselects the geo guess"
grep -qF UTC "$tmp_dir/stdin.1" || fail "timezone prompt offers the system timezone list"
grep -qFx Asia/Ashgabat "$tmp_dir/stdin.1" || fail "timezone prompt offers the canonical zone"
! grep -qFx Asia/Ashkhabad "$tmp_dir/stdin.1" || fail "timezone prompt drops tzdata backward-compatibility aliases"
pass "timezone prompt preselects the geo guess when one is available"

# An unnetworked first boot has no guess, and the fallback has to survive `set -e`
Expand Down
6 changes: 6 additions & 0 deletions test/shell.d/timezone-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ grep -F '%wheel ALL=(root) NOPASSWD: /usr/bin/timedatectl ^set-timezone [A-Za-z0
grep -F 'sudo timedatectl set-timezone "$timezone"' "$timezone_menu" >/dev/null ||
fail "timezone menu uses the passwordless sudoers timedatectl rule"

grep -F '/usr/share/zoneinfo/zone.tab' "$timezone_menu" >/dev/null ||
fail "timezone menu lists zones from zone.tab"

! grep -F 'timedatectl list-timezones |' "$timezone_menu" >/dev/null ||
fail "timezone menu does not list tzdata backward-compatibility aliases"

! grep -F 'pkexec timedatectl set-timezone "$timezone"' "$timezone_menu" >/dev/null ||
fail "timezone menu does not wrap timedatectl in pkexec"

Expand Down