#!/bin/bash
# .local/bin/garuda-locale.sh

localectl > /tmp/garuda-locale.txt

cat /tmp/garuda-locale.txt | grep Keymap > /tmp/keymap.txt

cat /tmp/garuda-locale.txt | grep Layout > /tmp/layout.txt

locale=$(cat /tmp/keymap.txt | awk '{ print $3 }')

variant=$(cat /tmp/layout.txt | awk '{ print $3 }')

sed -i "/kb_layout  =/c\        kb_layout  = \"$locale\"," "$HOME/.config/hypr/hyprland.lua"

if [ "$variant" != "$locale" ]

then

sed -i "/kb_variant =/c\        kb_variant = \"$variant\"," "$HOME/.config/hypr/hyprland.lua"

fi

sed -i 's|hl.exec_cmd(".local/bin/garuda-locale.sh")|-- hl.exec_cmd(".local/bin/garuda-locale.sh")|' "$HOME/.config/hypr/hyprland.lua"
