diff --git a/.config/i3/config b/.config/i3/config index ed7e7a59..8f2e876e 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -46,6 +46,7 @@ bar { bindsym $mod+Return exec $term bindsym $mod+Shift+Return exec --no-startup-id samedir +bindsym $mod+Mod1+space exec --no-startup-id kblayoutmanager cycle $(echo $KBLAYOUTS) bindsym $mod+Shift+space floating toggle bindsym $mod+space focus mode_toggle diff --git a/.config/i3blocks/config b/.config/i3blocks/config index e83de5a0..5e0e7b9c 100644 --- a/.config/i3blocks/config +++ b/.config/i3blocks/config @@ -45,6 +45,10 @@ signal=12 interval=once signal=10 +[lang] +interval=once +signal=13 + #[disk] #interval=60 #command=disk / diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 1f37d24f..396a8ab5 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -36,6 +36,8 @@ super + shift + w $BROWSER # Et cetera... +super + alt + space + kblayoutmanager cycle $(echo $KBLAYOUTS) super + grave dmenuunicode super + Scroll_Lock diff --git a/.local/bin/kblayoutmanager b/.local/bin/kblayoutmanager new file mode 100755 index 00000000..f5164403 --- /dev/null +++ b/.local/bin/kblayoutmanager @@ -0,0 +1,34 @@ +#!/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 ' or 'cycle ... '" ;; +esac + +pkill -RTMIN+13 i3blocks # for [lang] in i3blocks diff --git a/.local/bin/statusbar/lang b/.local/bin/statusbar/lang new file mode 100755 index 00000000..fab8c9b7 --- /dev/null +++ b/.local/bin/statusbar/lang @@ -0,0 +1,10 @@ +#!/bin/sh +# A simple module to print current keyboard layout + +lang="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" + +# Since shortcuts are unlikely to work with non-latin/US keyboard layouts, +# the line below makes US layout green to help you recognize anything else easier +[ "$lang" = "us" ] && color="#00ff00" || color="#ff0000" + +printf "%s\n" "$color" "$lang" diff --git a/.zprofile b/.zprofile index d9e95b7e..cf7f571a 100644 --- a/.zprofile +++ b/.zprofile @@ -40,6 +40,7 @@ export ANSIBLE_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/ansible/ansible.cfg" export DICS="/usr/share/stardict/dic/" export SUDO_ASKPASS="$HOME/.local/bin/dmenupass" export FZF_DEFAULT_OPTS="--layout=reverse --height 40%" +export KBLAYOUTS="us gb" export LESS=-R export LESS_TERMCAP_mb="$(printf '%b' '')" export LESS_TERMCAP_md="$(printf '%b' '')"