Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bandwidth_primary.1s.sh #1566

Merged
merged 5 commits into from
Jan 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Network/bandwidth_primary.1s.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
# <xbar.version>v0.0.1</xbar.version>
# <xbar.author>Kaspars Mickevics</xbar.author>
# <xbar.author.github>fxlv</xbar.author.github>
# <xbar.desc>Displays bandwidth usage for the primary interface in Megabits/s</xbar.desc>
# <xbar.desc>Displays bandwidth usage for a network interface in Megabits/s</xbar.desc>
# <xbar.dependencies>ifstat</xbar.dependencies>
# <xbar.image>https://cloud.githubusercontent.com/assets/2462211/12748504/584bbcea-c9b3-11e5-8109-ad8fdcefdc75.png</xbar.image>
# <xbar.var>string(VAR_NETWORK_INTERFACE="en0"): The interface to track (Usual interface for MacOS wifi is en0)</xbar.var>

# based on bandwidth.1s.sh by Ant Cosentino

# only gather stats from interface en0
# no need to samlpe unused interfaces
INTERFACE="en0"


if [ ! -e /usr/local/bin/ifstat ]; then
echo "Please install ifstat or change the path to it in the script."
Expand All @@ -26,10 +23,10 @@ function kilo_to_mega {
}

function get_ifstat {
interface=$1
IFSTAT_INTERFACE=$1
# 1 sample for 0.5 second interval
# outputs two values (in/out) in kilobits per second
/usr/local/bin/ifstat -n -w -i "${interface}" -b 0.5 1 | tail -n 1
/usr/local/bin/ifstat -n -w -i "${IFSTAT_INTERFACE}" -b 0.5 1 | tail -n 1
}

function print_ifstat {
Expand All @@ -41,5 +38,5 @@ function print_ifstat {

}

print_ifstat "$(get_ifstat ${INTERFACE})"
print_ifstat "$(get_ifstat ${VAR_NETWORK_INTERFACE})"
echo "---"