Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
#!/bin/bash
# Script to show current keyboard layout in i3status bar
# Requires https://github.com/nonpop/xkblayout-state
# Inspiration for wather display:
# https://keheliya.blogspot.com/2018/01/weather-info-in-i3status.html
# Suggested crontab entry:
# */5 * * * * curl -s wttr.in/?format=3\&m > ~/.weather.cache
# For Purple air updates:
# */5 * * * * ~/bin/purple.py > /dev/null
i3status | while :
do
read line
LG=$(xkblayout-state print "%s" | tr -d '\n\r')
IFS=', ' read -r -a LAYOUT <<< $(setxkbmap -query | awk '/layout/{print $2}')
lastidx=$( expr ${#LAYOUT[@]} - 1 )
P=$(cat ~/.purple-avg.cache | tail -n 1)
res="{ \"full_text\": \"🖮:\", \"separator\":false, \"separator_block_width\": 6 }"
for index in "${!LAYOUT[@]}"
do
i="${LAYOUT[index]}"
if [ $i == $LG ]
then
c=", \"color\":\"#FF0000\", \"border\":\"#AAAAAA\""
else
c=", \"color\":\"#444444\""
fi
if [[ $index -eq $lastidx ]]; then
e=""
else
e=", \"separator\":false, \"separator_block_width\": 6 "
fi
res="$res,{ \"full_text\": \"$i\"$c$e}"
done
ares="{ \"full_text\": \"🌫: $P\", \"color\":\"#ffbf00\", \"separator\":true, \"separator_block_width\": 20 }"
echo "${line/[/[$ares,$res,}" || exit 1
done