From d5afb7822f68c8f4204db491f3c9f27d87d3bcd3 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 10 Apr 2021 00:35:06 -0300 Subject: [PATCH 1/7] gets the RX and TX values and transform to kB/s --- scripts/network_bandwith.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 scripts/network_bandwith.sh diff --git a/scripts/network_bandwith.sh b/scripts/network_bandwith.sh new file mode 100755 index 0000000..682a0cc --- /dev/null +++ b/scripts/network_bandwith.sh @@ -0,0 +1,27 @@ +#!/bin/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_upload_kbps kB/s • ↓ $total_download_kbps kB/s" + done +} +main From 6ac5897ac1fee071d04b93be47233fc8d3d953d2 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 10 Apr 2021 00:37:12 -0300 Subject: [PATCH 2/7] increased status-right-length to show bandwith values --- scripts/dracula.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index bb4f5de..d52449f 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -113,7 +113,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 250 # pane border styling if $show_border_contrast; then From 550e8ce144e9b11a38431346f08de0891d4ef308 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 10 Apr 2021 00:38:43 -0300 Subject: [PATCH 3/7] checking if network_name exists and call network_bandwith script --- scripts/dracula.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index d52449f..89b1963 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -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' @@ -167,6 +168,11 @@ main() powerbg=${cyan} fi + if [[ "$show_network_bandwith" != "" ]]; then # network bandwith + 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} @@ -211,6 +217,10 @@ 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 -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 From 2e48e24b70a13fdffeadf74041ab7bc72bf64dde Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sat, 10 Apr 2021 00:44:11 -0300 Subject: [PATCH 4/7] installation and readme instructions --- INSTALL.md | 2 ++ README.md | 2 +- scripts/network_bandwith.sh | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4cacbdf..57a768d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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` diff --git a/README.md b/README.md index 41069a8..a93acb0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/scripts/network_bandwith.sh b/scripts/network_bandwith.sh index 682a0cc..3c544c8 100755 --- a/scripts/network_bandwith.sh +++ b/scripts/network_bandwith.sh @@ -21,7 +21,7 @@ main() { total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc) total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc) - echo "↑ $total_upload_kbps kB/s • ↓ $total_download_kbps kB/s" + echo "↓ $total_download_kbps kB/s • ↑ $total_upload_kbps kB/s" done } main From 910d648d6775b79e8f34146d771e114bdd42cad1 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Fri, 30 Apr 2021 10:59:22 -0300 Subject: [PATCH 5/7] Fixing shebang to follow script files convention --- scripts/network_bandwith.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/network_bandwith.sh b/scripts/network_bandwith.sh index 3c544c8..655c9f0 100755 --- a/scripts/network_bandwith.sh +++ b/scripts/network_bandwith.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash INTERVAL="1" # update interval in seconds From 4616ee9ebe81761eff7c6d708a7ffc6e45175311 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sun, 2 May 2021 19:24:57 -0300 Subject: [PATCH 6/7] Only set status-right-length when the network_bandwidth option is enabled --- scripts/dracula.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 89b1963..1d539d2 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -114,7 +114,7 @@ main() # set length tmux set-option -g status-left-length 100 - tmux set-option -g status-right-length 250 + tmux set-option -g status-right-length 100 # pane border styling if $show_border_contrast; then @@ -169,6 +169,7 @@ main() 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 @@ -218,6 +219,7 @@ main() 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 From 2b5906140fd92bb6a361024f189bbf1135d38bed Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Sun, 2 May 2021 19:29:23 -0300 Subject: [PATCH 7/7] Change from backticks to $() as command substitution --- scripts/network_bandwith.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/network_bandwith.sh b/scripts/network_bandwith.sh index 655c9f0..213ef26 100755 --- a/scripts/network_bandwith.sh +++ b/scripts/network_bandwith.sh @@ -7,16 +7,16 @@ 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` + 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` + 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_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)