/ scripts / network_ping.sh
network_ping.sh
 1  #!/usr/bin/env bash
 2  # setting the locale, some users have issues with different locales, this forces the correct one
 3  export LC_ALL=en_US.UTF-8
 4  
 5  # configuration
 6  # @dracula-ping-server "example.com"
 7  # @dracula-ping-rate 5
 8  
 9  current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10  source $current_dir/utils.sh
11  
12  ping_function() {
13    case $(uname -s) in
14    Linux | Darwin)
15      # storing the hostname/IP in the variable PINGSERVER, default is google.com
16      pingserver=$(get_tmux_option "@dracula-ping-server" "google.com")
17      pingtime=$(ping -c 1 "$pingserver" | tail -1 | awk '{print $4}' | cut -d '/' -f 2)
18      echo "$pingtime ms"
19      ;;
20  
21    CYGWIN* | MINGW32* | MSYS* | MINGW*)
22      # TODO - windows compatability
23      ;;
24    esac
25  }
26  
27  main() {
28  
29    echo $(ping_function)
30    RATE=$(get_tmux_option "@dracula-ping-rate" 5)
31    sleep $RATE
32  }
33  
34  # run main driver
35  main