From 72e385c44dfa2e1f7a81ec6a21d7016d60572ac6 Mon Sep 17 00:00:00 2001 From: Janno Tjarks Date: Fri, 11 Feb 2022 16:38:16 +0100 Subject: [PATCH 01/31] Added kubernetes-context plugin --- README.md | 1 + scripts/dracula.sh | 6 +++++ scripts/kubernetes_context.sh | 51 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100755 scripts/kubernetes_context.sh diff --git a/README.md b/README.md index f4b3c51..3c0b143 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul * When prefix is enabled smiley face turns from green to yellow * When charging, 'AC' is displayed * If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature +* Current kubernetes context ## Compatibility diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..2c571cc 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -24,6 +24,7 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) + show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette @@ -168,6 +169,11 @@ main() script="#($current_dir/network_ping.sh)" fi + if [ $plugin = "kubernetes-context" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray") + script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)" + fi + if [ $plugin = "weather" ]; then # wait unit $datafile exists just to avoid errors # this should almost never need to wait unless something unexpected occurs diff --git a/scripts/kubernetes_context.sh b/scripts/kubernetes_context.sh new file mode 100755 index 0000000..ded1417 --- /dev/null +++ b/scripts/kubernetes_context.sh @@ -0,0 +1,51 @@ +#!/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 + +label=$1 + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh + +current_context=$(kubectl config view --minify --output 'jsonpath={.current-context}'; echo) +current_user=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.user}'; echo) +current_cluster=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.cluster}'; echo) +current_namespace=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.namespace}'; echo) + +main() +{ + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + OUTPUT_STRING="" + if [ ! -z "$current_user" ] + then + OUTPUT_STRING="${current_user}@" + fi + + if [ ! -z "$current_cluster" ] + then + OUTPUT_STRING="${OUTPUT_STRING}${current_cluster}" + fi + + if [ ! -z "$current_namespace" ] + then + OUTPUT_STRING="${OUTPUT_STRING}:${current_namespace}" + fi + + if [ "$OUTPUT_STRING" = "" ] + then + OUTPUT_STRING="kubeconfig not valid" + fi + + if [ "$label" = "" ] + then + echo "${OUTPUT_STRING}" + else + echo "${label} ${OUTPUT_STRING}" + fi + + sleep $RATE +} + +# run the main driver +main From fb043e3ac2aadb412bdbff79324b6764b857e468 Mon Sep 17 00:00:00 2001 From: Janno Tjarks Date: Fri, 11 Feb 2022 17:38:01 +0100 Subject: [PATCH 02/31] Added the plugin spotify-tui --- README.md | 1 + scripts/dracula.sh | 5 +++++ scripts/spotify-tui.sh | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100755 scripts/spotify-tui.sh diff --git a/README.md b/README.md index f4b3c51..952e038 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul * When prefix is enabled smiley face turns from green to yellow * When charging, 'AC' is displayed * If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature +* Spotify playback (needs the tool spotify-tui installed) ## Compatibility diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..df07e5d 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -168,6 +168,11 @@ main() script="#($current_dir/network_ping.sh)" fi + if [ $plugin = "spotify-tui" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray") + script="#($current_dir/spotify-tui.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 diff --git a/scripts/spotify-tui.sh b/scripts/spotify-tui.sh new file mode 100755 index 0000000..dc07206 --- /dev/null +++ b/scripts/spotify-tui.sh @@ -0,0 +1,24 @@ +#!/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 + +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source $current_dir/utils.sh + +main() +{ + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + + if ! command -v spt &> /dev/null + then + exit 1 + fi + + spotify_playback=$(spt playback) + echo ${spotify_playback} + +} + +# run the main driver +main From 77069707413597ca8aad1bb1ce10cab47646f284 Mon Sep 17 00:00:00 2001 From: Rojo Date: Sun, 27 Mar 2022 23:28:41 +0200 Subject: [PATCH 03/31] Update docs to include weather options --- INSTALL.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index e9d092b..92cc66f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -201,9 +201,20 @@ set -g @dracula-git-no-repo-message "" #### weather options -Switch from default fahrenheit to celsius +Switch from default fahrenheit to celsius (default: Fahrenheit) ```bash set -g @dracula-show-fahrenheit false ``` +Set your location manually (default: it tries to guess your location with your IP) + +```bash +set -g @dracula-fixed-location "Some City" +``` + +Hide your location (default: true) + +```bash +set -g @dracula-show-location false +``` From 42eaf7a950511ed0f791ddf9435d82dca7d2a3f4 Mon Sep 17 00:00:00 2001 From: Rojo Date: Sun, 27 Mar 2022 23:31:33 +0200 Subject: [PATCH 04/31] No defaults --- INSTALL.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 92cc66f..96f987c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -201,19 +201,19 @@ set -g @dracula-git-no-repo-message "" #### weather options -Switch from default fahrenheit to celsius (default: Fahrenheit) +Switch from default fahrenheit to celsius ```bash set -g @dracula-show-fahrenheit false ``` -Set your location manually (default: it tries to guess your location with your IP) +Set your location manually ```bash set -g @dracula-fixed-location "Some City" ``` -Hide your location (default: true) +Hide your location ```bash set -g @dracula-show-location false From 3e75296b73f483806291f4f1c5ff4bb09a8ad465 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 18 Jun 2022 05:35:23 -0400 Subject: [PATCH 05/31] Add attached-clients plugin --- scripts/attached_clients.sh | 35 +++++++++++++++++++++++++++++++++++ scripts/dracula.sh | 5 +++++ 2 files changed, 40 insertions(+) create mode 100755 scripts/attached_clients.sh diff --git a/scripts/attached_clients.sh b/scripts/attached_clients.sh new file mode 100755 index 0000000..ca7056d --- /dev/null +++ b/scripts/attached_clients.sh @@ -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-clients-minimum 1 +# @dracula-clients-singular client +# @dracula-clients-plural clients + +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source $current_dir/utils.sh + +count_clients() { + pane=$(tmux list-panes -F "#{session_name}" | head -n 1) + tmux list-clients -t $pane | wc -l | tr -d ' ' +} + +main() { + # storing the refresh rate in the variable RATE, default is 5 + RATE=$(get_tmux_option "@dracula-refresh-rate" 5) + clients_count=$(count_clients) + clients_minimum=$(get_tmux_option "@dracula-clients-minimum" 1) + if (( $clients_count >= $clients_minimum )); then + if (( $clients_count > 1 )); then + clients_label=$(get_tmux_option "@dracula-clients-plural" "clients") + else + clients_label=$(get_tmux_option "@dracula-clients-singular" "client") + fi + echo "$clients_count $clients_label" + fi + sleep $RATE +} + +# run main driver +main diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..ebb33d6 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -168,6 +168,11 @@ main() script="#($current_dir/network_ping.sh)" fi + if [ $plugin = "attached-clients" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-attached-clients-colors" "cyan dark_gray") + script="#($current_dir/attached_clients.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 From 07813ac51a50c13db22b8139ae58b0e1cb73c72d Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 18 Jun 2022 06:28:11 -0400 Subject: [PATCH 06/31] Add documentation for attached_clients.sh --- INSTALL.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index f62a08d..5e8d2a8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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, network-ping, weather, time +# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, attached-clients, weather, time set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" ``` @@ -215,3 +215,19 @@ Switch from default fahrenheit to celsius set -g @dracula-show-fahrenheit false ``` + +#### attached-clients options + +Set the minimum number of clients to show (otherwise, show nothing) + +```bash +set -g @dracula-clients-minimum 1 +``` + +Set the label when there is one client, or more than one client + +```bash +set -g @dracula-clients-singular client +set -g @dracula-clients-plural clients +``` + From d9b6d00121255ba5d850341da075e7b54933b80c Mon Sep 17 00:00:00 2001 From: Yusuke Uchida Date: Sat, 18 Sep 2021 21:40:30 +0900 Subject: [PATCH 07/31] dracula.sh: add use_arbitrary_time_format and time_format options --- scripts/dracula.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..321a3f1 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -24,6 +24,8 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) + use_arbitrary_time_format=$(get_tmux_option "@arbitrary_time_format" false) + time_format=$(get_tmux_option "@time_format" "Y-%m-%d(%a) %H:%M:%S") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette @@ -181,15 +183,20 @@ main() if [ $plugin = "time" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") - if $show_day_month && $show_military ; then # military time and dd/mm - script="%a %d/%m %R ${timezone} " - elif $show_military; then # only military time - script="%a %m/%d %R ${timezone} " - elif $show_day_month; then # only dd/mm - script="%a %d/%m %I:%M %p ${timezone} " - else - script="%a %m/%d %I:%M %p ${timezone} " - fi + case $use_arbitrary_time_format in + false) + script=${time_format} + true) + if $show_day_month && $show_military ; then # military time and dd/mm + script="%a %d/%m %R ${timezone} " + elif $show_military; then # only military time + script="%a %m/%d %R ${timezone} " + elif $show_day_month; then # only dd/mm + script="%a %d/%m %I:%M %p ${timezone} " + else + script="%a %m/%d %I:%M %p ${timezone} " + fi + esac fi if $show_powerline; then From bca34814a43f902ca0d2147766e6b43dfb49bdd0 Mon Sep 17 00:00:00 2001 From: Yusuke Uchida Date: Sat, 18 Sep 2021 21:42:09 +0900 Subject: [PATCH 08/31] dracula.sh: add prefix dracula- --- scripts/dracula.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 321a3f1..61853b5 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -24,8 +24,8 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) - use_arbitrary_time_format=$(get_tmux_option "@arbitrary_time_format" false) - time_format=$(get_tmux_option "@time_format" "Y-%m-%d(%a) %H:%M:%S") + use_arbitrary_time_format=$(get_tmux_option "@dracula-arbitrary-time-format" false) + time_format=$(get_tmux_option "@dracula-time-format" "Y-%m-%d(%a) %H:%M:%S") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette From 4b6bdaf9e26a26d1f95aa159c3220b569eae10d1 Mon Sep 17 00:00:00 2001 From: Yusuke Uchida Date: Sat, 18 Sep 2021 21:46:48 +0900 Subject: [PATCH 09/31] dracula.sh: fixed branch --- scripts/dracula.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 61853b5..8845e0c 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -183,10 +183,8 @@ main() if [ $plugin = "time" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") - case $use_arbitrary_time_format in + case $use_arbitrary_time_format in false) - script=${time_format} - true) if $show_day_month && $show_military ; then # military time and dd/mm script="%a %d/%m %R ${timezone} " elif $show_military; then # only military time @@ -196,6 +194,8 @@ main() else script="%a %m/%d %I:%M %p ${timezone} " fi + true) + script=${time_format} esac fi From d4f3009800c500a3b6d7736b58e3c57958f7ad8b Mon Sep 17 00:00:00 2001 From: Yusuke Uchida Date: Sat, 18 Sep 2021 22:15:41 +0900 Subject: [PATCH 10/31] dracula.sh: changed default value of time_format --- scripts/dracula.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 8845e0c..799538d 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -25,7 +25,7 @@ main() show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) use_arbitrary_time_format=$(get_tmux_option "@dracula-arbitrary-time-format" false) - time_format=$(get_tmux_option "@dracula-time-format" "Y-%m-%d(%a) %H:%M:%S") + time_format=$(get_tmux_option "@dracula-time-format" "%Y-%m-%d(%a) %H:%M") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") # Dracula Color Pallette From c39cc30213d68d6e5cb12e0c0afae76741c0c693 Mon Sep 17 00:00:00 2001 From: Yusuke Uchida Date: Sat, 18 Sep 2021 22:15:54 +0900 Subject: [PATCH 11/31] dracula.sh: debug case statement --- scripts/dracula.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 799538d..5e858f2 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -193,9 +193,9 @@ main() script="%a %d/%m %I:%M %p ${timezone} " else script="%a %m/%d %I:%M %p ${timezone} " - fi + fi;; true) - script=${time_format} + script=${time_format};; esac fi From 597f7bed29310bb9546c83315337e1f89a05f7f4 Mon Sep 17 00:00:00 2001 From: Yusuke Uchida Date: Sat, 16 Oct 2021 00:57:10 +0900 Subject: [PATCH 12/31] dracula.sh: deleted use_arbitrary_time_format option --- scripts/dracula.sh | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 5e858f2..c93aa94 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -24,7 +24,6 @@ main() show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) - use_arbitrary_time_format=$(get_tmux_option "@dracula-arbitrary-time-format" false) time_format=$(get_tmux_option "@dracula-time-format" "%Y-%m-%d(%a) %H:%M") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") @@ -183,20 +182,19 @@ main() if [ $plugin = "time" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") - case $use_arbitrary_time_format in - false) - if $show_day_month && $show_military ; then # military time and dd/mm - script="%a %d/%m %R ${timezone} " - elif $show_military; then # only military time - script="%a %m/%d %R ${timezone} " - elif $show_day_month; then # only dd/mm - script="%a %d/%m %I:%M %p ${timezone} " - else - script="%a %m/%d %I:%M %p ${timezone} " - fi;; - true) - script=${time_format};; - esac + if [ -n "$time_format" ]; then + script=${time_format} + else + if $show_day_month && $show_military ; then # military time and dd/mm + script="%a %d/%m %R ${timezone} " + elif $show_military; then # only military time + script="%a %m/%d %R ${timezone} " + elif $show_day_month; then # only dd/mm + script="%a %d/%m %I:%M %p ${timezone} " + else + script="%a %m/%d %I:%M %p ${timezone} " + fi + fi fi if $show_powerline; then From 8012d2164a3a143e8ac9c8aecb2ff4b9d0d83784 Mon Sep 17 00:00:00 2001 From: Jihed Mastouri <25284659+jihedmastouri@users.noreply.github.com> Date: Wed, 10 Aug 2022 14:14:17 +0100 Subject: [PATCH 13/31] Battery Status for Fedora 36 --- scripts/battery.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/battery.sh b/scripts/battery.sh index 65211bf..86b9ac0 100755 --- a/scripts/battery.sh +++ b/scripts/battery.sh @@ -89,10 +89,10 @@ battery_status() discharging|Discharging) echo '' ;; - high) + high|Full) echo '' ;; - charging) + charging|Charging) echo 'AC' ;; *) From 0850532083a9683e5d7af78c3b7a195ca9f86c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Migone?= Date: Fri, 26 Aug 2022 10:55:12 +0200 Subject: [PATCH 14/31] feat: add network-vpn plugin (only macOS) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Migone --- INSTALL.md | 6 +++--- scripts/dracula.sh | 5 +++++ scripts/network_vpn.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100755 scripts/network_vpn.sh diff --git a/INSTALL.md b/INSTALL.md index e1b6587..0cc70b1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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, network-ping, weather, time +# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, network-vpn, weather, time set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" ``` @@ -190,13 +190,13 @@ set -g @dracula-git-disable-status true Set symbol to use for when branch is up to date with HEAD ```bash -# default is ✓. Avoid using non unicode characters that bash uses like $, * and ! +# default is ✓. Avoid using non unicode characters that bash uses like $, * and ! set -g @dracula-git-show-current-symbol ✓ ``` Set symbol to use for when branch diverges from HEAD ```bash -# default is unicode !. Avoid bash special characters +# default is unicode !. Avoid bash special characters set -g @dracula-git-show-diff-symbol ! ``` diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..8887f90 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -168,6 +168,11 @@ main() script="#($current_dir/network_ping.sh)" fi + if [ $plugin = "network-vpn" ]; then + IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-vpn-colors" "cyan dark_gray") + script="#($current_dir/network_vpn.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 diff --git a/scripts/network_vpn.sh b/scripts/network_vpn.sh new file mode 100755 index 0000000..468445e --- /dev/null +++ b/scripts/network_vpn.sh @@ -0,0 +1,32 @@ +#!/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 + +current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source $current_dir/utils.sh + +vpn_function() { + case $(uname -s) in + Linux | Darwin) + vpn=$(scutil --nc list | grep Connected) + + if [ -z $vpn ]; then + echo "" + else + echo "VPN" + fi + ;; + + CYGWIN* | MINGW32* | MSYS* | MINGW*) + # TODO - windows compatability + ;; + esac +} + +main() { + + echo $(vpn_function) +} + +# run main driver +main From 731114654d4471606d7c5dfa16b473a1594300f8 Mon Sep 17 00:00:00 2001 From: tarantila <5209092+tarantila@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:12:26 +0200 Subject: [PATCH 15/31] Display CPU label on CPU load configuration Change to display the defined value of "dracula-cpu-usage-label" (e.g. CPU) when load average is used instead percentage. Before this change the label was not displayed if CPU load average is used. --- scripts/cpu_info.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 41b49c1..b73db09 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -44,10 +44,10 @@ main() { # storing the refresh rate in the variable RATE, default is 5 RATE=$(get_tmux_option "@dracula-refresh-rate" 5) cpu_load=$(get_tmux_option "@dracula-cpu-display-load" false) + cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") if [ "$cpu_load" = true ]; then - echo "$(get_load)" + echo "$cpu_label $(get_load)" else - cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU") cpu_percent=$(get_percent) echo "$cpu_label $cpu_percent" fi From 135637745daef7bd8f6f62e1a4c75aad4b0bbb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Mon, 5 Sep 2022 15:47:55 +0200 Subject: [PATCH 16/31] scripts: git: add option for untracked files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default 'git status' will look for untracked files and the script will always detect that the local tree has changes if untracked files are present. That is not always optimal since sometimes we might have, for example, some custom build scripts (for some project) that is always present and we don't want the status bar to always indicate changes. Hence, add an option to disable this behavior by adding the '-uno' flag to 'git status'. The default behavior is still maintained. Signed-off-by: Nuno Sá --- INSTALL.md | 5 +++++ scripts/git.sh | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index e1b6587..ebeae4e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -206,6 +206,11 @@ Set symbol or message to use when the current pane has no git repo set -g @dracula-git-no-repo-message "" ``` +Hide untracked files from being displayed as local changes +```bash +# default is false +set -g @dracula-git-no-untracked-files true +``` #### weather options diff --git a/scripts/git.sh b/scripts/git.sh index 3dba4e9..5dd8a2f 100755 --- a/scripts/git.sh +++ b/scripts/git.sh @@ -7,6 +7,7 @@ IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-git-disable-statu IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-current-symbol" "✓") IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!") IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "") +IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false") # Get added, modified, updated and deleted files from git status getChanges() @@ -77,8 +78,9 @@ checkEmptySymbol() # check to see if the current repo is not up to date with HEAD checkForChanges() { + [ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno" if [ "$(checkForGitDir)" == "true" ]; then - if [ "$(git -C $path status -s)" != "" ]; then + if [ "$(git -C $path status -s $no_untracked)" != "" ]; then echo "true" else echo "false" From e9f46f76ca4eff782d3883645971585741720efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Mon, 5 Sep 2022 15:57:11 +0200 Subject: [PATCH 17/31] scripts: git: add '--no-optional-locks' option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As stated in 'git status --help': "By default, git status will automatically refresh the index, updating the cached stat information from the working tree and writing out the result. Writing out the updated index is an optimization that isn’t strictly necessary (status computes the values for itself, but writing them out is just to save subsequent programs from repeating our computation). When status is run in the background, the lock held during the write may conflict with other simultaneous processes, causing them to fail. Scripts running status in the background should consider using git --no-optional-locks status (see git(1) for details)." This was actually happen during rebasing whith the following error: "error: Unable to create '/home/nsa/work/linux/.git/index.lock': File exists. Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue." This change fixes the above... Signed-off-by: Nuno Sá --- scripts/git.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/git.sh b/scripts/git.sh index 5dd8a2f..235c44e 100755 --- a/scripts/git.sh +++ b/scripts/git.sh @@ -17,7 +17,7 @@ getChanges() declare -i updated=0; declare -i deleted=0; -for i in $(git -C $path status -s) +for i in $(git -C $path --no-optional-locks status -s) do case $i in @@ -80,7 +80,7 @@ checkForChanges() { [ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno" if [ "$(checkForGitDir)" == "true" ]; then - if [ "$(git -C $path status -s $no_untracked)" != "" ]; then + if [ "$(git -C $path --no-optional-locks status -s $no_untracked)" != "" ]; then echo "true" else echo "false" From eedd33771fa4e6cac274f208a1e19a8e756f3b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Tue, 20 Sep 2022 14:29:45 +0200 Subject: [PATCH 18/31] git: add remote info support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this new option, we get information about which remote branch we're tracking. On top of this, we'll get information about ahead/behind commits when we diverged from remote. The output format will be in the form: 'local...remote +ahead -behind', where ahead and behind are the number of commits ahead and behind. This functionality is controlled by a new option called '@dracula-git-show-remote-status'. Note that for this to be properly displayed, we need to increase the size of the right status bar when the git plugin is enabled. In order to be easier to introduce the change, getMessage() was also a bit changed in order to be easier to append the remote info. Signed-off-by: Nuno Sá --- INSTALL.md | 6 ++++++ scripts/dracula.sh | 3 ++- scripts/git.sh | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index ebeae4e..32a6159 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -212,6 +212,12 @@ Hide untracked files from being displayed as local changes set -g @dracula-git-no-untracked-files true ``` +Show remote tracking branch together with diverge/sync state +```bash +# default is false +set -g @dracula-git-show-remote-status true +``` + #### weather options Switch from default fahrenheit to celsius diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..845d392 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -129,7 +129,8 @@ main() if [ $plugin = "git" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") - script="#($current_dir/git.sh)" + tmux set-option -g status-right-length 250 + script="#($current_dir/git.sh)" fi if [ $plugin = "battery" ]; then diff --git a/scripts/git.sh b/scripts/git.sh index 235c44e..965d9ec 100755 --- a/scripts/git.sh +++ b/scripts/git.sh @@ -8,6 +8,7 @@ IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-curre IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!") IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "") IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false") +IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false") # Get added, modified, updated and deleted files from git status getChanges() @@ -110,37 +111,59 @@ getBranch() fi } +getRemoteInfo() +{ + base=$(git -C $path for-each-ref --format='%(upstream:short) %(upstream:track)' "$(git -C $path symbolic-ref -q HEAD)") + remote=$(echo "$base" | cut -d" " -f1) + out="" + + if [ -n "$remote" ]; then + out="...$remote" + ahead=$(echo "$base" | grep -E -o 'ahead[ [:digit:]]+' | cut -d" " -f2) + behind=$(echo "$base" | grep -E -o 'behind[ [:digit:]]+' | cut -d" " -f2) + + [ -n "$ahead" ] && out+=" +$ahead" + [ -n "$behind" ] && out+=" -$behind" + fi + + echo "$out" +} + # return the final message for the status bar getMessage() { if [ $(checkForGitDir) == "true" ]; then branch="$(getBranch)" - + output="" + if [ $(checkForChanges) == "true" ]; then changes="$(getChanges)" if [ "${hide_status}" == "false" ]; then if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then - echo "${changes} $branch" + output=$(echo "${changes} $branch") else - echo "$diff_symbol ${changes} $branch" + output=$(echo "$diff_symbol ${changes} $branch") fi else if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then - echo "$branch" + output=$(echo "$branch") else - echo "$diff_symbol $branch" + output=$(echo "$diff_symbol $branch") fi fi else if [ $(checkEmptySymbol $current_symbol) == "true" ]; then - echo "$branch" + output=$(echo "$branch") else - echo "$current_symbol $branch" + output=$(echo "$current_symbol $branch") fi fi + + [ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo) + echo "$output" else echo $no_repo_message fi From 143a0d888800d150593ba8c72a4e7b6c8a2c2885 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 01:10:30 -0400 Subject: [PATCH 19/31] Add option to show/hide empty plugins --- scripts/dracula.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 2b5e1f4..b8889a2 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -25,6 +25,7 @@ main() show_day_month=$(get_tmux_option "@dracula-day-month" false) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") + show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true) # Dracula Color Pallette white='#f8f8f2' @@ -193,10 +194,18 @@ main() fi if $show_powerline; then - tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " + if $show_empty_plugins; then + tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " + else + tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script }" + fi powerbg=${!colors[0]} else - tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " + if $show_empty_plugins; then + tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " + else + tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}] $script }" + fi fi done From e057d06c0d272cbf80397094554cfdfd2f94be3e Mon Sep 17 00:00:00 2001 From: Bryan Hoang Date: Mon, 7 Nov 2022 11:32:43 -0500 Subject: [PATCH 20/31] fix(dracula.sh): fix execution errors Resolves an issue cause by a syntax error and a removed executable bit introduced by dracula/tmux#153. The syntax/permissions issue stops the plugin from running properly when I ran into the issue earlier today. The missing executable bit is likely what's causing dracula/tmux#178 given that `man bash` has the following excerpt: > If a command is found but is not executable, the return status is 126. --- scripts/dracula.sh | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 scripts/dracula.sh diff --git a/scripts/dracula.sh b/scripts/dracula.sh old mode 100644 new mode 100755 index 5cd4124..49ddcef --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -172,6 +172,7 @@ main() if [ $plugin = "spotify-tui" ]; then IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray") script="#($current_dir/spotify-tui.sh)" + fi if [ $plugin = "kubernetes-context" ]; then IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray") From e2dd7c83f8ed095daede8c23b9de94349051db59 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Fri, 28 Oct 2022 01:42:26 -0400 Subject: [PATCH 21/31] Reject unrecognized plugins in config Prevents duplication of preceding recognized plugin for each unrecognized plugin --- scripts/dracula.sh | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 49ddcef..394bd84 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -131,55 +131,45 @@ main() if [ $plugin = "git" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") script="#($current_dir/git.sh)" - fi - if [ $plugin = "battery" ]; then + elif [ $plugin = "battery" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray") script="#($current_dir/battery.sh)" - fi - if [ $plugin = "gpu-usage" ]; then + elif [ $plugin = "gpu-usage" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray") script="#($current_dir/gpu_usage.sh)" - fi - if [ $plugin = "cpu-usage" ]; then + elif [ $plugin = "cpu-usage" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray") script="#($current_dir/cpu_info.sh)" - fi - if [ $plugin = "ram-usage" ]; then + elif [ $plugin = "ram-usage" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray") script="#($current_dir/ram_info.sh)" - fi - if [ $plugin = "network" ]; then + elif [ $plugin = "network" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray") script="#($current_dir/network.sh)" - fi - if [ $plugin = "network-bandwidth" ]; then + elif [ $plugin = "network-bandwidth" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwidth-colors" "cyan dark_gray") tmux set-option -g status-right-length 250 script="#($current_dir/network_bandwidth.sh)" - fi - if [ $plugin = "network-ping" ]; then + elif [ $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 = "spotify-tui" ]; then + elif [ $plugin = "spotify-tui" ]; then IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray") script="#($current_dir/spotify-tui.sh)" - fi - if [ $plugin = "kubernetes-context" ]; then + elif [ $plugin = "kubernetes-context" ]; then IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray") script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)" - fi - if [ $plugin = "weather" ]; then + elif [ $plugin = "weather" ]; then # wait unit $datafile exists just to avoid errors # this should almost never need to wait unless something unexpected occurs while [ ! -f $datafile ]; do @@ -188,9 +178,8 @@ main() IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") script="#(cat $datafile)" - fi - if [ $plugin = "time" ]; then + elif [ $plugin = "time" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") if $show_day_month && $show_military ; then # military time and dd/mm script="%a %d/%m %R ${timezone} " @@ -201,6 +190,9 @@ main() else script="%a %m/%d %I:%M %p ${timezone} " fi + + else + continue fi if $show_powerline; then From ac95b3e0699548255411cb304f0885ebbca98229 Mon Sep 17 00:00:00 2001 From: Adrien Kara Date: Fri, 6 Jan 2023 00:42:01 +0100 Subject: [PATCH 22/31] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(network=5Fb?= =?UTF-8?q?andwidth):=20more=20flexibility=20and=20less=20spaghetti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use the internationally recommended unit symbol - Commentary for next contributor - Remove spaghetti code - More flexible for future evolution Signed-off-by: Adrien Kara --- scripts/network_bandwidth.sh | 100 +++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/scripts/network_bandwidth.sh b/scripts/network_bandwidth.sh index d9b5f70..4d9e782 100755 --- a/scripts/network_bandwidth.sh +++ b/scripts/network_bandwidth.sh @@ -1,51 +1,69 @@ #!/usr/bin/env bash -INTERVAL="1" # update interval in seconds +# INTERVAL is equal to 1s because we want to express the bandwidth in sec +readonly INTERVAL=1 + +# UPLOAD and DOWNLOAD index +readonly UPLOAD=0 +readonly DOWNLOAD=1 + +# SIZE index are the multiple of the unit byte and value the internationally recommended unit symbol in sec +readonly SIZE=( + [1]='B/s' + [1024]='kB/s' + [1048576]='MB/s' + [1073741824]='GB/s' +) network_name=$(tmux show-option -gqv "@dracula-network-bandwidth") +# interface_bytes give interface name and signal tx/rx return Bytes +interface_bytes() { + cat "/sys/class/net/$1/statistics/$2_bytes" +} + +# get_bandwidth return the number of bytes exchanged for tx and rx +get_bandwidth() { + upload="$(interface_bytes "$network_name" "tx")" + download="$(interface_bytes "$network_name" "rx")" + + #wait the interval for Wait for interval to calculate the difference + sleep "$INTERVAL" + + upload="$(bc <<<"$(interface_bytes "$network_name" "tx") - $upload")" + download="$(bc <<<"$(interface_bytes "$network_name" "rx") - $download")" + + #set to 0 by default useful for non-existent interface + echo "${upload:-0} ${download:-0}" +} + +# bandwidth_to_unit convert bytes into its highest unit and add unit symbol in sec +bandwidth_to_unit() { + local size=1 + for i in "${!SIZE[@]}"; do + if (($1 < i)); then + break + fi + + size="$i" + done + + local result="0.00" + if (($1 != 0)); then + result="$(bc <<<"scale=2; $1 / $size")" + fi + + echo "$result ${SIZE[$size]}" +} + main() { - while true - do - output_download="" - output_upload="" - output_download_unit="" - output_upload_unit="" + bandwidth=() - 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) - - if [ $total_download_bps -gt 1073741824 ]; then - output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}') - output_download_unit="gB/s" - elif [ $total_download_bps -gt 1048576 ]; then - output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}') - output_download_unit="mB/s" - else - output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/$2}') - output_download_unit="kB/s" - fi - - if [ $total_upload_bps -gt 1073741824 ]; then - output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}') - output_upload_unit="gB/s" - elif [ $total_upload_bps -gt 1048576 ]; then - output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}') - output_upload_unit="mB/s" - else - output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/$2}') - output_upload_unit="kB/s" - fi - - echo "↓ $output_download $output_download_unit • ↑ $output_upload $output_upload_unit" + while true; do + IFS=" " read -ra bandwidth <<<"$(get_bandwidth)" + echo "↓ $(bandwidth_to_unit "${bandwidth[$DOWNLOAD]}") • ↑ $(bandwidth_to_unit "${bandwidth[$UPLOAD]}")" done } + +#run main driver main From 4bb5e56053f5292493fd84207f1f3626feae42d4 Mon Sep 17 00:00:00 2001 From: Adrien Kara Date: Fri, 6 Jan 2023 19:46:04 +0100 Subject: [PATCH 23/31] =?UTF-8?q?=E2=9C=A8=20feat(network=5Fbandwidth):=20?= =?UTF-8?q?add=20more=20configuration=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Can auto detect used interface (only with linux ip for now) - Can show the name of used interface - A waiting interval can be set between each update Signed-off-by: Adrien Kara --- INSTALL.md | 12 ++++++++++ scripts/network_bandwidth.sh | 46 +++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index ebeae4e..4143845 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -152,6 +152,18 @@ Customize label set -g @dracula-ram-usage-label "RAM" ``` +#### network-bandwidth + +You can configure which network interface you want to view the bandwidth, +Displaying of the interface name, The interval between each bandwidth update. +The most common interfaces name are `eth0` for a wired connection and `wlan0` for a wireless connection. + +```bash +set -g @dracula-network-bandwidth eth0 +set -g @dracula-network-bandwidth-interval 0 +set -g @dracula-network-bandwidth-show-interface true +``` + #### 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. diff --git a/scripts/network_bandwidth.sh b/scripts/network_bandwidth.sh index 4d9e782..6427bdd 100755 --- a/scripts/network_bandwidth.sh +++ b/scripts/network_bandwidth.sh @@ -15,7 +15,22 @@ readonly SIZE=( [1073741824]='GB/s' ) -network_name=$(tmux show-option -gqv "@dracula-network-bandwidth") +# interface_get try to automaticaly get the used interface if network_name is empty +interface_get() { + name="$(tmux show-option -gqv "@dracula-network-bandwidth")" + + if [[ -z $name ]]; then + case "$(uname -s)" in + Linux) + if type ip >/dev/null; then + name="$(ip -o route get 192.168.0.0 | awk '{print $5}')" + fi + ;; + esac + fi + + echo "$name" +} # interface_bytes give interface name and signal tx/rx return Bytes interface_bytes() { @@ -24,14 +39,14 @@ interface_bytes() { # get_bandwidth return the number of bytes exchanged for tx and rx get_bandwidth() { - upload="$(interface_bytes "$network_name" "tx")" - download="$(interface_bytes "$network_name" "rx")" + upload="$(interface_bytes "$1" "tx")" + download="$(interface_bytes "$1" "rx")" #wait the interval for Wait for interval to calculate the difference sleep "$INTERVAL" - upload="$(bc <<<"$(interface_bytes "$network_name" "tx") - $upload")" - download="$(bc <<<"$(interface_bytes "$network_name" "rx") - $download")" + upload="$(bc <<<"$(interface_bytes "$1" "tx") - $upload")" + download="$(bc <<<"$(interface_bytes "$1" "rx") - $download")" #set to 0 by default useful for non-existent interface echo "${upload:-0} ${download:-0}" @@ -57,11 +72,30 @@ bandwidth_to_unit() { } main() { + counter=0 bandwidth=() + network_name="" + show_interface="$(tmux show-option -gqv "@dracula-network-bandwidth-show-interface")" + interval_update="$(tmux show-option -gqv "@dracula-network-bandwidth-interval")" + + if [[ -z $interval_update ]]; then + interval_update=0 + fi + while true; do - IFS=" " read -ra bandwidth <<<"$(get_bandwidth)" + if ((counter == 0)); then + counter=60 + network_name="$(interface_get)" + fi + + IFS=" " read -ra bandwidth <<<"$(get_bandwidth "$network_name")" + + if [[ $show_interface == "true" ]]; then echo -n "[$network_name] "; fi echo "↓ $(bandwidth_to_unit "${bandwidth[$DOWNLOAD]}") • ↑ $(bandwidth_to_unit "${bandwidth[$UPLOAD]}")" + + ((counter = counter - 1)) + sleep "$interval_update" done } From a960a12af1ebb6a2150ce05f2900454d22230398 Mon Sep 17 00:00:00 2001 From: Adrien Kara Date: Sat, 7 Jan 2023 16:55:14 +0100 Subject: [PATCH 24/31] =?UTF-8?q?=F0=9F=90=9B=20fix(#180):=20set=20network?= =?UTF-8?q?=5Fping=20as=20executable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Kara --- scripts/network_ping.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/network_ping.sh diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh old mode 100644 new mode 100755 From beb6085ad78e4691879d0911897e71ffd3543d64 Mon Sep 17 00:00:00 2001 From: Adrien Kara Date: Sat, 7 Jan 2023 18:36:14 +0100 Subject: [PATCH 25/31] =?UTF-8?q?=F0=9F=90=9B=20fix(#165):=20is=20no=20lon?= =?UTF-8?q?ger=20based=20on=20word=20matching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Kara --- scripts/ram_info.sh | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 97d61b6..ab983d5 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -9,20 +9,11 @@ get_percent() { case $(uname -s) in Linux) - total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') - used_mem=$(free -g | awk '/^Mem/ {print $3}') - total_mem=$(free -h | awk '/^Mem/ {print $2}') - if (( $total_mem_gb == 0)); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - total_mem_mb=$(free -m | awk '/^Mem/ {print $2}') - echo $memory_usage\M\B/$total_mem_mb\M\B - elif (( $used_mem == 0 )); then - memory_usage=$(free -m | awk '/^Mem/ {print $3}') - echo $memory_usage\M\B/$total_mem_gb\G\B - else - memory_usage=$(free -g | awk '/^Mem/ {print $3}') - echo $memory_usage\G\B/$total_mem_gb\G\B - fi + usage="$(free -h | awk 'NR==2 {print $3}')" + total="$(free -h | awk 'NR==2 {print $2}')" + formated="${usage}/${total}" + + echo "${formated//i/B}" ;; Darwin) From 1d3d07c3d251e6f70524934f7eab8273a58456f4 Mon Sep 17 00:00:00 2001 From: Adrien Kara Date: Sat, 7 Jan 2023 23:58:58 +0100 Subject: [PATCH 26/31] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(ram=5Finfo)?= =?UTF-8?q?:=20cleanup=20and=20follow=20bash=20recommendations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove the sleep rate, controled by show_refresh in dracula.sh Signed-off-by: Adrien Kara --- scripts/ram_info.sh | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index ab983d5..00af64a 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -5,7 +5,7 @@ export LC_ALL=en_US.UTF-8 current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $current_dir/utils.sh -get_percent() +get_ratio() { case $(uname -s) in Linux) @@ -20,11 +20,11 @@ get_percent() # Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') - if (( $used_mem < 1024 )); then - echo $used_mem\M\B/$total_mem + if ((used_mem < 1024 )); then + echo "${used_mem}MB/$total_mem" else - memory=$(($used_mem/1024)) - echo $memory\G\B/$total_mem + memory=$((used_mem/1024)) + echo "${memory}GB/$total_mem" fi ;; @@ -39,11 +39,11 @@ get_percent() total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) used_mem=$((total_mem - free_mem)) echo $used_mem - if (( $used_mem < 1024 )); then - echo $used_mem\M\B/$total_mem + if ((used_mem < 1024 )); then + echo "${used_mem}MB/$total_mem" else - memory=$(($used_mem/1024)) - echo $memory\G\B/$total_mem + memory=$((used_mem/1024)) + echo "${memory}GB/$total_mem" fi ;; @@ -55,12 +55,9 @@ get_percent() main() { - # storing the refresh rate in the variable RATE, default is 5 - RATE=$(get_tmux_option "@dracula-refresh-rate" 5) ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM") - ram_percent=$(get_percent) - echo "$ram_label $ram_percent" - sleep $RATE + ram_ratio=$(get_ratio) + echo "$ram_label $ram_ratio" } #run main driver From 83a05e1a36835f77a2b0bee2dea040ad4659c567 Mon Sep 17 00:00:00 2001 From: Darko Grozdanovski Date: Wed, 22 Mar 2023 13:23:19 +0100 Subject: [PATCH 27/31] fix gpu reporting issue #195 --- scripts/gpu_usage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index 9ffc647..552ed2b 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -27,7 +27,7 @@ get_gpu() { gpu=$(get_platform) if [[ "$gpu" == NVIDIA ]]; then - usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }') + usage=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits | awk '{ sum += $0 } END { printf("%d%%\n", sum / NR) }') else usage='unknown' fi From 09c57506561b8a4b6d18ce03de9ad8a7cf062854 Mon Sep 17 00:00:00 2001 From: jonathanforhan Date: Fri, 7 Apr 2023 20:40:53 -0400 Subject: [PATCH 28/31] Add cwd.sh to display the tmux pane's current working directory, updated README to reflect change --- README.md | 1 + scripts/cwd.sh | 30 ++++++++++++++++++++++++++++++ scripts/dracula.sh | 6 ++++++ 3 files changed, 37 insertions(+) create mode 100755 scripts/cwd.sh diff --git a/README.md b/README.md index a6536d0..fb80867 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul - If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature - Spotify playback (needs the tool spotify-tui installed) - Current kubernetes context +- Current working directory of tmux pane ## Compatibility diff --git a/scripts/cwd.sh b/scripts/cwd.sh new file mode 100755 index 0000000..cfae694 --- /dev/null +++ b/scripts/cwd.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# return current working directory of tmux pane +getPaneDir() +{ + nextone="false" + for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); + do + if [ "$nextone" == "true" ]; then + echo $i + return + fi + if [ "$i" == "1" ]; then + nextone="true" + fi + done +} + +main() +{ + path=$(getPaneDir) + + # change '/home/user' to '~' + cwd=$(echo $path | sed "s;$HOME;~;g") + + echo $cwd +} + +#run main driver program +main diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 3e1bc1b..1054563 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -128,6 +128,12 @@ main() for plugin in "${plugins[@]}"; do + if [ $plugin = "cwd" ]; then + IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white") + tmux set-option -g status-right-length 250 + script="#($current_dir/cwd.sh)" + fi + if [ $plugin = "git" ]; then IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") tmux set-option -g status-right-length 250 From c43100532fb84e5da868b81c7b9caec8c697db72 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Sat, 8 Apr 2023 14:18:42 -0400 Subject: [PATCH 29/31] add gpu driver disclaimer --- INSTALL.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 2e34d7c..21e30d4 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -138,6 +138,8 @@ set -g @dracula-battery-label "Battery" #### gpu-usage options +Note, currently only the Linux NVIDIA Proprietary drivers are supported. Nouveau and AMD Graphics Cards support are still under development. + Customize label ```bash @@ -248,4 +250,31 @@ Hide your location ```bash set -g @dracula-show-location false + +set -g @dracula-plugins "cpu-usage ram-usage network network-bandwidth time" +set -g @dracula-network-bandwidth enp5s0 +set -g @dracula-show-powerline true +set -g @dracula-show-flags false +set -g @dracula-refresh-rate 5 +set -g @dracula-show-left-icon session +set -g @dracula-border-contrast true +set -g @dracula-military-time true +set -g @dracula-show-location false +set -g @dracula-show-timezone false +set -g @dracula-show-weather false + + + +# set -g @dracula-border-contrast true +# set -g @dracula-cpu-usage true +# set -g @dracula-military-time true +# set -g @dracula-ram-usage true +# set -g @dracula-refresh-rate 5 +# set -g @dracula-show-battery true +# set -g @dracula-show-flags true +# set -g @dracula-show-left-icon session +# set -g @dracula-show-network false +# set -g @dracula-show-powerline false +# set -g @dracula-show-powerline true +# set -g @dracula-show-weather false ``` From 42deb775706d2efb12a122b04d86eb2033bc40d9 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Sat, 8 Apr 2023 14:56:40 -0400 Subject: [PATCH 30/31] fix documentation errors --- INSTALL.md | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 51d943b..8264019 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -111,6 +111,12 @@ Enable high contrast pane border set -g @dracula-border-contrast true ``` +Hide empty plugins + +```bash +set -g @dracula-show-empty-plugins false +``` + #### cpu-usage options Customize label @@ -250,36 +256,8 @@ Hide your location ```bash set -g @dracula-show-location false - -set -g @dracula-plugins "cpu-usage ram-usage network network-bandwidth time" -set -g @dracula-network-bandwidth enp5s0 -set -g @dracula-show-powerline true -set -g @dracula-show-flags false -set -g @dracula-refresh-rate 5 -set -g @dracula-show-left-icon session -set -g @dracula-border-contrast true -set -g @dracula-military-time true -set -g @dracula-show-location false -set -g @dracula-show-timezone false -set -g @dracula-show-weather false - - - -# set -g @dracula-border-contrast true -# set -g @dracula-cpu-usage true -# set -g @dracula-military-time true -# set -g @dracula-ram-usage true -# set -g @dracula-refresh-rate 5 -# set -g @dracula-show-battery true -# set -g @dracula-show-flags true -# set -g @dracula-show-left-icon session -# set -g @dracula-show-network false -# set -g @dracula-show-powerline false -# set -g @dracula-show-powerline true -# set -g @dracula-show-weather false ``` - #### attached-clients options Set the minimum number of clients to show (otherwise, show nothing) From 8eacce7ee4d0bcdcc89d8f18c74a4b3cc032512f Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Sat, 8 Apr 2023 15:12:22 -0400 Subject: [PATCH 31/31] add only Darwin support --- scripts/network_vpn.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/network_vpn.sh b/scripts/network_vpn.sh index 468445e..74b1eea 100755 --- a/scripts/network_vpn.sh +++ b/scripts/network_vpn.sh @@ -7,7 +7,11 @@ source $current_dir/utils.sh vpn_function() { case $(uname -s) in - Linux | Darwin) + Linux) + # TODO + ;; + + Darwin) vpn=$(scutil --nc list | grep Connected) if [ -z $vpn ]; then