#!/bin/sh # switchkeys: A little script to switch between two keyboard layouts # in the Linux console and XFree86. You need to edit the top of this # file to change the paths to the layout files. Also note that the # PATH is not set in this script, so you may wish to set it here to # ensure proper operation. Requires awk and the relevant programs to # set keyboard maps, does not check to see if they exist. The detection # algorithm for the current layout may also break easily. All in all, # not a robust script, but works for me. # # Made by Kimmo Kulovesi # ABSOLUTELY NO WARRANTY - USE AT YOUR OWN RISK ONLY. # Distribute as you please. ### Edit here: # X layouts ARKKUDV_X='/usr/local/share/keymaps/arkkudv.Xmodmap' OTHER_X='fi' # Console layouts ARKKUDV_C='/usr/local/share/keymaps/arkkudv.kmap.gz' OTHER_C='fi-latin1' LK_OPT="--unicode" ### if [ -n "$DISPLAY" ]; then current_layout="`xmodmap -pk | awk \ '$3 == "(p)" { seen_p=1 next } $3 == "(q)" { if (seen_p == 1) print "dvorak" else print "qwerty" exit }'`" if [ "$current_layout" = "qwerty" ]; then if [ -e "$ARKKUDV_X" ]; then xmodmap "$ARKKUDV_X" else setxkbmap 'dvorak' fi else if [ -e "/$OTHER_X" ]; then xmodmap "$OTHER_X" else setxkbmap "$OTHER_X" fi fi else current_layout="`dumpkeys | awk \ '/keycode [ 0-9]+ = [ +]*[pP] / { seen_p=1 next } /keycode [ 0-9]+ = [ +]*[qQ] / { if (seen_p == 1) print "dvorak" else print "qwerty" exit }'`" if [ "$current_layout" = "qwerty" ]; then if [ -e "$ARKKUDV_C" ]; then loadkeys $LK_OPT "$ARKKUDV_C" >/dev/null 2>&1 else loadkeys $LK_OPT 'dvorak' >/dev/null 2>&1 fi else loadkeys $LK_OPT "$OTHER_C" >/dev/null 2>&1 fi fi