tmux2k/scripts/ping.sh

28 lines
607 B
Bash
Raw Permalink Normal View History

2022-08-09 06:28:35 +05:30
#!/usr/bin/env bash
2024-03-17 04:00:27 +05:30
export LC_ALL=en_US.UTF-8
2022-08-09 06:28:35 +05:30
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2022-08-13 17:11:48 +05:30
source "$current_dir"/utils.sh
2022-08-09 06:28:35 +05:30
ping_function() {
2023-03-29 14:52:27 +05:30
case $(uname -s) in
Linux | Darwin)
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"
;;
2022-08-09 06:28:35 +05:30
2024-03-17 04:00:27 +05:30
CYGWIN* | MINGW32* | MSYS* | MINGW*) ;; # TODO - windows compatability
2023-03-29 14:52:27 +05:30
esac
2022-08-09 06:28:35 +05:30
}
main() {
2023-03-29 14:52:27 +05:30
echo "$(ping_function)"
RATE=$(get_tmux_option "@tmux2k-ping-rate" 5)
sleep "$RATE"
2022-08-09 06:28:35 +05:30
}
main