Skip to content

Instantly share code, notes, and snippets.

@nlamprian
Last active August 29, 2015 14:00
Show Gist options
  • Save nlamprian/dd583c858e1920d960cd to your computer and use it in GitHub Desktop.
Save nlamprian/dd583c858e1920d960cd to your computer and use it in GitHub Desktop.
Swaps "Caps Lock" and "Left Ctrl" in Ubuntu
#!/bin/sh
# Script to remap the "Caps Lock" and "Left Ctrl" keys
# The change persists between sessions
#
# Caps Lock -> Left Ctrl
# Left Ctrl -> Caps Lock
#
# Make it executable and run it:
# chmod +x capslock_lctrl_remap.sh
# ./capslock_lctrl_remap.sh
if [ $# = 1 ] && [ "$1" = "-h" ]; then
echo "Arguments:"
echo "-h\thelp"
echo "-l\tlogout"
exit 0
fi
# Remapping
cd /usr/share/X11/xkb/symbols/
sudo sed -i -e "/key <CAPS>/ s/Caps_Lock/Control_L/g" -e "/key <LCTL>/ s/Control_L/Caps_Lock/g" pc
# Enforces keyboard layouts recompilation
cd /var/lib/xkb/
sudo rm *
# Logout: Save any open files
if [ "$1" = "-l" ]; then
echo "Logging out"
kill -9 -1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment