nixos-config/modules/workspace/i3blocks/scripts/connections.nix

63 lines
1.6 KiB
Nix
Raw Normal View History

2020-02-17 17:00:59 +04:00
{ bash, networkmanager, iconfont, config, modemmanager, ... }: ''
#!${bash}/bin/bash
CONNECTIONS=$(${networkmanager}/bin/nmcli con show --active | tail +2 | tr -s ' ' | rev | cut -d' ' -f3 | rev)
text=""
for connection in $CONNECTIONS
do
grep wifi <<< $connection > /dev/null && {
SIGNAL=$(${networkmanager}/bin/nmcli d w | grep '^\*' | tr -s ' ' | cut -d' ' -f7)
if [[ $SIGNAL -lt 20 ]]
then
text+=
elif [[ $SIGNAL -lt 40 ]]
then
text+=
elif [[ $SIGNAL -lt 60 ]]
then
text+=
elif [[ $SIGNAL -lt 80 ]]
then
text+=
else
text+=
fi
}
grep gsm <<< $connection >/dev/null && {
MODEM=$(${modemmanager}/bin/mmcli -K -L | tail -1 | cut -d: -f2 | tr -d ' ')
STATUS=$(${modemmanager}/bin/mmcli -K -m $MODEM)
TECH=$(grep "modem.generic.access-technologies.value\[1\]" <<< $STATUS | cut -d: -f2 | tr -d ' ')
SIGNAL=$(grep "modem.generic.signal-quality.value" <<< $STATUS | cut -d: -f2 | tr -d ' ')
if [[ $SIGNAL -lt 20 ]]
then
text+=""
elif [[ $SIGNAL -lt 40 ]]
then
text+=""
elif [[ $SIGNAL -lt 60 ]]
then
text+=""
elif [[ $SIGNAL -lt 80 ]]
then
text+=""
else
text+=""
fi
if [[ $TECH == lte ]]
then
text+=""
else
text+=""
fi
}
grep ethernet <<< $connection > /dev/null && text+=""
done
code=0
[[ $text == "" ]] && {
text=
code=33
}
echo "<span font='${iconfont}'>$text</span>"
exit $code
''