nixos/home/common/optional/desktop/dwm/scripts/sb-network-status.nix

53 lines
1.4 KiB
Nix
Raw Normal View History

2024-06-14 21:48:43 +01:00
{ pkgs, ... }:
{
home.packages = with pkgs; [
(writeShellScriptBin "sb-network-status" ''
# Nerd Font Symbols
wifi_symbol=" "
lan_symbol="󰌗 "
disconnected_symbol="󰲜 "
vpn_symbol="󰖂 "
internet="󰞉 "
internet_disconnected="󰪎 "
# Get the network status
DEFAULT_INTERFACE=$(ip route | grep '^default' | awk '{print $5}' | uniq)
IP_ADDRESS=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')
if [ -z "$DEFAULT_INTERFACE" ]; then
network_symbol="$disconnected_symbol"
else
# Check if it is a wireless interface (wlan*)
if [[ $DEFAULT_INTERFACE == wl* ]]; then
network_symbol="$wifi_symbol"
else
network_symbol="$lan_symbol"
fi
fi
# Check internet connectivity
if ! ping -c 1 8.8.8.8 &> /dev/null;
then
network_symbol="$network_symbol $internet_disconnected"
else
network_symbol="$network_symbol $internet"
fi
if ip addr show tun0 > /dev/null 2>&1; then
network_symbol="$network_symbol $vpn_symbol"
else
network_symbol="$network_symbol"
fi
if [ -z "$IP_ADDRESS" ];
then
printf "$network_symbol"
else
printf "[$network_symbol|$IP_ADDRESS] "
2024-06-14 21:48:43 +01:00
fi
'')
];
}