updated nvim init.lua and waybar network module

This commit is contained in:
2025-08-29 14:38:51 +02:00
parent 251b5a5eeb
commit 653591289d
4 changed files with 97 additions and 126 deletions

View File

@@ -3,14 +3,14 @@
"layer": "top",
"position": "top",
"output": "eDP-1",
"height": 40,
"height": 30,
"modules-left": ["hyprland/workspaces"],
"modules-center": [],
"modules-right": [
"custom/pixelbuds_pro",
"wireplumber",
"custom/audio-output",
"network",
"custom/network",
"custom/mem",
"custom/cpu",
"custom/disk-root",
@@ -51,7 +51,7 @@
},
"wireplumber": {
"format": "{volume}% {icon}",
"format-muted": "--- ",
"format-muted": "",
"format-icons": {
"headphone": "",
"hands-free": "",
@@ -87,7 +87,7 @@
},
"tray": {
"icon-size": 18,
"spacing": 10
"spacing": 6
},
"custom/power": {
"format": "",
@@ -192,19 +192,25 @@
"return-type": "json",
"exec": "~/.config/waybar/scripts/disk_info.sh ~/games",
"interval": 30
},
"custom/network": {
"exec": "~/.config/waybar/scripts/network.sh",
"interval": 2, // in seconds
"format": "{}",
"return-type": "json"
}
},{
"layer": "top",
"position": "top",
"output": "!eDP-1",
"height": 40,
"height": 30,
"modules-left": ["hyprland/workspaces"],
"modules-center": [],
"modules-right": [
// "custom/pixelbuds_pro",
"wireplumber",
"custom/audio-output",
"network",
"custom/network",
"custom/mem",
"custom/cpu",
"custom/disk-root",
@@ -245,7 +251,7 @@
},
"wireplumber": {
"format": "{volume}% {icon}",
"format-muted": "--- ",
"format-muted": "",
"format-icons": {
"headphone": "",
"hands-free": "",
@@ -281,7 +287,7 @@
},
"tray": {
"icon-size": 18,
"spacing": 10
"spacing": 6
},
"custom/power": {
"format": "",
@@ -386,5 +392,11 @@
"return-type": "json",
"exec": "~/.config/waybar/scripts/disk_info.sh ~/games",
"interval": 30
},
"custom/network": {
"exec": "~/.config/waybar/scripts/network.sh",
"interval": 2, // in seconds
"format": "{}",
"return-type": "json"
}
}]

50
waybar/scripts/network.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
# 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)
# Exit if no active interface is found
if [ -z "$INTERFACE" ]; then
echo "{\"text\": \"No connection\"}"
exit 0
fi
# Get the IP address for the interface
IP_ADDR=$(ip -4 addr show "$INTERFACE" | grep -oP 'inet \K[\d.]+')
# Get current time and byte counts
TIME_NOW=$(date +%s)
RX_BYTES_NOW=$(cat "/sys/class/net/$INTERFACE/statistics/rx_bytes")
TX_BYTES_NOW=$(cat "/sys/class/net/$INTERFACE/statistics/tx_bytes")
# Initialize speeds to 0
RX_MBPS="0.00"
TX_MBPS="0.00"
# Read previous values if the stats file exists
if [ -f "$STATS_FILE" ]; then
source "$STATS_FILE" # This loads PREV_TIME, PREV_RX_BYTES, PREV_TX_BYTES
fi
# Calculate speed if we have previous data and time has passed
if [ -n "$PREV_TIME" ] && [ "$TIME_NOW" -gt "$PREV_TIME" ]; then
TIME_DIFF=$((TIME_NOW - PREV_TIME))
RX_BPS=$(( (RX_BYTES_NOW - PREV_RX_BYTES) / TIME_DIFF ))
TX_BPS=$(( (TX_BYTES_NOW - PREV_TX_BYTES) / TIME_DIFF ))
# Using printf for better formatting (forces two decimal places)
RX_MBPS=$(printf "%.2f" "$(echo "$RX_BPS / 1024 / 1024" | bc -l)")
TX_MBPS=$(printf "%.2f" "$(echo "$TX_BPS / 1024 / 1024" | bc -l)")
fi
# Save current values for the next run
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"
# Output JSON for Waybar
echo "{\"text\": \"$INTERFACE ($IP_ADDR):  ${RX_MBPS} MB/s  ${TX_MBPS} MB/s\"}"

View File

@@ -11,7 +11,7 @@
window#waybar {
background-color: alpha(@base, 0.4);
padding: 10px;
padding: 4px;
transition-property: background-color;
transition-duration: 0.5s;
color: @text;
@@ -28,7 +28,7 @@ window#waybar.hidden {
/* Fix weird spacing in materia (waybar #450) */
box-shadow: inset 0 -3px transparent;
/* Use box-shadow instead of border so the text isn't offset */
padding: 6px 18px;
padding: 0px 12px;
margin: 0px 3px;
border-radius: 10px;
background-color: @base;
@@ -62,6 +62,7 @@ window#waybar.hidden {
#battery,
#backlight,
#wireplumber,
#custom-network,
#network,
#clock,
#tray,
@@ -76,7 +77,7 @@ window#waybar.hidden {
#custom-gpu-screen-recorder {
border-radius: 10px;
margin: 0px 3px;
padding: 6px 12px;
padding: 0px 6px;
background-color: @base;
color: @text;
}
@@ -88,19 +89,19 @@ window#waybar.hidden {
}
#custom-pixelbuds_pro.disconnected {
padding-right: 16px;
padding-left: 12px;
padding-right: 10px;
padding-left: 8px;
}
#custom-gpu-screen-recorder,
#custom-gpu-screen-recorder.recording {
padding-right: 18px;
padding-left: 10px;
padding-right: 12px;
padding-left: 4px;
}
#custom-gamemode {
padding-right: 15px;
padding-left: 11px;
padding-right: 9px;
padding-left: 5px;
}
#custom-pixelbuds_pro.anc-active {
@@ -141,7 +142,7 @@ window#waybar.hidden {
}
#custom-tlp {
padding: 0 10px;
padding: 0 4px;
min-width: 10px;
}
@@ -206,6 +207,7 @@ window#waybar.hidden {
#cpu,
#disk,
#network,
#custom-network,
#custom-gpu.normal,
#custom-cpu.normal,
#custom-mem.normal,
@@ -224,7 +226,7 @@ window#waybar.hidden {
}
#wireplumber {
padding-right: 16px;
padding-right: 10px;
}
#custom-audio-output.unmuted, #wireplumber {
@@ -237,12 +239,12 @@ window#waybar.hidden {
}
#network {
padding-right: 15px;
padding-right: 9px;
}
tooltip {
border-radius: 10px;
padding: 15px;
padding: 9px;
background-color: @base;
}