updated network script

This commit is contained in:
2025-09-08 03:17:41 +02:00
parent 653591289d
commit 8e5a15395a
2 changed files with 22 additions and 3 deletions

View File

@@ -24,6 +24,13 @@ device {
kb_variant = dvorak-intl
}
device {
name = topre-corporation-hhkb-professional
resolve_binds_by_sym = 1
kb_layout = us
kb_variant = dvorak-intl
}
# https://wiki.hyprland.org/Configuring/Variables/#gestures
gestures {
workspace_swipe = false

View File

@@ -3,8 +3,10 @@
# Path for the temporary file to store previous stats
STATS_FILE="/tmp/waybar_net_stats"
# Find the default network interface
INTERFACE=$(ip route | grep '^default' | awk '{print $5}' | head -n1)
# Find the primary default network interface by sorting routing metrics.
# This correctly prioritizes a VPN connection when it's active.
INTERFACE_INFO=$(ip route list | grep '^default' | sort -k 9 -n | head -n1)
INTERFACE=$(echo "$INTERFACE_INFO" | awk '{print $5}')
# Exit if no active interface is found
if [ -z "$INTERFACE" ]; then
@@ -46,5 +48,15 @@ echo "PREV_TIME=$TIME_NOW" > "$STATS_FILE"
echo "PREV_RX_BYTES=$RX_BYTES_NOW" >> "$STATS_FILE"
echo "PREV_TX_BYTES=$TX_BYTES_NOW" >> "$STATS_FILE"
# Format the main output string
OUTPUT_TEXT="$INTERFACE ($IP_ADDR):  ${RX_MBPS} MB/s  ${TX_MBPS} MB/s"
# Prepend a VPN icon if a common VPN interface is active
case "$INTERFACE" in
tun*|wg*|ppp*|pvpn*)
OUTPUT_TEXT="$OUTPUT_TEXT"
;;
esac
# Output JSON for Waybar
echo "{\"text\": \"$INTERFACE ($IP_ADDR):  ${RX_MBPS} MB/s  ${TX_MBPS} MB/s\"}"
echo "{\"text\": \"$OUTPUT_TEXT\"}"