Closed emmagamma closed 9 months ago
And here's a little demo of it working, side-by-side with activity monitor:
https://github.com/dracula/tmux/assets/5084142/603a3c3f-5c2a-4baa-bba9-c6e1fd36418b
you'll notice activity monitor updates more frequently than once per second, so it's showing a higher-resolution picture of your traffic and may occasionally display higher and lower spikes for tx/rx compared to the network-bandwidth in tmux. but overall they both give a very accurate indication of your traffic.
This is wonderful, thank you so much! I definitely agree that it is more reasonable to expect awk
to be installed. I have noticed that bc
is not installed on many systems. No need to squash commits, everything is very clean and well written.
sweet! wow that was incredibly fast haha I totally expected more back and forth, thanks for the quick merge <3
sweet! wow that was incredibly fast haha I totally expected more back and forth, thanks for the quick merge <3
You got everything right the first time! That's pretty rare around these parts ;). I can tell that you poked around the codebase to see what the code standards are, I'm impressed. Thanks again.
So I went to enable network-bandwidth (on a mac) and noticed this wasn't supported yet, but it was only after getting some custom changes working locally that I even thought to check if there was already a PR for it haha.
I see #113 exists already, but it looks like the person who made that PR just got busy with work and hasn't had time to address all the feedback and resolve the conflicts, and progress seems to have stalled on that several years ago - so I really hope I'm not stepping on any toes by making a separate PR for the same feature, but I'd really love to get this merged into the repo so that I don't need to run a modified version of this repo and manually keep it in sync with my local changes when I update to newer versions.
please let me know if there's anything I should change, happy to ^.^ (I figure you'll probably want me to squash the commits, but I'll leave them as-is for now, for convenience)
and some notes to hopefully make reviewing this a bit easier:
route
instead ofip
to get the interface name on Darwin Architectures, which is installed by default on macOS.netstat
to get the tx and rx bytes, except instead of calling netstat twice, we can just do it once and return both values at the same time.interface_bytes
fn to no longer require a second argument ($2 which would always either be "tx" or "rx"), so instead now it just gets the interface name from $1 (the first argument) and returns BOTH the tx and rx bytes for that interface, in the format: "TX_Bytes RX_Bytes" where the upload (tx) bytes are listed first, as is the convention elsewhere, and then a whitespace character followed by the download (rx) bytes. This lets us reduce the number of calls tointerface_bytes
per interval from 4 to 2 while also making the code inget_bandwidth
a bit simpler and easier to read.bc
to useawk
for floating point math, the "%.2f" limits the output of printf to two decimal places. I believe it should be reasonable to expect awk to be installed already on most OS's and the repo's existing patterns seem to agree but please lmk if that's not a sound assumption.