diff --git a/bin/setxkbmap-toggle b/bin/setxkbmap-toggle new file mode 100755 index 0000000..53040ae --- /dev/null +++ b/bin/setxkbmap-toggle @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Usage: setxkbmap-toggle layout[:variant] [layout[:variant]]... + +layout=`setxkbmap -query | sed -n "s/^layout:\s\+//p"` +variant=`setxkbmap -query | sed -n "s/^variant:\s\+//p"` + + +[ "$variant" = "" ] && CURRENT="$layout" || CURRENT="$layout:$variant" + +next=$1 + +while [ $# -gt 0 ] +do + keymap=$1 + shift + + if [ "$keymap" = "$CURRENT" ] + then + if [ $# -gt 0 ] + then + next=$1 + shift + fi + fi +done + +echo "$next" | grep ":" >/dev/null +if [ $? -eq 0 ] +then + layout=`echo $next | cut -f1 -d:` + variant=`echo $next | cut -f2 -d:` +else + layout=$next + variant="" +fi + +setxkbmap "$layout" "$variant" + +[ "$variant" = "" ] && CURRENT="$layout" || CURRENT="$layout:$variant" +echo $CURRENT