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

67 lines
1.8 KiB
Nix
Raw Normal View History

2022-09-01 23:10:23 +04:00
{ bash, gnugrep, coreutils-full, util-linux, networkmanager, iconfont, config, modemmanager, lib, ... }: ''
2020-02-17 17:00:59 +04:00
#!${bash}/bin/bash
2022-09-01 23:10:23 +04:00
PATH=$PATH:${lib.makeBinPath [ networkmanager coreutils-full gnugrep modemmanager util-linux.bin ]}
export PATH
CONNECTIONS=$(nmcli con show --active | tail +2 | tr -s ' ' | rev | cut -d' ' -f3 | rev)
2020-02-17 17:00:59 +04:00
text=""
for connection in $CONNECTIONS
do
grep wifi <<< $connection > /dev/null && {
2020-07-27 01:16:19 +04:00
# 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
text=
2020-02-17 17:00:59 +04:00
}
grep gsm <<< $connection >/dev/null && {
2022-09-01 23:10:23 +04:00
MODEM=$(mmcli -K -L | tail -1 | cut -d: -f2 | tr -d ' ')
STATUS=$(mmcli -K -m $MODEM)
2020-02-17 17:00:59 +04:00
TECH=$(grep "modem.generic.access-technologies.value\[1\]" <<< $STATUS | cut -d: -f2 | tr -d ' ')
2020-07-27 01:16:19 +04:00
# 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
text+=
2020-02-17 17:00:59 +04:00
if [[ $TECH == lte ]]
then
2020-07-27 01:16:19 +04:00
text+=""
2020-02-17 17:00:59 +04:00
else
2020-07-27 01:16:19 +04:00
text+=""
2020-02-17 17:00:59 +04:00
fi
}
2020-07-27 01:16:19 +04:00
grep ethernet <<< $connection > /dev/null && text+=""
2020-02-17 17:00:59 +04:00
done
code=0
[[ $text == "" ]] && {
2020-07-27 01:16:19 +04:00
text=
2020-02-17 17:00:59 +04:00
code=33
}
echo "<span font='${iconfont}'>$text</span>"
exit $code
''