dotfiles

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 1379747a1756f613584ab804c3332e1e42d245bb
parent 406bb4faa7899b54ae6a6b4a1e94b009004ad79b
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Fri, 29 May 2020 16:03:19 -0400

minimize file writes and use built-in arithmatic

Diffstat:
M.local/bin/statusbar/nettraf | 16+++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/.local/bin/statusbar/nettraf b/.local/bin/statusbar/nettraf @@ -10,16 +10,14 @@ case "$BLOCK_BUTTON" in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -rxfile="${XDG_CACHE_HOME:-$HOME/.cache}/rxlog" -txfile="${XDG_CACHE_HOME:-$HOME/.cache}/txlog" +logfile="${XDG_CACHE_HOME:-$HOME/.cache}/netlog" +prevdata="$(cat "$logfile")" -rxcurrent="$(cat /sys/class/net/*/statistics/rx_bytes | paste -sd '+' | bc)" -txcurrent="$(cat /sys/class/net/*/statistics/tx_bytes | paste -sd '+' | bc)" +rxcurrent="$(($(cat /sys/class/net/*/statistics/rx_bytes | paste -sd '+')))" +txcurrent="$(($(cat /sys/class/net/*/statistics/tx_bytes | paste -sd '+')))" printf "🔻%sKiB 🔺%sKiB\\n" \ - "$(printf -- "(%s-%s)/1024\\n" "$rxcurrent" "$(cat "$rxfile")" | bc)" \ - "$(printf -- "(%s-%s)/1024\\n" "$txcurrent" "$(cat "$txfile")" | bc)" + "$(((rxcurrent-${prevdata%% *})/1024))" \ + "$(((txcurrent-${prevdata##* })/1024))" -# Log the current values for next run. -echo "$rxcurrent" > "$rxfile" -echo "$txcurrent" > "$txfile" +echo "$rxcurrent $txcurrent" > "$logfile"