automate/001_swap-caps.sh

38 lines
867 B
Bash

#!/bin/bash
# Default destination directory if not provided
DEST=${1:-/etc/skel}
# Create the.xinitrc.d directory if it doesn't exist
mkdir -p ${DEST}/.xinitrc.d
# Write the setxkbmap configuration to a script file
cat <<EOF | sudo tee ${DEST}/.xinitrc.d/setxkbmap.sh >/dev/null
#!/bin/bash
setxkbmap -model pc104 -layout gb,us -option caps:swapecape
EOF
# Make the script executable
chmod +x ${DEST}/.xinitrc.d/setxkbmap.sh
# Keyboard configuration adjustments
config_file="/etc/default/keyboard"
typeset -A rules
rules=(
"XKBMODEL" "pc105"
"XKBLAYOUT" "extd"
"XKBVARIANT" ""
"XKBOPTIONS" "caps:swapescape"
"BACKSPACE" "guess"
)
for rule in "${rules[@]}"; do
regex="s/^#\?\(${rule}\s*\).*$/\1=${rules[$rule]}/"
sudo sed -i "${regex}" ${config_file}
done
# Trigger udevadm to apply changes
sudo udevadm trigger --subsystem-match=input --action=change