Created
February 23, 2017 17:01
-
-
Save rzbrk/9a873c1d3324a32c7e88a716e66d84df to your computer and use it in GitHub Desktop.
Switch between two keyboard maps
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
#!/bin/bash | |
############################################################################### | |
# Begin of configuration section | |
############################################################################### | |
# Define the default keyboard map here | |
default_map="de" | |
# Define the alternative keyboard map here | |
#alternative_map="us" | |
alternative_map="ru" | |
# Icon file for messages | |
ks_icon="/usr/share/pixmaps/keyb-switch.jpg" | |
############################################################################### | |
# Begin of section with function definitions | |
# Don't change any lines below unless you know what you do! | |
############################################################################### | |
# Determine the current keyboard map | |
function det_curr_map { | |
local curr=$(setxkbmap -query | grep layout | awk '{ print $2 }') | |
echo "$curr" | |
} | |
# Show message to inform about keyboard map change | |
function ks_message { | |
notify-send -t 3000 \ | |
--icon=$ks_icon \ | |
"keyb-switch" \ | |
"Changed keyboard map to \"${current_map^^}\"." | |
} | |
############################################################################### | |
# Begin of main program | |
############################################################################### | |
# Determine the current map | |
current_map=$(det_curr_map) | |
if [ "$current_map" == "$default_map" ]; then | |
setxkbmap $alternative_map | |
else | |
setxkbmap $default_map | |
fi | |
# Update variable current_map | |
current_map=$(det_curr_map) | |
# Show message | |
ks_message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy this file to /usr/local/bin and chmod +x. When you configure a keyboard shortcut like "CTRL+F9" (avoid letters!) for this script, you can quickly change between two predefined keyboard layouts. If you like, provide a icon file at /usr/share/pixmaps/keyb-switch.jpg.