diff --git a/INSTALL.md b/INSTALL.md index 93615ea..e9d092b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -48,7 +48,7 @@ To enable plugins set up the `@dracula-plugins` option in you `.tmux.conf` file, The order that you define the plugins will be the order on the status bar left to right. ```bash -# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, weather, time +# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, weather, time set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" ``` @@ -144,6 +144,15 @@ Customize label set -g @dracula-ram-usage-label "RAM" ``` +#### network-ping options + +You can configure which server (hostname, IP) you want to ping and at which rate (in seconds). Default is google.com at every 5 seconds. + +```bash +set -g @dracula-ping-server "google.com" +set -g @dracula-ping-rate 5 +``` + #### time options Disable timezone diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 5637bf6..2b5e1f4 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -163,6 +163,11 @@ main() script="#($current_dir/network_bandwidth.sh)" fi + if [ $plugin = "network-ping" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray") + script="#($current_dir/network_ping.sh)" + fi + if [ $plugin = "weather" ]; then # wait unit $datafile exists just to avoid errors # this should almost never need to wait unless something unexpected occurs diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh new file mode 100644 index 0000000..442f6be --- /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 +# @dracula-ping-server "example.com" +# @dracula-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 "@dracula-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 "@dracula-ping-rate" 5) + sleep $RATE +} + +# run main driver +main