From 8d14a2a771bbdff57b47e15fa89802bb5698f1ed Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Tue, 2 Apr 2024 08:15:31 +0300 Subject: [PATCH] Tmux : Rework statusbar. --- module/common/Tmux.nix | 4 +- .../common/tmux/{tmux_script.sh => Script.sh} | 52 ++++++++++++++++--- module/common/tmux/tmux.conf | 4 +- 3 files changed, 48 insertions(+), 12 deletions(-) rename module/common/tmux/{tmux_script.sh => Script.sh} (52%) diff --git a/module/common/Tmux.nix b/module/common/Tmux.nix index 969f042..5e4c3a5 100644 --- a/module/common/Tmux.nix +++ b/module/common/Tmux.nix @@ -1,9 +1,9 @@ { pkgs, ... }: let - tmux_script = pkgs.writeShellScriptBin "tmux_script" (builtins.readFile ./tmux/tmux_script.sh); + script = pkgs.writeShellScriptBin "tmux_script" (builtins.readFile ./tmux/Script.sh); in { programs.tmux = { enable = true; extraConfig = builtins.readFile ./tmux/tmux.conf; }; - environment.systemPackages = [ tmux_script ]; + environment.systemPackages = [ script ]; } diff --git a/module/common/tmux/tmux_script.sh b/module/common/tmux/Script.sh similarity index 52% rename from module/common/tmux/tmux_script.sh rename to module/common/tmux/Script.sh index 58bf502..2166e4d 100755 --- a/module/common/tmux/tmux_script.sh +++ b/module/common/tmux/Script.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -action="${1}" - function _tmux_battery() { local IFS=$'\n' @@ -30,12 +28,13 @@ function _tmux_battery() { echo -n "${icon}" ${is_charging} && echo -n "󱐋" - [[ "${level}" -lt 40 ]] && echo -n " ${level}" + [[ "${level}" -lt 40 ]] && echo -n "\n${level}%" } function _tmux_volume() { local IFS=$'\n' local level=$(wpctl get-volume @DEFAULT_SINK@ | cut -d\ -f2 | sed -e "s/^0//" -e "s/\.//") + [[ "${level}" = "" ]] && return 1 [[ "${level}" = "00" ]] && level="0" local icon @@ -55,11 +54,48 @@ function _tmux_volume() { wpctl get-volume @DEFAULT_SINK@ | grep '[MUTED]' && icon="󰸈" echo -n "${icon}" - [[ "${level}" -gt 100 ]] && echo -n " ${level}%" + [[ "${level}" -gt 100 ]] && echo -n "\n${level}%" } -case ${action} in - "battery") _tmux_battery ;; - "volume") _tmux_volume ;; - "*") ;; +function _tmux_statusbar() { + IFS=$'\n' + + # Get data. + battery=($(_tmux_battery)) + volume=($(_tmux_volume)) + + # Prepare separators. + sep_batvol=" " + + if [[ "${battery[1]}" != "" ]] || [[ "${volume[1]}" != "" ]]; then + sep_batvol="  " + fi + if [[ "${battery[0]}" = "" ]]; then + sep_batvol="" + fi + + # Print. + echo -n " " + + [[ "${volume[0]}" != "" ]] && echo -n "${volume[0]}${sep_batvol}" + [[ "${battery[0]}" != "" ]] && echo -n "${battery[0]}" + + echo -n " " +} + +function _tmux_client_count() { + local IFS=$'\n' + local session=${1} + local count=$(tmux list-clients -t ${session} | wc -l) + + [ ${count} -gt 1 ] && echo -n "(${count}) " +} + +IFS=$'\n' +action=${1} +session=${2} + +case "${action}" in + "statusbar") _tmux_statusbar ;; + "client_count") _tmux_client_count ${session} ;; esac diff --git a/module/common/tmux/tmux.conf b/module/common/tmux/tmux.conf index af5eff2..dd63f1e 100644 --- a/module/common/tmux/tmux.conf +++ b/module/common/tmux/tmux.conf @@ -68,10 +68,10 @@ set -g status-position bottom set -g status-justify left set -g status-style "bg=#3c3836 fg=#a89984" -set -g status-left "#[bold,bg=#a89984,fg=#282828] #H-#S #(count=$(tmux list-clients -t #S | wc -l); [ ${count} -gt 1 ] && echo (${count}) )#[bg=#3c3836,fg=#a89984]" +set -g status-left "#[bold,bg=#a89984,fg=#282828] #H-#S #(tmux_script client_count #S)#[bg=#3c3836,fg=#a89984]" set -g status-left-length 50 set -g status-right-length 50 -set -g status-right " #(tmux_script battery) #(tmux_script volume)  %Y-%m-%d #[fg=#a89984]#[bold,bg=#a89984,fg=#282828] %H:%M " +set -g status-right "#(tmux_script statusbar) %Y-%m-%d #[fg=#a89984]#[bold,bg=#a89984,fg=#282828] %H:%M " set-window-option -g window-status-separator ""