From 5a56df3d3669dfd0fa9945357c4cd29b048d7382 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Sun, 21 Feb 2021 15:40:42 +0000 Subject: [PATCH] Properly handle empty locale selection --- roles/home-cli/files/bashrc | 46 +++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/roles/home-cli/files/bashrc b/roles/home-cli/files/bashrc index b97cc3d..6c3566e 100644 --- a/roles/home-cli/files/bashrc +++ b/roles/home-cli/files/bashrc @@ -51,35 +51,41 @@ _acp_set_locale () { list) localectl list-locales ;; - "") - LANG=C - _acp_locale_selected=1 - ;; *) - if [ $(localectl list-locales | grep "$_acp_entered_locale" | wc -l) -eq 0 ] + if [ $(localectl list-locales | grep "${_acp_entered_locale}" | wc -l) -eq 0 ] then echo "Invalid locale entered." continue fi - LANG="$_acp_entered_locale" - LC_COLLATE="$LANG" # Alphabetic sorting. - LC_CTYPE="$LANG" # Interpretation of byte sequences. - LC_IDENTIFICATION="$LANG" # Locale metadata (GNU). - LC_MEASUREMENT="$LANG" # Units of measure -- metric/imperial (GNU). - LC_MESSAGES="$LANG" # Language that messages are displayed in. - LC_NAME="$LANG" # Salutations and titles (GNU). - LC_NUMERIC="$LANG" # Formatting for non-monetary numbers. - LC_TIME="$LANG" # Time format. - LC_ADDRESS="$LANG" # Postal address (GNU). - LC_MONETARY="$LANG" # Currency display. - LC_PAPER="$LANG" # Standard paper size -- A4 or Letter (GNU). - LC_TELEPHONE="$LANG" # Formats for telephone services (GNU). - rm -f "$HOME/.config/locale.conf" - locale > "$HOME/.config/locale.conf" + if [ -z "$_acp_entered_locale" ] + then + LANG=C.utf8 + else + LANG="$_acp_entered_locale" + fi _acp_locale_selected=1 ;; esac + LC_COLLATE="$LANG" # Alphabetic sorting. + LC_CTYPE="$LANG" # Interpretation of byte sequences. + LC_IDENTIFICATION="$LANG" # Locale metadata (GNU). + LC_MEASUREMENT="$LANG" # Units of measure -- metric/imperial (GNU). + LC_MESSAGES="$LANG" # Language that messages are displayed in. + LC_NAME="$LANG" # Salutations and titles (GNU). + LC_NUMERIC="$LANG" # Formatting for non-monetary numbers. + LC_TIME="$LANG" # Time format. + LC_ADDRESS="$LANG" # Postal address (GNU). + LC_MONETARY="$LANG" # Currency display. + LC_PAPER="$LANG" # Standard paper size -- A4 or Letter (GNU). + LC_TELEPHONE="$LANG" # Formats for telephone services (GNU). + if [ ! -z "$_acp_entered_locale" ] + then + rm -f "$HOME/.config/locale.conf" + locale > "$HOME/.config/locale.conf" + fi done + unset _acp_locale_selected + unset _acp_entered_locale } if [ -r "$HOME/.config/locale.conf" ]