dotfiles/de/home/.config/eww/scripts/bar/networking
2025-09-01 01:00:01 -07:00

62 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
function ifstatus(){
is_online=false
is_wireless=false
is_ethernet=false
is_vpn=false
is_proton=false
is_proton_sc=false
is_homevpn=false
is_homevpn_full=false
if nmcli -g TYPE connection show --active | grep -q "wireless";then
is_wireless='true'
fi
if nmcli -g TYPE connection show --active | grep -q "ethernet";then
is_ethernet='true'
fi
vpn_cons=$(nmcli -g TYPE,NAME connection show --active | grep -e "vpn" -e "wireguard")
# echo "${vpn_cons//$'\n'/;}"
case "${vpn_cons//$'\n'/;}" in
*ProtonVPN|*ProtonVPN\;*)
is_proton='true'
;;&
*ProtonVPN-SC|*ProtonVPN-SC\;*)
is_proton_sc='true'
;;&
*HomeVPN|*HomeVPN\;*)
is_homevpn='true'
;;&
*HomeVPN-Full|*HomeVPN-Full\;*)
is_homevpn_full='true'
;;&
*ProtonVPN*|*ProtonVPN-SC*|*HomeVPN*|*HomeVPN-Full*)
is_vpn='true'
;;
esac
# if grep -qe "ProtonVPN$" <<<${vpn_cons};then
# is_proton='true'
# fi
# if grep -qe "ProtonVPN-SC$" <<<${vpn_cons};then
# is_proton_sc='true'
# fi
# if grep -qe "HomeVPN$" <<<${vpn_cons};then
# is_homevpn='true'
# fi
# if grep -qe "HomeVPN-Full$" <<<${vpn_cons};then
# is_homevpn_full='true'
# fi
echo $(jq -n --arg online "${is_online}" --arg wifi "${is_wireless}" --arg wired "${is_ethernet}" --arg vpn "${is_vpn}" --arg proton "${is_proton}" --arg proton_sc "${is_proton_sc}" --arg homevpn "${is_homevpn}" --arg homevpn_full "${is_homevpn_full}" '{online: $online, wifi: $wifi, wired: $wired, vpn: $vpn, proton: $proton, proton_sc: $proton_sc, homevpn: $homevpn, homevpn_full: $homevpn_full}')
}
ifstatus
ip monitor address | {
while read -r event; do
# echo hi ${event};
ifstatus
done;
}