Add script to disable CapsLock (Linux)

This commit is contained in:
q3aql 2020-11-05 14:44:35 +01:00
parent d701077ea1
commit 697b735052

View File

@ -0,0 +1,29 @@
#!/bin/bash
##################################
# Script to disable CapsLock #
# #
# Author: q3aql@protonmail.ch #
##################################
# Variables
xmodmap_config_dir=/tmp/.disable-capslock
xmodmap_config_file=${xmodmap_config_dir}/capslock.key
# Check dir and create/restore config
mkdir -p ${xmodmap_config_dir}
if [ -f ${xmodmap_config_file} ] ; then
echo "* Restoring original function of CapsLock..."
sleep 2
restore_key=$(cat ${xmodmap_config_file})
xmodmap -e "keycode ${restore_key} = Caps_Lock"
rm -rf ${xmodmap_config_file}
echo "* Restored!"
else
echo "* Creating mapping of CapsLock to Shift..."
sleep 2
capslock_key_detect=$(xmodmap -pke | grep Caps_Lock | tr -s " " | grep keycode | head -1 | cut -d " " -f 2)
echo ${capslock_key_detect} > ${xmodmap_config_file}
xmodmap -e "keycode ${capslock_key_detect} = Shift_L"
echo "* Created!"
fi