Skip to content

Commit

Permalink
Merge pull request #161 from aaronkollasch/attached-clients
Browse files Browse the repository at this point in the history
Show the number of attached clients
  • Loading branch information
ethancedwards8 authored Apr 8, 2023
2 parents eda8c62 + ae09b2f commit 872c128
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
18 changes: 17 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```

Expand Down Expand Up @@ -278,3 +278,19 @@ set -g @dracula-show-weather 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)

```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
```
35 changes: 35 additions & 0 deletions scripts/attached_clients.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ main()
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray")
script="#($current_dir/network_ping.sh)"

elif [ $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)"

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)"
Expand Down

0 comments on commit 872c128

Please sign in to comment.