mirror of
https://github.com/LukeSmithxyz/voidrice.git
synced 2026-03-20 01:37:45 +01:00
`kblayoutmanager` switches layouts. Layouts are read from `$KBLAYOUTS`. An extra file, `~/.local/bin/statusbar/lang` is added in the commit, which adds layout indicator to i3blocks. Example binds are `Super+Alt+Space` added to both i3/config and sxhkd/config. Example `KBLAYOUTS` are US Standard Layout and Global UK layout. Special thanks to KEZ-
35 lines
1.2 KiB
Bash
Executable File
35 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# An edited https://github.com/porras/i3-keyboard-layout/blob/master/i3-keyboard-layout by MYDavoodeh
|
|
# FIXME The script is relatively way too slow (especially when cycling)
|
|
set -e
|
|
|
|
get_kbdlayout(){ setxkbmap -query | grep -oP 'layout:\s*\K\w+' ;}
|
|
|
|
set_kbdlayout(){ # TODO Add support for variations of langugages
|
|
setxkbmap "$1"
|
|
# pgrep i3status | xargs --no-run-if-empty kill -s USR1 # to tell i3status to update
|
|
}
|
|
|
|
cycle(){ # TODO Optimize cycling time
|
|
current_layout=$(get_kbdlayout)
|
|
eval last="\$$#"
|
|
# If current_layout is the last one OR current_layout is not in the given layouts,
|
|
{ [ "$last" = "$current_layout" ] || ! echo "$*" | grep -qo "$current_layout" ;} &&
|
|
# set the first one in cycle as the initiator,
|
|
set_kbdlayout "$1" ||
|
|
# otherwise find the next.
|
|
set_kbdlayout "$(echo "$*" | sed -E "s/^.*$current_layout ([a-zA-Z]*).*$/\1/")"
|
|
}
|
|
|
|
|
|
subcommand="$1"
|
|
shift || (echo "$helpmsg" && exit)
|
|
case $subcommand in
|
|
"get") get_kbdlayout ;;
|
|
"set") set_kbdlayout "$1" ;;
|
|
"cycle") cycle "$@" ;;
|
|
*) echo "Error: Command $subcommand not found. Please use one of the enteries: 'get', 'set <layout>' or 'cycle <layout1> <layout2> ... <layoutN>'" ;;
|
|
esac
|
|
|
|
pkill -RTMIN+13 i3blocks # for [lang] in i3blocks
|