From 524a9abb288fc5a2ecc2c7ecbfbd2fee227652c4 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Sun, 21 Apr 2024 21:19:14 +0200 Subject: [PATCH] Add script to change the keyboard layout. Personally I'm used to the US keyboard, but Libre En Communs has other sysadmins than me and they might want to use their preferred keyboard layout instead. This script has been tested on a Guix system installation. Finding a way to launch the script at boot will be done later on. Signed-off-by: Denis 'GNUtoo' Carikli --- scripts/kbd.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 scripts/kbd.sh diff --git a/scripts/kbd.sh b/scripts/kbd.sh new file mode 100755 index 0000000..fd12a05 --- /dev/null +++ b/scripts/kbd.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2024 Denis 'GNUtoo' Carikli +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +keymaps="/run/current-system/profile/share/keymaps/i386" + +ask_keymap_type() +{ + index=0 + keymap_type_list="" + for keymap_type in "${keymaps}"/* ; do + # shellcheck disable=SC2001 # For ^ or $ regex. + keymap_type="$(echo "${keymap_type}" | sed "s#^${keymaps}/##")" + if [ "${keymap_type}" = "include" ] ; then + continue + fi + keymap_type_list="${keymap_type_list} ${index} ${keymap_type}" + index=$((index + 1)) + done + + IFS=' ' read -r -a keymap_type_list_array <<< "${keymap_type_list}" + + # shellcheck disable=SC2086 + result=$(dialog --stdout \ + --menu "Keyboard layout type:" \ + 0 0 0 \ + ${keymap_type_list}) + + if [ "${result}" = "" ] ; then + exit 0 + fi + + result=$((result * 2)) + result=$((result + 1)) + + directory=${keymap_type_list_array[${result}]} + echo "${directory}" +} + +ask_keymap() +{ + directory="$1" + + index=0 + keymap_list="" + for keymap in "${keymaps}"/"${directory}"/* ; do + # shellcheck disable=SC2001 # For ^ or $ regex. + mapname=$(echo "${keymap}" | \ + sed "s#^${keymaps}/${directory}/##" | \ + sed 's#\.map\.gz$##') + keymap_list="${keymap_list} ${index} ${mapname}" + index=$((index + 1)) + done + + IFS=' ' read -r -a keymap_list_array <<< "${keymap_list}" + + # shellcheck disable=SC2086 + result=$(dialog --stdout --menu "Keyboard layout:" 0 0 0 ${keymap_list}) + if [ "${result}" = "" ] ; then + exit 0 + fi + result=$((result * 2)) + result=$((result + 1)) + + keymap_name=${keymap_list_array[${result}]} + + echo "${keymaps}/${directory}/${keymap_name}.map.gz" +} + +directory="$(ask_keymap_type)" +if [ -z "${directory}" ] ; then + exit 0 +fi + +keymap_path="$(ask_keymap "${directory}")" +if [ -z "${keymap_path}" ] ; then + exit 0 +fi + +loadkeys "${keymap_path}"