From f8d647da9444268462ec306ba89f06238fb5cc7c Mon Sep 17 00:00:00 2001 From: Stephan Raabe Date: Mon, 20 Nov 2023 17:47:51 +0100 Subject: [PATCH] Add keyboard layout and variant settings with gum --- .install/keyboard.sh | 79 ++++++++++++++++++++++++++++++++ .install/setup.sh | 41 ----------------- .install/templates/keyboard.conf | 12 +++++ .install/templates/keyboard.py | 3 ++ install.sh | 2 +- 5 files changed, 95 insertions(+), 42 deletions(-) create mode 100755 .install/keyboard.sh delete mode 100644 .install/setup.sh create mode 100644 .install/templates/keyboard.conf create mode 100644 .install/templates/keyboard.py diff --git a/.install/keyboard.sh b/.install/keyboard.sh new file mode 100755 index 0000000..aa1aee8 --- /dev/null +++ b/.install/keyboard.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# ------------------------------------------------------ +# Setup +# ------------------------------------------------------ +echo -e "${GREEN}" +cat <<"EOF" + _ __ _ _ +| |/ /___ _ _| |__ ___ __ _ _ __ __| | +| ' // _ \ | | | '_ \ / _ \ / _` | '__/ _` | +| . \ __/ |_| | |_) | (_) | (_| | | | (_| | +|_|\_\___|\__, |_.__/ \___/ \__,_|_| \__,_| + |___/ + +EOF +echo -e "${NONE}" + +# Default layout and variants +keyboard_layout="us" +keyboard_variant="" + +_setupKeyboardLayout() { + if gum confirm "Current keyboard layout: $keyboard_layout! Do you want to change it?" ;then + keyboard_layout=$(localectl list-x11-keymap-layouts | gum filter --placeholder "Select keyboard layout...") + echo "" + echo "Keyboard layout changed to $keyboard_layout" + elif [ $? -eq 130 ]; then + exit 130 + fi + _setupKeyboardVariant +} + +_setupKeyboardVariant() { + if gum confirm "Current keyboard variant: $keyboard_variant! Do you want to change it?" ;then + keyboard_variant=$(localectl list-x11-keymap-variants | gum filter --placeholder "Select keyboard variant...") + echo "" + echo "Keyboard layout changed to $keyboard_variant" + elif [ $? -eq 130 ]; then + exit 130 + fi + echo "" + _confirmKeyboard +} + +_confirmKeyboard() { + echo "Current selected keyboard setup:" + echo "Keyboard layout: $keyboard_layout" + echo "Keyboard variant: $keyboard_variant" + if gum confirm "Do you want proceed with this keyboard setup?" --affirmative "Proceed" --negative "Change" ;then + return 0 + elif [ $? -eq 130 ]; then + exit 130 + else + _setupKeyboardLayout + fi +} + +if [ "$restored" == "1" ]; then + echo "You have already restored your settings into the new installation." +else + _confirmKeyboard + + cp .install/templates/keyboard.conf ~/dotfiles-versions/$version/hypr/conf/keyboard.conf + cp .install/templates/keyboard.py ~/dotfiles-versions/$version/qtile/conf/keyboard.py + + SEARCH="\"KEYBOARD_LAYOUT\"" + REPLACE="\"$keyboard_layout\"" + sed -i "s/$SEARCH/$REPLACE/g" ~/dotfiles-versions/$version/hypr/conf/keyboard.conf + + SEARCH="\"KEYBOARD_LAYOUT\"" + REPLACE="\"$keyboard_layout\"" + sed -i "s/$SEARCH/$REPLACE/g" ~/dotfiles-versions/$version/qtile/conf/keyboard.py + + SEARCH="\"KEYBOARD_VARIANT\"" + REPLACE="\"$keyboard_variant\"" + sed -i "s/$SEARCH/$REPLACE/g" ~/dotfiles-versions/$version/hypr/conf/keyboard.conf + + echo "" + echo "Keyboard setup updated successfully." +fi diff --git a/.install/setup.sh b/.install/setup.sh deleted file mode 100644 index 8e49884..0000000 --- a/.install/setup.sh +++ /dev/null @@ -1,41 +0,0 @@ -# ------------------------------------------------------ -# Setup -# ------------------------------------------------------ -echo -e "${GREEN}" -cat <<"EOF" - ____ _ -/ ___| ___| |_ _ _ _ __ -\___ \ / _ \ __| | | | '_ \ - ___) | __/ |_| |_| | |_) | -|____/ \___|\__|\__,_| .__/ - |_| - -EOF -echo -e "${NONE}" -if [ "$restored" == "1" ]; then - echo "You have already restored your settings into the new installation." -else - while true; do - read -p "Do you want to set your keyboard layout? (Yy/Nn): " yn - case $yn in - [Yy]* ) - read -p "Enter your preferred keyboard layout (us,de,...) (default:us): " keyboard - if [ -z "$keyboard" ]; then - keyboard="us" - fi - - SEARCH="kb_layout = us" - REPLACE="kb_layout = $keyboard" - sed -i "s/$SEARCH/$REPLACE/g" ~/dotfiles-versions/$version/hypr/conf/keyboard.conf - - SEARCH="keyboard_layout = \"us\"" - REPLACE="keyboard_layout = \"$keyboard\"" - sed -i "s/$SEARCH/$REPLACE/g" ~/dotfiles-versions/$version/qtile/conf/keyboard.py - break;; - [Nn]* ) - break;; - * ) echo "Please answer yes or no.";; - esac - done -fi -echo "" diff --git a/.install/templates/keyboard.conf b/.install/templates/keyboard.conf new file mode 100644 index 0000000..3a974d0 --- /dev/null +++ b/.install/templates/keyboard.conf @@ -0,0 +1,12 @@ +# ----------------------------------------------------- +# Keyboard Layout +# ----------------------------------------------------- +input { + kb_layout = "KEYBOARD_LAYOUT" + kb_variant = "KEYBOARD_VARIANT" + follow_mouse = 1 + touchpad { + natural_scroll = false + } + sensitivity = 0 # -1.0 - 1.0, 0 means no modification. +} diff --git a/.install/templates/keyboard.py b/.install/templates/keyboard.py new file mode 100644 index 0000000..9939dbb --- /dev/null +++ b/.install/templates/keyboard.py @@ -0,0 +1,3 @@ +# Setup global keyboard layout here + +keyboard_layout = "KEYBOARD_LAYOUT" diff --git a/install.sh b/install.sh index b88f4cf..b0f18bb 100755 --- a/install.sh +++ b/install.sh @@ -59,7 +59,7 @@ source .install/wallpaper.sh source .install/disabledm.sh source .install/issue.sh source .install/restore.sh -source .install/setup.sh +source .install/keyboard.sh source .install/copy.sh source .install/config-folder.sh source .install/init-pywal.sh