Tmux : Rework statusbar.

This commit is contained in:
Dmitry Voronin 2024-04-02 08:15:31 +03:00
parent 79d3d09558
commit 8d14a2a771
3 changed files with 48 additions and 12 deletions

View file

@ -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 ];
}

View file

@ -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

View file

@ -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 ""