power menu, redshift, polybar

This commit is contained in:
azpsen
2024-01-28 16:37:10 -06:00
parent 89516a6ce1
commit 319b44ecbd
307 changed files with 7642 additions and 5 deletions

View File

@@ -0,0 +1,25 @@
# Script: network-traffic
A script that displays the current network traffic.
It allows you to count traffic from more then one interface.
## Dependencies
* `bc`
## Configuration
Change the values in `INTERVAL` and `INTERFACES`. You can also choose between bit and byte output.
## Module
```ini
[module/network-traffic]
type = custom/script
exec = ~/polybar-scripts/network-traffic.sh
tail = true
```

View File

@@ -0,0 +1,61 @@
#!/bin/bash
print_bytes() {
if [ "$1" -eq 0 ] || [ "$1" -lt 1000 ]; then
bytes="0 kB/s"
elif [ "$1" -lt 1000000 ]; then
bytes="$(echo "$1/1000" | bc -l | LANG=C xargs printf "%.f\n") kB/s"
else
bytes="$(echo "$1/1000000" | bc -l | LANG=C xargs printf "%.1f\n") MB/s"
fi
echo "$bytes"
}
print_bit() {
if [ "$1" -eq 0 ] || [ "$1" -lt 10 ]; then
bit="0 B"
elif [ "$1" -lt 100 ]; then
bit="$(echo "$1*8" | bc -l | LANG=C xargs printf "%.f\n") B"
elif [ "$1" -lt 100000 ]; then
bit="$(echo "$1*8/1000" | bc -l | LANG=C xargs printf "%.f\n") K"
else
bit="$(echo "$1*8/1000000" | bc -l | LANG=C xargs printf "%.1f\n") M"
fi
echo "$bit"
}
INTERVAL=10
INTERFACES="enp0s25 wlp3s0"
declare -A bytes
for interface in $INTERFACES; do
bytes[past_rx_$interface]="$(cat /sys/class/net/"$interface"/statistics/rx_bytes)"
bytes[past_tx_$interface]="$(cat /sys/class/net/"$interface"/statistics/tx_bytes)"
done
while true; do
down=0
up=0
for interface in $INTERFACES; do
bytes[now_rx_$interface]="$(cat /sys/class/net/"$interface"/statistics/rx_bytes)"
bytes[now_tx_$interface]="$(cat /sys/class/net/"$interface"/statistics/tx_bytes)"
bytes_down=$(((${bytes[now_rx_$interface]} - ${bytes[past_rx_$interface]}) / INTERVAL))
bytes_up=$(((${bytes[now_tx_$interface]} - ${bytes[past_tx_$interface]}) / INTERVAL))
down=$(( "$down" + "$bytes_down" ))
up=$(( "$up" + "$bytes_up" ))
bytes[past_rx_$interface]=${bytes[now_rx_$interface]}
bytes[past_tx_$interface]=${bytes[now_tx_$interface]}
done
echo "Download: $(print_bytes $down) / Upload: $(print_bytes $up)"
# echo "Download: $(print_bit $down) / Upload: $(print_bit $up)"
sleep $INTERVAL
done