Skip to content

Commit 41d32c0

Browse files
committed
Ping plugin
1 parent 5535270 commit 41d32c0

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

INSTALL.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ To enable plugins set up the `@dracula-plugins` option in you `.tmux.conf` file,
4848
The order that you define the plugins will be the order on the status bar left to right.
4949

5050
```bash
51-
# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, weather, time
51+
# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, weather, time
5252
set -g @dracula-plugins "cpu-usage gpu-usage ram-usage"
5353
```
5454

@@ -144,6 +144,15 @@ Customize label
144144
set -g @dracula-ram-usage-label "RAM"
145145
```
146146

147+
#### network-ping options
148+
149+
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.
150+
151+
```bash
152+
set -g @dracula-ping-server "google.com"
153+
set -g @dracula-ping-rate 5
154+
```
155+
147156
#### time options
148157

149158
Disable timezone

scripts/dracula.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ main()
163163
script="#($current_dir/network_bandwidth.sh)"
164164
fi
165165

166+
if [ $plugin = "network-ping" ]; then
167+
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray")
168+
#tmux set-option -g status-right-length 250
169+
script="#($current_dir/network_ping.sh)"
170+
fi
171+
166172
if [ $plugin = "weather" ]; then
167173
# wait unit $datafile exists just to avoid errors
168174
# this should almost never need to wait unless something unexpected occurs

scripts/network_ping.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy