From 41d32c0af3c91bf95e072e141b73aa44c07effe5 Mon Sep 17 00:00:00 2001 From: adrianmihalko Date: Thu, 23 Dec 2021 00:50:24 +0100 Subject: [PATCH 1/3] Ping plugin --- INSTALL.md | 11 ++++++++++- scripts/dracula.sh | 6 ++++++ scripts/network_ping.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 scripts/network_ping.sh 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..fb70c92 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -163,6 +163,12 @@ 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") + #tmux set-option -g status-right-length 250 + 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..2cc17bf --- /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 + ;; + + 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 From 45ad8cdafdc53dbe0342123266f45a9f5e3123dc Mon Sep 17 00:00:00 2001 From: adrianmihalko Date: Thu, 23 Dec 2021 00:51:47 +0100 Subject: [PATCH 2/3] Update dracula.sh --- scripts/dracula.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index fb70c92..2b5e1f4 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -165,7 +165,6 @@ main() if [ $plugin = "network-ping" ]; then IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray") - #tmux set-option -g status-right-length 250 script="#($current_dir/network_ping.sh)" fi From a0987b8b963c9a3a213057f656d1a341b7fc6520 Mon Sep 17 00:00:00 2001 From: adrianmihalko Date: Thu, 23 Dec 2021 00:55:35 +0100 Subject: [PATCH 3/3] Update network_ping.sh --- scripts/network_ping.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh index 2cc17bf..442f6be 100644 --- a/scripts/network_ping.sh +++ b/scripts/network_ping.sh @@ -15,7 +15,7 @@ ping_function() { # 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 + echo "$pingtime ms" ;; CYGWIN* | MINGW32* | MSYS* | MINGW*)