Skip to content

Instantly share code, notes, and snippets.

@bjonord
Created July 19, 2014 23:38
Show Gist options
  • Save bjonord/3f8850cad11d992b4bc2 to your computer and use it in GitHub Desktop.
Save bjonord/3f8850cad11d992b4bc2 to your computer and use it in GitHub Desktop.
keyboard-switcher
#!/bin/zsh
# If an explicit layout is provided as an argument, use it. Otherwise, select the next layout from
# the set [us(colemak), us(altgr-intl), se].
if [[ -n "$1" ]]; then
setxkbmap $1 -variant $2
else
layout=$(setxkbmap -query | awk '$1 ~/layout/ {print $2}')
variant=$(setxkbmap -query | awk '$1 ~/variant/ {print $2}')
case $layout$variant in
uscolemak)
setxkbmap se -option caps:ctrl_modifier
;;
se)
setxkbmap us -variant altgr-intl -option caps:ctrl_modifier
;;
*)
setxkbmap us -variant colemak -option caps:ctrl_modifier
;;
esac
fi
result=$(setxkbmap -query | awk '$1 ~/(layout|variant)/ {print $2}')
echo $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment