Created
December 20, 2017 09:56
-
-
Save Cnly/d462290ca5756c4bec0c2f67cb4cd6e5 to your computer and use it in GitHub Desktop.
Remap keys on Gnome (E.g. Swap Alt and Ctrl) without screwing up input methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
ALL_SOURCES="`gsettings get org.gnome.desktop.input-sources sources`" | |
SOURCE_COUNT="`echo $ALL_SOURCES | tr -d -c ')' | awk '{ print length; }'`" | |
CURRENT_SOURCE_STR="`gsettings get org.gnome.desktop.input-sources current`" | |
CURRENT_SOURCE="${CURRENT_SOURCE_STR#uint32 }" | |
next_source() { | |
if [ "$CURRENT_SOURCE" -lt $((SOURCE_COUNT - 1)) ]; then | |
gsettings set org.gnome.desktop.input-sources current $((CURRENT_SOURCE + 1)) | |
else | |
gsettings set org.gnome.desktop.input-sources current 0 | |
fi | |
} | |
prev_source() { | |
if [ "$CURRENT_SOURCE" -gt 0 ]; then | |
gsettings set org.gnome.desktop.input-sources current $((CURRENT_SOURCE - 1)) | |
else | |
gsettings set org.gnome.desktop.input-sources current $((SOURCE_COUNT - 1)) | |
fi | |
} | |
if [ "next" = "$1" ]; then | |
next_source | |
fi | |
if [ "prev" = "$1" ]; then | |
prev_source | |
fi | |
sleep 0.005 | |
setxkbmap -option ctrl:swap_lalt_lctl_lwin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment