From 5548e053196551692050c6978891d6dcc975e70d Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 12 Mar 2023 20:15:14 +0100 Subject: [PATCH] Add configure-locale implementation --- configs/crystal/configure-locale/up.nu | 44 +++++++++++++++++++++++++- src/task/commands/todo.rs | 2 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/configs/crystal/configure-locale/up.nu b/configs/crystal/configure-locale/up.nu index 949cd64..c4bb2fd 100644 --- a/configs/crystal/configure-locale/up.nu +++ b/configs/crystal/configure-locale/up.nu @@ -1,5 +1,47 @@ let RUN_IN_CHROOT = true; + +def set_keymap [keymap: string] { + debug $"Setting keymap to ($keymap)" + touch /etc/vconsole.conf + $"\nKEYMAP=($keymap)" | save -a /etc/vconsole.conf +} + +def set_timezone [timezone: string] { + debug $"Setting timezone to ($timezone)" + run ln -sf $"/usr/share/zoneinfo/($timezone)" /etc/localtime + run hwclock --systohc +} + +def set_locales [locales] { + debug $"Setting locales to ($locales)" + mut new_locales = $locales + + if ($new_locales | length) == 0 { + warn "No locale configured. Defaulting to en_US.UTF_8" + # set a default locale + $new_locales = ["en_US.UTF-8 UTF-8"] + "LANG=en_US.UTF-8" | save -f /etc/locale.conf + } else { + # save the first locale as the leading one + let first_locale = ($new_locales.0 | split row " " | get 0) + $"LANG=($first_locale)" | save -f /etc/locale.conf + } + + $new_locales | each {|$locale| + let locale_parts = ($locale | split row " ") + let locale_name = $locale_parts.0 + let encoding = $locale_parts.1 + $"($locale_name) ($encoding)\n" | save -a /etc/locale.gen + } + run locale-gen +} + # Applies all system changes of `configure-locale` def main [cfg] { - echo "Executing up task `configure-locale` with config" $cfg + debug $"Configuring locale with config ($cfg)" + set_keymap $cfg.keymap + set_timezone $cfg.timezone + set_locales $cfg.locale + + info "Locale configured" } diff --git a/src/task/commands/todo.rs b/src/task/commands/todo.rs index 6161eea..e5ae5ff 100644 --- a/src/task/commands/todo.rs +++ b/src/task/commands/todo.rs @@ -43,7 +43,7 @@ impl Command for TodoCommand { String::from("TODO"), format!("This is a TODO: {}", args.join(" ")), Some(call.span()), - Some(String::from("Implement this functionality")), + Some(args.join(" ")), vec![], )) }