From 42246125a40e0cfaa40692ec29d701185f9efa20 Mon Sep 17 00:00:00 2001 From: Abhishek Keshri Date: Tue, 9 Aug 2022 06:28:35 +0530 Subject: [PATCH] Add network_ping.sh --- scripts/network_ping.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/network_ping.sh diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh new file mode 100644 index 0000000..e4692bc --- /dev/null +++ b/scripts/network_ping.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# setting the locale, some users have issues with different locales, this forces the correct one +export LC_ALL=en_US.UTF-8 + +# configuration +# @tmux2k-ping-server "example.com" +# @tmux2k-ping-rate 5 + +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source $current_dir/utils.sh + +ping_function() { + case $(uname -s) in + Linux | Darwin) + # storing the hostname/IP in the variable PINGSERVER, default is google.com + pingserver=$(get_tmux_option "@tmux2k-ping-server" "google.com") + pingtime=$(ping -c 1 "$pingserver" | tail -1 | awk '{print $4}' | cut -d '/' -f 2) + echo "$pingtime ms" + ;; + + CYGWIN* | MINGW32* | MSYS* | MINGW*) + # TODO - windows compatability + ;; + esac +} + +main() { + + echo $(ping_function) + RATE=$(get_tmux_option "@tmux2k-ping-rate" 5) + sleep $RATE +} + +# run main driver +main