From 2971ffdd80c15e9a1585e5445298a91bf95a8d13 Mon Sep 17 00:00:00 2001 From: pvincent Date: Wed, 2 Sep 2026 00:00:36 +0400 Subject: [PATCH] smart_write --- lib/initiate.bash | 3 ++- tools/smart_write | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/initiate.bash b/lib/initiate.bash index a91e6cc..67e16c8 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -238,8 +238,9 @@ function fix_locales { done for locale in "${!found_locales[@]}"; do if [[ ${found_locales[$locale]} == 'false' ]]; then + local language="${locale:0:5}" echo "Locale: $locale missing" - sudo sed -i "s/^# *\(${locale:0:5}\.UTF-8\)/\1/" /etc/locale.gen + sudo /opt/miaou-bash/tools/smart_write /etc/locale.gen "(^# )?${language}\.UTF-8 UTF-8" "${language}.UTF-8 UTF-8" should_regenerate=true fi done diff --git a/tools/smart_write b/tools/smart_write index 6f45616..904de62 100755 --- a/tools/smart_write +++ b/tools/smart_write @@ -1,14 +1,14 @@ #!/usr/bin/env miaou-bash function usage { - builtin echo "Usage: $(basename "$0") " + builtin echo "Usage: $(basename "$0") " } [[ $# -ne 3 ]] && usage && exit 2 -REGEX=$1 -STRING=$2 -FILE=$3 +FILE=$1 +REGEX=$2 +STRING=$3 if ! grep -Pq "$REGEX" "$FILE"; then builtin echo -e "$STRING" >>"$FILE"