tmux-kanagawa/scripts/network_ping.sh

36 lines
856 B
Bash
Raw Permalink Normal View History

2021-12-23 00:50:24 +01:00
#!/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
# @kanagawa-ping-server "example.com"
# @kanagawa-ping-rate 5
2021-12-23 00:50:24 +01:00
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 "@kanagawa-ping-server" "google.com")
2021-12-23 00:50:24 +01:00
pingtime=$(ping -c 1 "$pingserver" | tail -1 | awk '{print $4}' | cut -d '/' -f 2)
2021-12-23 00:55:35 +01:00
echo "$pingtime ms"
2021-12-23 00:50:24 +01:00
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
# TODO - windows compatability
;;
esac
}
main() {
echo $(ping_function)
RATE=$(get_tmux_option "@kanagawa-ping-rate" 5)
2021-12-23 00:50:24 +01:00
sleep $RATE
}
# run main driver
main