Merge pull request #144 from adrianmihalko/master

Ping plugin
This commit is contained in:
Ethan Edwards 2021-12-23 09:58:01 -05:00 committed by GitHub
commit a966029b99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View file

@ -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

View file

@ -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

35
scripts/network_ping.sh Normal file
View file

@ -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