From 72e385c44dfa2e1f7a81ec6a21d7016d60572ac6 Mon Sep 17 00:00:00 2001 From: Janno Tjarks Date: Fri, 11 Feb 2022 16:38:16 +0100 Subject: [PATCH 01/15] 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/15] 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 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 03/15] 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 04/15] 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 05/15] 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 e057d06c0d272cbf80397094554cfdfd2f94be3e Mon Sep 17 00:00:00 2001 From: Bryan Hoang Date: Mon, 7 Nov 2022 11:32:43 -0500 Subject: [PATCH 06/15] 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 07/15] 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 08/15] =?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 09/15] =?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 10/15] =?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 11/15] =?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 12/15] =?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 13/15] 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 14/15] 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 15/15] 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 ```