From 3e75296b73f483806291f4f1c5ff4bb09a8ad465 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Sat, 18 Jun 2022 05:35:23 -0400 Subject: [PATCH] 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