Skip to content

Commit e25e7a3

Browse files
Merge pull request #100 from rodrigocnascimento/feat/network-bandwith
Network bandwith feature
2 parents f508a89 + 2b59061 commit e25e7a3

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

INSTALL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ programs.tmux = {
4747
Customize the status bar by adding any of these lines to your .tmux.conf as desired:
4848
* Disable battery functionality: `set -g @dracula-show-battery false`
4949
* Disable network functionality: `set -g @dracula-show-network false`
50+
* Enable network bandwith functionality: `set -g @dracula-network-bandwith $network_name`
51+
- You could get the `$network_name` through the command: `sudo lshw -class network -short | grep wl | awk '{print $2}'`
5052
* Disable weather functionality: `set -g @dracula-show-weather false`
5153
* Disable time functionality: `set -g @dracula-show-time false`
5254
* Disable location information: `set -g @dracula-show-location false`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
1717
* Support for powerline
1818
* Day, date, time, timezone
1919
* Current location based on network with temperature and forecast icon (if available)
20-
* Network connection status and SSID
20+
* Network connection status, bandwith and SSID
2121
* Battery percentage and AC power connection status
2222
* Refresh rate control
2323
* CPU usage

scripts/dracula.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ main()
3939
show_day_month=$(get_tmux_option "@dracula-day-month" false)
4040
show_time=$(get_tmux_option "@dracula-show-time" true)
4141
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
42+
show_network_bandwith=$(get_tmux_option "@dracula-network-bandwith" "")
4243

4344
# Dracula Color Pallette
4445
white='#f8f8f2'
@@ -113,7 +114,7 @@ main()
113114

114115
# set length
115116
tmux set-option -g status-left-length 100
116-
tmux set-option -g status-right-length 100
117+
tmux set-option -g status-right-length 100
117118

118119
# pane border styling
119120
if $show_border_contrast; then
@@ -167,6 +168,12 @@ main()
167168
powerbg=${cyan}
168169
fi
169170

171+
if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
172+
tmux set-option -g status-right-length 250
173+
tmux set-option -ga status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh)"
174+
powerbg=${green}
175+
fi
176+
170177
if $show_weather; then # weather
171178
tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #(cat $current_dir/../data/weather.txt)"
172179
powerbg=${orange}
@@ -211,6 +218,11 @@ main()
211218
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) "
212219
fi
213220

221+
if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
222+
tmux set-option -g status-right-length 250
223+
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) "
224+
fi
225+
214226
if $show_weather; then # weather
215227
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $current_dir/../data/weather.txt) "
216228
fi

scripts/network_bandwith.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
INTERVAL="1" # update interval in seconds
4+
5+
network_name=$(tmux show-option -gqv "@dracula-network-bandwith")
6+
7+
main() {
8+
while true
9+
do
10+
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
11+
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
12+
13+
sleep $INTERVAL
14+
15+
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
16+
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
17+
18+
total_download_bps=$(expr $final_download - $initial_download)
19+
total_upload_bps=$(expr $final_upload - $initial_upload)
20+
21+
total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc)
22+
total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc)
23+
24+
echo "$total_download_kbps kB/s • ↑ $total_upload_kbps kB/s"
25+
done
26+
}
27+
main

0 commit comments

Comments
 (0)