keyboard-layout-switch.sh (500B)
1 #!/bin/sh 2 # toggle between two keyboard layouts 3 4 layoutfile="$HOME/.cache/kbd-layout" 5 6 # define two languages 7 lang1="us" 8 lang2="dk" 9 10 set_language() { 11 printf '%s\n' "$1" > "$layoutfile" 12 setxkbmap "$1" -option -option ctrl:nocaps 13 } 14 15 if [ ! -f "$layoutfile" ]; then 16 set_language "$lang1" 17 exit 0 18 fi 19 20 # read the language file, and switch to the other language 21 currlang="$(cat "$layoutfile")" 22 23 if [ "$currlang" = "$lang1" ]; then 24 set_language "$lang2" 25 else 26 set_language "$lang1" 27 fi