From 148dc3c78308232d98dc35a7bf9d1c1a9d8264b6 Mon Sep 17 00:00:00 2001 From: sebastian Date: Thu, 17 Sep 2026 14:52:39 +0200 Subject: [PATCH] make tmux show the battery in the status line --- .../tmux/executable_tmux-battery-insert.sh | 7 +++++++ dot_config/tmux/tmux.conf | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 dot_config/tmux/executable_tmux-battery-insert.sh diff --git a/dot_config/tmux/executable_tmux-battery-insert.sh b/dot_config/tmux/executable_tmux-battery-insert.sh new file mode 100644 index 0000000..f68b1fd --- /dev/null +++ b/dot_config/tmux/executable_tmux-battery-insert.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Insert the battery segment in tmux-power's status-right, right before the time segment. +batt=' #{battery_color_fg}#{battery_icon_status} #{battery_percentage} ' +icon=$(tmux show -gv @tmux_power_time_icon) +cur=$(tmux show -gv status-right) +new=$(BATT="$batt" ICON="$icon" perl -0pe 's/((?:#\[[^\]]*\])+[^#]*\Q$ENV{ICON}\E)/$ENV{BATT}$1/' <<< "$cur") +tmux set -g status-right "$new" diff --git a/dot_config/tmux/tmux.conf b/dot_config/tmux/tmux.conf index 7874167..32cfdb6 100644 --- a/dot_config/tmux/tmux.conf +++ b/dot_config/tmux/tmux.conf @@ -27,6 +27,23 @@ set-window-option -g pane-base-index 1 #set -g @tmux_power_theme 'forest' +# +#Battery in the status bar (next to the time) + +#set -g status-right '#{battery_icon_status} #{battery_percentage} | %H:%M ' +set -g status-interval 30 + +# Optional: color by charge level +set -g @batt_icon_status_charged '󰁹' +set -g @batt_icon_status_charging '󰂄' +set -g @batt_icon_status_discharging '󰁾' +set -g @batt_icon_status_attached '󰚥' +# (status-right is set by tmux-power; the battery gets appended below after TPM) + +# Plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-battery' + # # Tmux Power # @@ -107,6 +124,10 @@ set -ga update-environment TERM_PROGRAM run '~/.config/tmux/plugins/tpm/tpm' +# Battery: insert before tmux-power's time segment, then let tmux-battery fill in the placeholders +run '~/.config/tmux/tmux-battery-insert.sh' +run '~/.config/tmux/plugins/tmux-battery/battery.tmux' + # Pane-Titel anzeigen set -g pane-border-status top set -g pane-border-format ' #{pane_index}: #{pane_title} '