#!/bin/sh
# Switch between keyboard layouts

# Add whatever layouts you want
set -- us latam

current=$(setxkbmap -query | awk '/layout/{ print $2 }')
total="$#"

index=1
for l in "$@" ; do
    if [ "$l" = "$current" ] ; then
        : $((index+=1))
        [ "$index" -gt "$total" ] && index=1
        setxkbmap $(eval "echo \${${index}}")
        break
    fi
    : $((index+=1))
done

DWMBLOCKS="$(pidof dwmblocks)"
if [ -n "$DWMBLOCKS" ] ; then
    kill -46 "$DWMBLOCKS" 2>/dev/null
fi