Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
71 changes: 71 additions & 0 deletions core/tabs/utils/locale-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh -e
. ../common-script.sh

setLocale() {
if command_exists locale-gen; then
iso=$(curl -4fsSL --max-time 5 https://ifconfig.io/country_code 2>/dev/null) || iso="US"
suggested_locales=$(ls /usr/share/i18n/locales/ | grep -i "$iso" || true)

Check warning on line 7 in core/tabs/utils/locale-setup.sh

View workflow job for this annotation

GitHub Actions / Shellcheck

[shellcheck] reported by reviewdog 🐶 Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames. Raw Output: ./core/tabs/utils/locale-setup.sh:7:29: warning: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames. (ShellCheck.SC2010)
Comment thread
technicks89 marked this conversation as resolved.
Outdated

if [ -z "$suggested_locales" ]; then
suggested_locales=$(ls /usr/share/i18n/locales/)
Comment thread
technicks89 marked this conversation as resolved.
Outdated
fi

printf "%s\n" "Suggested locales based on your location ($iso):"
i=1
for loc in $suggested_locales; do
printf " %d) %s\n" "$i" "$loc"
i=$((i + 1))
done
printf " %s\n" "c) Enter a custom locale"

printf "%s" "Select a locale number (or 'c' for custom): "
read -r choice

if [ "$choice" = "c" ] || [ "$choice" = "C" ]; then
LOCALE=""
while [ -z "$LOCALE" ]; do
printf "%s" "Enter locale (e.g. en_US): "
read -r custom_locale

if [ -z "$custom_locale" ]; then
printf "%s\n" "Locale cannot be empty."
continue
fi

if [ -f "/usr/share/i18n/locales/$custom_locale" ]; then
LOCALE="$custom_locale"
else
printf "%s\n" "'$custom_locale' is not a recognized locale. Please try again."
fi
done
else
case "$choice" in
''|*[!0-9]*)
printf "%s\n" "Invalid selection."
exit 1
;;
esac
LOCALE=$(printf "%s\n" "$suggested_locales" | sed -n "${choice}p")
if [ -z "$LOCALE" ]; then
printf "%s\n" "Invalid selection."
Comment thread
technicks89 marked this conversation as resolved.
exit 1
fi
fi

if ! grep -qxF "${LOCALE} UTF-8" /etc/locale.gen 2>/dev/null; then
printf '%s UTF-8\n' "$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.gen >/dev/null
fi
if grep -q '^LANG=' /etc/locale.conf 2>/dev/null; then
"$ESCALATION_TOOL" sed -i "s/^LANG=.*/LANG=${LOCALE}/" /etc/locale.conf
else
printf 'LANG=%s\n' "$LOCALE" | "$ESCALATION_TOOL" tee -a /etc/locale.conf >/dev/null
fi
"$ESCALATION_TOOL" locale-gen "${LOCALE}"
else
printf "%b\n" "ERROR! locale-gen not found; cannot generate locales on this system."
exit 1
fi
Comment thread
technicks89 marked this conversation as resolved.
}

checkEnv
Comment thread
technicks89 marked this conversation as resolved.
setLocale
11 changes: 11 additions & 0 deletions core/tabs/utils/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ name = "Crypto tool"
script = "encrypt_decrypt_tool.sh"
task_list = "I FM"

[[data]]
name = "Locale Setup"
Comment thread
technicks89 marked this conversation as resolved.
description = "This allows the user to set their locale"
script = "locale-setup.sh"
task_list = "FM"
Comment thread
technicks89 marked this conversation as resolved.

[[data.preconditions]]
matches = true
data = "command_exists"
values = [ "locale-gen" ]

[[data]]
name = "Numlock on Startup"
description = "This utility is designed to enable Num Lock at boot, rather than within desktop environments like KDE or GNOME"
Expand Down
1 change: 1 addition & 0 deletions docs/content/userguide/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ https://github.com/ChrisTitusTech/dwm-titus

- **Bluetooth Manager**: This utility is designed to manage bluetooth in your system
- **Numlock on Startup**: This utility is designed to enable Num Lock at boot, rather than within desktop environments like KDE or GNOME
- **Locale Setup**: This allows the user to set their locale
- **Ollama**: This utility is designed to manage ollama in your system
- **Ranalama**: This utility is designed to manage ramalama in your system
- **Service Manager**: This utility is designed to manage services in your system
Expand Down
Loading