Move polybar scripts to config directory

This commit is contained in:
Marty Oehme 2019-12-02 20:33:37 +01:00
parent 78a008c738
commit f3460e6ff1
6 changed files with 86 additions and 70 deletions

View file

@ -201,7 +201,7 @@ bindsym $mod+Shift+r restart
exec_always --no-startup-id feh --bg-scale ~/pictures/wall.jpg
# launch polybar (script ensures only 1 instance existing at a time)
exec_always --no-startup-id poly-launch
exec_always --no-startup-id polybar-launch
# default workspaces for most used apps
# assign [class="^qutebrowser$"] → number 1

View file

@ -190,7 +190,7 @@ label = %date% %{T2}%{T-}%time%
[module/archupdates]
type = custom/script
exec = poly-archupdates
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-archupdates
interval = 600
format = <label>
format-foreground = ${colors.primary}
@ -198,7 +198,7 @@ label = %output%
[module/networkspeed]
type = custom/script
exec = poly-networkspeed
exec = $XDG_CONFIG_HOME/polybar/scripts/poly-networkspeed
tail = true
; vim:ft=dosini

View file

@ -0,0 +1,83 @@
#!/bin/bash
INTERVAL=3
# interfaces for desktop and laptop
INTERFACES="enp6s0 wlp0s29u1u1 wlp56s0"
print_bytes() {
if [ "$1" -eq 0 ] || [ "$1" -lt 1000 ]; then
bytes="0"
elif [ "$1" -lt 1000000 ]; then
bytes="$(echo "scale=0;$1/1000" | bc -l)k"
else
bytes="$(echo "scale=1;$1/1000000" | bc -l)M"
fi
echo "$bytes"
}
print_bit() {
if [ "$1" -eq 0 ] || [ "$1" -lt 10 ]; then
bit="0 B"
elif [ "$1" -lt 100 ]; then
bit="$(echo "scale=0;$1*8" | bc -l) B"
elif [ "$1" -lt 100000 ]; then
bit="$(echo "scale=0;$1*8/1000" | bc -l) K"
else
bit="$(echo "scale=1;$1*8/1000000" | bc -l) M"
fi
echo "$bit"
}
declare -A bytes
get_initial_throughput() {
for interface in $INTERFACES; do
local dir="/sys/class/net/$interface"
if [ -d "$dir" ]; then
bytes[past_rx_$interface]="$(cat "$dir"/statistics/rx_bytes)"
bytes[past_tx_$interface]="$(cat "$dir"/statistics/tx_bytes)"
fi
done
}
get_throughput() {
while true; do
down=0
up=0
for interface in $INTERFACES; do
local dir="/sys/class/net/$interface"
if [ -d "$dir" ]; then
bytes[now_rx_$interface]="$(cat "$dir"/statistics/rx_bytes)"
bytes[now_tx_$interface]="$(cat "$dir"/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]}
fi
done
if [ "$down" -gt 1000 ] || [ "$up" -gt 1000 ]; then
echo " $(print_bytes $down) 祝$(print_bytes $up)"
else
echo ""
fi
# echo "Download: $(print_bytes $down) / Upload: $(print_bytes $up)"
# echo "Download: $(print_bit $down) / Upload: $(print_bit $up)"
sleep $INTERVAL
done
}
get_initial_throughput
get_throughput

View file

@ -1,67 +0,0 @@
#!/bin/bash
INTERVAL=3
INTERFACES="enp6s0 wlp0s29u1u1"
print_bytes() {
if [ "$1" -eq 0 ] || [ "$1" -lt 1000 ]; then
bytes="0"
elif [ "$1" -lt 1000000 ]; then
bytes="$(echo "scale=0;$1/1000" | bc -l)k"
else
bytes="$(echo "scale=1;$1/1000000" | bc -l)M"
fi
echo "$bytes"
}
print_bit() {
if [ "$1" -eq 0 ] || [ "$1" -lt 10 ]; then
bit="0 B"
elif [ "$1" -lt 100 ]; then
bit="$(echo "scale=0;$1*8" | bc -l) B"
elif [ "$1" -lt 100000 ]; then
bit="$(echo "scale=0;$1*8/1000" | bc -l) K"
else
bit="$(echo "scale=1;$1*8/1000000" | bc -l) M"
fi
echo "$bit"
}
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
if [ "$down" -gt 1000 ] || [ "$up" -gt 1000 ]; then
echo " $(print_bytes $down) 祝$(print_bytes $up)"
else
echo ""
fi
# echo "Download: $(print_bytes $down) / Upload: $(print_bytes $up)"
# echo "Download: $(print_bit $down) / Upload: $(print_bit $up)"
sleep $INTERVAL
done