Skip to content

Commit

Permalink
Merge pull request #100 from rodrigocnascimento/feat/network-bandwith
Browse files Browse the repository at this point in the history
Network bandwith feature
  • Loading branch information
ethancedwards8 authored Jun 20, 2021
2 parents f508a89 + 2b59061 commit e25e7a3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ programs.tmux = {
Customize the status bar by adding any of these lines to your .tmux.conf as desired:
* Disable battery functionality: `set -g @dracula-show-battery false`
* Disable network functionality: `set -g @dracula-show-network false`
* Enable network bandwith functionality: `set -g @dracula-network-bandwith $network_name`
- You could get the `$network_name` through the command: `sudo lshw -class network -short | grep wl | awk '{print $2}'`
* Disable weather functionality: `set -g @dracula-show-weather false`
* Disable time functionality: `set -g @dracula-show-time false`
* Disable location information: `set -g @dracula-show-location false`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
* Support for powerline
* Day, date, time, timezone
* Current location based on network with temperature and forecast icon (if available)
* Network connection status and SSID
* Network connection status, bandwith and SSID
* Battery percentage and AC power connection status
* Refresh rate control
* CPU usage
Expand Down
14 changes: 13 additions & 1 deletion scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ main()
show_day_month=$(get_tmux_option "@dracula-day-month" false)
show_time=$(get_tmux_option "@dracula-show-time" true)
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
show_network_bandwith=$(get_tmux_option "@dracula-network-bandwith" "")

# Dracula Color Pallette
white='#f8f8f2'
Expand Down Expand Up @@ -113,7 +114,7 @@ main()

# set length
tmux set-option -g status-left-length 100
tmux set-option -g status-right-length 100
tmux set-option -g status-right-length 100

# pane border styling
if $show_border_contrast; then
Expand Down Expand Up @@ -167,6 +168,12 @@ main()
powerbg=${cyan}
fi

if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
tmux set-option -g status-right-length 250
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)"
powerbg=${green}
fi

if $show_weather; then # weather
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)"
powerbg=${orange}
Expand Down Expand Up @@ -211,6 +218,11 @@ main()
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) "
fi

if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
tmux set-option -g status-right-length 250
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) "
fi

if $show_weather; then # weather
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $current_dir/../data/weather.txt) "
fi
Expand Down
27 changes: 27 additions & 0 deletions scripts/network_bandwith.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

INTERVAL="1" # update interval in seconds

network_name=$(tmux show-option -gqv "@dracula-network-bandwith")

main() {
while true
do
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)

sleep $INTERVAL

final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)

total_download_bps=$(expr $final_download - $initial_download)
total_upload_bps=$(expr $final_upload - $initial_upload)

total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc)
total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc)

echo "$total_download_kbps kB/s • ↑ $total_upload_kbps kB/s"
done
}
main

0 comments on commit e25e7a3

Please sign in to comment.