feat: add network name support

This commit is contained in:
Abhishek Keshri 2023-03-29 14:52:04 +05:30
parent 3837498239
commit 54ecf3dc0b
No known key found for this signature in database
GPG key ID: 62BD6AA2E913B3D3

View file

@ -1,23 +1,28 @@
#!/usr/bin/env bash
#!/bin/bash
INTERVAL="1" # update interval in seconds
# Network interface to monitor
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$current_dir"/utils.sh
# Network interface to monitor
network_name="en0"
if [[ $(uname -s) == "Darwin" ]]; then
network_name="en0" # en0 is wifi, TODO: Update network_name
network_name=$(get_tmux_option "@tmux2k-network-name" "en0")
elif [[ $(uname -s) == "Linux" ]]; then
network_name=$(tmux show-option -gqv "@dracula-network-bandwidth")
network_name=$(get_tmux_option "@tmux2k-network-name" "wlo1")
else
# update this later for window
# TODO: update this for windows
echo "Unknown operating system"
exit 1
fi
network_name=$(get_tmux_option "@tmux2k-network-name" "en0")
main() {
while true
do
while true; do
output_download=""
output_upload=""
output_download_unit=""
@ -41,13 +46,13 @@ main() {
final_upload=$(netstat -I "$network_name" -b | tail -n 1 | awk '{print $10}')
fi
total_download_bps=$(expr $final_download - $initial_download)
total_upload_bps=$(expr $final_upload - $initial_upload)
total_download_bps=$(expr "$final_download" - "$initial_download")
total_upload_bps=$(expr "$final_upload" - "$initial_upload")
if [ $total_download_bps -gt 1073741824 ]; then
if [ "$total_download_bps" -gt 1073741824 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_download_unit="gB/s"
elif [ $total_download_bps -gt 1048576 ]; then
elif [ "$total_download_bps" -gt 1048576 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_download_unit="mB/s"
else
@ -55,10 +60,10 @@ main() {
output_download_unit="kB/s"
fi
if [ $total_upload_bps -gt 1073741824 ]; then
if [ "$total_upload_bps" -gt 1073741824 ]; then
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_upload_unit="gB/s"
elif [ $total_upload_bps -gt 1048576 ]; then
elif [ "$total_upload_bps" -gt 1048576 ]; then
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_upload_unit="mB/s"
else