Skip to content

Instantly share code, notes, and snippets.

@rzbrk
Created February 23, 2017 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rzbrk/9a873c1d3324a32c7e88a716e66d84df to your computer and use it in GitHub Desktop.
Save rzbrk/9a873c1d3324a32c7e88a716e66d84df to your computer and use it in GitHub Desktop.
Switch between two keyboard maps
#!/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
@rzbrk
Copy link
Author

rzbrk commented Feb 23, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment