#!/bin/bash
panel_fifo="/tmp/i3_lemonbar1_${USER}"
panel_commands="/tmp/i3_lemonbar2_${USER}"

function show(){
    setxkbmap -print | grep xkb_symbols | awk '{print $4}' | awk -F"+" '{print $2}'
}
if [ $# -lt 1  ]; then
    echo LANG$(show)
fi
if [ "$1" == "next" ]; then
    cur=$(show)
    next='se'
    if [ "$cur" == "se" ]; then
        next='pl'
    fi
    setxkbmap $next
    if [ -e $panel_fifo ]; then
        echo -e "LANG$next" > "${panel_fifo}"
    fi
    if [ -e $panel_commands ]; then
        echo -e "setlang $next" > "${panel_commands}"
    fi
elif [ "$1" == "qset" ]; then
        next=$2
    setxkbmap $next
    if [ -e $panel_fifo ]; then
        echo -e "LANG$next" > "${panel_fifo}"
    fi
elif [ "$1" == "show" ]; then
    show
else
    exit 1
fi
